Create a PDF portfolio (package) on iOS
To create a PDF portfolio containing multiple file types.
void AddPackage(PTPDFDoc *doc, NSString *file, NSString* desc)
{
PTNameTree *files = [PTNameTree Create: [doc GetSDFDoc] name: @"EmbeddedFiles"];
PTFileSpec *fs = [PTFileSpec Create: [doc GetSDFDoc] path: file embed: true];
[files Put: [file dataUsingEncoding: NSUTF8StringEncoding] key_sz:(int)file.length value: [fs GetSDFObj]];
[fs SetDesc: desc];
PTObj * 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" name: @"T"];
}
PTPDFDoc *doc = [[PTPDFDoc alloc] init];
AddPackage(doc, filename, @"PDF");
AddPackage(doc, imagename, @"Image");func AddPackage(doc: PTPDFDoc, file: String, desc: String) {
let files: PTNameTree = PTNameTree.create(doc.getSDFDoc(), name: "EmbeddedFiles")
let fs: PTFileSpec = PTFileSpec.create(doc.getSDFDoc(), path: file, embed: true)
let data: Data! = file.data(using: .utf8)
files.put(data, key_sz: Int32(data.count), value: fs.getSDFObj())
fs.setDesc(desc)
let collection: PTObj
if let optCollection: PTObj = doc.getRoot().find("Collection") {
collection = optCollection
} else {
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", name: "T")
}
let doc: PTPDFDoc = PTPDFDoc()
AddPackage(doc: doc, file: filename, desc: "PDF")
AddPackage(doc: doc, file: imagename, desc: "Image")PDF packages (portfolios) Full code sample which illustrates how to create, extract, and manipulate PDF Packages (also known as PDF Portfolios).
Last updated
Was this helpful?