> For the complete documentation index, see [llms.txt](https://docs.apryse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apryse.com/web/get-started/samples/webviewerconverttest.md).

# Convert - 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, RT

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.

This sample works with [Full-API for WebViewer.](/web/full-api/full-api-overview.md)

<pre class="language-js" data-line-numbers><code class="lang-js">//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2023 by Apryse Software Inc. All Rights Reserved.
// Consult legal.txt regarding legal and license information.
//---------------------------------------------------------------------------------------

(exports => {
  exports.runWebViewerConvertTest = () => {
    const PDFNet = exports.Core.PDFNet;

    const main = async () => {
      console.log('Beginning Test');
      let ret = 0;
      const inputPath = '../TestFiles/';
      try {
        const doc = await PDFNet.PDFDoc.createFromURL(inputPath + 'tiger.pdf');
        doc.initSecurityHandler();
        doc.lock();
        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 XodFilterReader.read(chunkLength);
          retrievedLength = bufferSubArray.length;
          dataArray.push(bufferSubArray);
        }
        const bufferFinal = new Uint8Array(dataArray.length * chunkLength + retrievedLength);
        for (let i = 0; i &#x3C; dataArray.length; i++) {
          const offset = i * chunkLength;
          const currentArr = dataArray[i];
          bufferFinal.set(currentArr, offset);
        }
        saveBufferAsXOD(bufferFinal, 'from_pdf_streamed.xod');
        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, '<code class="expression">visitor.claims.wvKey || "YOUR_LICENSE_KEY"</code>')
    PDFNet.runWithCleanup(main);
  };
})(window);
// eslint-disable-next-line spaced-comment
//# sourceURL=WebViewerConvertTest.js
</code></pre>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.apryse.com/web/get-started/samples/webviewerconverttest.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
