Sample to create PDF Portfolio (packages)

To create a PDF portfolio containing multiple file types using JavaScript.

1<html>
2 <script src="../lib/core/webviewer-core.min.js"></script>
3 <script src="../lib/core/pdf/PDFNet.js"></script>
4 <script>
5 (async function() {
6 Core.setWorkerPath('../lib/core');
7
8 async function AddPackage(doc, file, desc) {
9 const files = await PDFNet.NameTree.create(doc.getSDFDoc(), "EmbeddedFiles");
10 const fs = await PDFNet.FileSpec.create(doc, file, true);
11 var key = new TextEncoder("utf-8").encode(file);
12 files.put(key, fs.getSDFObj());
13 fs.getSDFObj().putText("Desc", desc);
14
15 var collection = doc.getRoot().findObj("Collection");
16 if (!collection) collection = doc.getRoot().putDict("Collection");
17
18 // You could here manipulate any entry in the Collection dictionary.
19 // For example, the following line sets the tile mode for initial view mode
20 // Please refer to section '2.3.5 Collections' in PDF Reference for details.
21 collection.putName("View", "T");
22 }
23 var doc = await PDFNet.PDFDoc.create();
24 await AddPackage(doc, filename, "PDF");
25 await AddPackage(doc, imagename, "Image");
26 })()
27 </script>
28</html>

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales
Sample to Create PDF Portfolio (Packages) using Apryse's Web SDK | Apryse documentation