Some test text!

menu

WebViewer

More languages

chevron_right
More languages
JavaScript
C++
C#
C# (.NET Core)
Java
Obj-C
JS (Node.js)
PHP
Python
Ruby
Swift
VB

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.

Get StartedSamplesDownload

To run this sample, get started with a free trial of PDFTron SDK.

//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2020 by PDFTron Systems Inc. All Rights Reserved.
// Consult legal.txt regarding legal and license information.
//---------------------------------------------------------------------------------------


const { PDFNet } = require('../../../lib/pdfnet.js');

((exports) => {
  'use strict';

  exports.runWebViewerConvertTest = () => {
    const main = async() => {
      console.log('Beginning Test');
      let ret = 0;
      const inputPath = '../../TestFiles/';
      try {
        const doc = await PDFNet.PDFDoc.createFromFilePath(inputPath + 'tiger.pdf');
        doc.initSecurityHandler();
        doc.lock();
        console.log('PDFNet and PDF document initialized and locked');

        await PDFNet.Convert.toXod(doc, '../../TestFiles/Output/from_pdf.xod', new PDFNet.Obj("0"));
        // have example of streaming

        const XodFilter = await doc.convertToXodStream();
        const XodFilterReader = await PDFNet.FilterReader.create(XodFilter);
        const dataArray = []; // used to store all the data of the .xod file
        const chunkLength = 1024; // size of every chunk stored in
        let retrievedLength = chunkLength; // amount of data to place in dataArray at a time
        while (chunkLength === retrievedLength) {
          const bufferSubArray = await XodFilterReader.read(chunkLength);
          retrievedLength = bufferSubArray.length;
          dataArray.push(bufferSubArray);
        }
        const bufferFinal = new Uint8Array(dataArray.length * chunkLength + retrievedLength);
        for (let i = 0; i < dataArray.length; i++) {
          const offset = i * chunkLength;
          const currentArr = dataArray[i];
          bufferFinal.set(currentArr, offset);
        }
        var fs = require('fs');
        fs.writeFileSync('../../TestFiles/Output/from_pdf_streamed.xod', bufferFinal, 'binary');
        console.log('done.');
      } catch (err) {
        console.log(err.stack);
        ret = 1;
      }
      return ret;
    };
    // add your own license key as the second parameter, e.g. PDFNet.runWithCleanup(main, 'YOUR_LICENSE_KEY')
    PDFNet.runWithCleanup(main, 0).then(function(){PDFNet.shutdown();});
  };
  exports.runWebViewerConvertTest();
})(exports);
// eslint-disable-next-line spaced-comment
//# sourceURL=WebViewerConvertTest.js
close

Free Trial

Get unlimited trial usage of PDFTron SDK to bring accurate, reliable, and fast document processing capabilities to any application or workflow.

Select a platform to get started with your free trial.

Unlimited usage. No email address required.

Join our upcoming webinar to find out about built-in, full-functioning document capabilities directly in Salesforce.

Save your seat
close