WebViewerConvert

These samples shows how to integrate PDFNet WebViewer into any HTML5, Silverlight, or Flash web application. The sample is using 'pdftron.PDF.Convert.ToXod()' to convert/stream PDF, XPS, MS Office, RTF, HTML and other document formats to WebViewer 'pdftron.PDF.Convert.ToXod()' is an optional Add-On to the Core SDK and is part of PDFNet WebViewer Publishing Platform.

1//---------------------------------------------------------------------------------------
2// Copyright (c) 2001-2023 by Apryse Software Inc. All Rights Reserved.
3// Consult legal.txt regarding legal and license information.
4//---------------------------------------------------------------------------------------
5
6(exports => {
7
8
9
10
11 exports.runWebViewerConvertTest = () => {
12 const PDFNet = exports.Core.PDFNet;
13
14 const main = async () => {
15 console.log('Beginning Test');
16 let ret = 0;
17 const inputPath = '../TestFiles/';
18 try {
19 const doc = await PDFNet.PDFDoc.createFromURL(inputPath + 'tiger.pdf');
20 doc.initSecurityHandler();
21 doc.lock();
22 console.log('PDFNet and PDF document initialized and locked');
23
24 const XodBuffer = await doc.convertToXod();
25
26 saveBufferAsXOD(XodBuffer, 'from_pdf.xod');
27
28 // have example of streaming
29
30 const XodFilter = await doc.convertToXodStream();
31 const XodFilterReader = await PDFNet.FilterReader.create(XodFilter);
32 const dataArray = []; // used to store all the data of the .xod file
33 const chunkLength = 1024; // size of every chunk stored in
34 let retrievedLength = chunkLength; // amount of data to place in dataArray at a time
35 while (chunkLength === retrievedLength) {
36 const bufferSubArray = await XodFilterReader.read(chunkLength);
37 retrievedLength = bufferSubArray.length;
38 dataArray.push(bufferSubArray);
39 }
40 const bufferFinal = new Uint8Array(dataArray.length * chunkLength + retrievedLength);
41 for (let i = 0; i < dataArray.length; i++) {
42 const offset = i * chunkLength;
43 const currentArr = dataArray[i];
44 bufferFinal.set(currentArr, offset);
45 }
46 saveBufferAsXOD(bufferFinal, 'from_pdf_streamed.xod');
47 console.log('done.');
48 } catch (err) {
49 console.log(err.stack);
50 ret = 1;
51 }
52 return ret;
53 };
54 // add your own license key as the second parameter, e.g. PDFNet.runWithCleanup(main, 'YOUR_LICENSE_KEY')
55 PDFNet.runWithCleanup(main);
56 };
57})(window);
58// eslint-disable-next-line spaced-comment
59//# sourceURL=WebViewerConvertTest.js

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales