1func AddPackage(doc: PTPDFDoc, file: String, desc: String) {
2 let files: PTNameTree = PTNameTree.create(doc.getSDFDoc(), name: "EmbeddedFiles")
3 let fs: PTFileSpec = PTFileSpec.create(doc.getSDFDoc(), path: file, embed: true)
4 let data: Data! = file.data(using: .utf8)
5 files.put(data, key_sz: Int32(data.count), value: fs.getSDFObj())
6 fs.setDesc(desc)
7
8 let collection: PTObj
9 if let optCollection: PTObj = doc.getRoot().find("Collection") {
10 collection = optCollection
11 } else {
12 collection = doc.getRoot().putDict("Collection")
13 }
14
15 // You could here manipulate any entry in the Collection dictionary.
16 // For example, the following line sets the tile mode for initial view mode
17 // Please refer to section '2.3.5 Collections' in PDF Reference for details.
18 collection.putName("View", name: "T")
19}
20let doc: PTPDFDoc = PTPDFDoc()
21AddPackage(doc: doc, file: filename, desc: "PDF")
22AddPackage(doc: doc, file: imagename, desc: "Image")