Some test text!

menu
Create a packagekeyboard_arrow_down

Create a PDF portfolio (package) using JavaScript

Only available with the Full API

To create a PDF portfolio containing multiple file types.

<html>
  <script src="../lib/core/CoreControls.js"></script>
  <script src="../lib/core/pdf/PDFNet.js"></script>
  <script>
    (async function() {
      CoreControls.setWorkerPath('../lib/core');

      async function AddPackage(doc, file, desc) {
        const files = await PDFNet.NameTree.create(doc.getSDFDoc(), "EmbeddedFiles");
        const fs = await PDFNet.FileSpec.create(doc, file, true);
        var key = new TextEncoder("utf-8").encode(file);
        files.put(key, fs.getSDFObj());
        fs.getSDFObj().putText("Desc", desc);

        var collection = doc.getRoot().findObj("Collection");
        if (!collection) collection = doc.getRoot().putDict("Collection");

        // You could here manipulate any entry in the Collection dictionary.
          // For example, the following line sets the tile mode for initial view mode
        // Please refer to section '2.3.5 Collections' in PDF Reference for details.
        collection.putName("View", "T");
      }
      var doc = await PDFNet.PDFDoc.create();
      await AddPackage(doc, filename, "PDF");
      await AddPackage(doc, imagename, "Image");
    })()
  </script>
</html>

PDF packages (portfolios)
Full code sample which illustrates how to create, extract, and manipulate PDF Packages (also known as PDF Portfolios).

Get the answers you need: Support

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 live demo to learn about use cases & capabilities for WebViewer

Learn more
close