Some test text!



Switch language

Switch language
JS (Node.js)

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-2019 by PDFTron Systems Inc. All Rights Reserved.
// Consult legal.txt regarding legal and license information.

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

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

        const XodBuffer = await doc.convertToXod();

        saveBufferAsXOD(XodBuffer, 'from_pdf.xod');

        // 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;
          retrievedLength = bufferSubArray.length;
        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);
        saveBufferAsXOD(bufferFinal, 'from_pdf_streamed.xod');
      } catch (err) {
        ret = 1;
      return ret;

    // start the generator
    PDFNet.runWithCleanup(main, window.sampleL);
// eslint-disable-next-line spaced-comment
//# sourceURL=WebViewerConvertTest.js

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.