Create a PDF portfolio (package) in Android
To create a PDF portfolio containing multiple file types.
void addPackage(PDFDoc doc, String file, String desc) throws PDFNetException {
NameTree files = NameTree.create(doc.getSDFDoc(), "EmbeddedFiles");
FileSpec fs = FileSpec.create(doc, file, true);
files.put(file.getBytes(), fs.getSDFObj());
fs.getSDFObj().putText("Desc", desc);
Obj collection = doc.getRoot().findObj("Collection");
if (collection == null) 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");
}
PDFDoc doc = new PDFDoc();
AddPackage(doc, filename, "PDF");
AddPackage(doc, imagename, "Image");@Throws(PDFNetException::class)
fun addPackage(doc: PDFDoc, file: String, desc: String) {
val files = NameTree.create(doc.sdfDoc, "EmbeddedFiles")
val fs = FileSpec.create(doc, file, true)
files.put(file.toByteArray(), fs.sdfObj)
fs.sdfObj.putText("Desc", desc)
var collection: Obj? = doc.root.findObj("Collection")
if (collection == null) collection = doc.root.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")
}
val doc = PDFDoc()
AddPackage(doc, filename, "PDF")
AddPackage(doc, imagename, "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?