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