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