For the complete documentation index, see llms.txt. This page is also available as Markdown.

Create a PDF portfolio (package) on Server/Desktop

To create a PDF portfolio containing multiple file types.

void AddPackage(PDFDoc doc, string file, string desc)
{
	NameTree files = NameTree.Create(doc, "EmbeddedFiles");
	FileSpec fs = FileSpec.Create(doc, file, true);
	byte[] file1_name = System.Text.Encoding.UTF8.GetBytes(file);
	files.Put(file1_name, fs.GetSDFObj());
	fs.GetSDFObj().PutText("Desc", desc);

	Obj collection = doc.GetRoot().FindObj("Collection");
	if (collection == null) collection = doc.GetRoot().PutDict("Collection");

	// 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");
void AddPackage(PDFDoc& doc, string file, const char* desc)
{
	NameTree files = NameTree::Create(doc, "EmbeddedFiles");
	FileSpec fs = FileSpec::Create(doc, file.c_str(), true);
	files.Put((UChar*)file.c_str(), int(file.size()), fs.GetSDFObj());
	fs.SetDesc(desc);

	Obj 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", "T");
}
PDFDoc doc;
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). Code sample is available in C++, C#, Java, Python, Go, PHP, Ruby & VB.

Last updated

Was this helpful?