To create a PDF portfolio containing multiple file types.
1void AddPackage(PDFDoc doc, string file, string desc)
2{
3 NameTree files = NameTree.Create(doc, "EmbeddedFiles");
4 FileSpec fs = FileSpec.Create(doc, file, true);
5 byte[] file1_name = System.Text.Encoding.UTF8.GetBytes(file);
6 files.Put(file1_name, fs.GetSDFObj());
7 fs.GetSDFObj().PutText("Desc", desc);
8
9 Obj collection = doc.GetRoot().FindObj("Collection");
10 if (collection == null) collection = doc.GetRoot().PutDict("Collection");
11
12 // Manipulate any entry in the Collection dictionary.
13 // For example, the following line sets the tile mode for initial view mode
14 // Please refer to section '2.3.5 Collections' in PDF Reference for details.
15 collection.PutName("View", "T");
16}
17PDFDoc doc = new PDFDoc();
18AddPackage(doc, filename, "PDF");
19AddPackage(doc, imagename, "Image");
1void AddPackage(PDFDoc& doc, string file, const char* desc)
2{
3 NameTree files = NameTree::Create(doc, "EmbeddedFiles");
4 FileSpec fs = FileSpec::Create(doc, file.c_str(), true);
5 files.Put((UChar*)file.c_str(), int(file.size()), fs.GetSDFObj());
6 fs.SetDesc(desc);
7
8 Obj 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}
16PDFDoc doc;
17AddPackage(doc, filename, "PDF");
18AddPackage(doc, imagename, "Image");
1func AddPackage(doc PDFDoc, file string, desc string){
2 files := NameTreeCreate(doc.GetSDFDoc(), "EmbeddedFiles")
3 fs := FileSpecCreate(doc.GetSDFDoc(), file, true)
4 key := make([]byte, len(file))
5 for i := 0; i < len(file); i++{
6 key[i] = file[i]
7 //fmt.Println(file[i])
8 }
9 files.Put(&key[0], len(key), fs.GetSDFObj())
10 fs.SetDesc(desc)
11
12 collection := doc.GetRoot().FindObj("Collection")
13 if collection.GetMp_obj().Swigcptr() == 0{
14 collection = doc.GetRoot().PutDict("Collection")
15 }
16
17 // You could here manipulate any entry in the Collection dictionary.
18 // For example, the following line sets the tile mode for initial view mode
19 // Please refer to section '2.3.5 Collections' in PDF Reference for details.
20 collection.PutName("View", "T");
21}
22doc := NewPDFDoc()
23AddPackage(doc, filename, "PDF")
24AddPackage(doc, imagename, "Image")
1void addPackage(PDFDoc doc, String file, String desc) throws PDFNetException {
2 NameTree files = NameTree.create(doc.getSDFDoc(), "EmbeddedFiles");
3 FileSpec fs = FileSpec.create(doc, file, true);
4 files.put(file.getBytes(), fs.getSDFObj());
5 fs.getSDFObj().putText("Desc", desc);
6
7 Obj collection = doc.getRoot().findObj("Collection");
8 if (collection == null) collection = doc.getRoot().putDict("Collection");
9
10 // You could here manipulate any entry in the Collection dictionary.
11 // For example, the following line sets the tile mode for initial view mode
12 // Please refer to section '2.3.5 Collections' in PDF Reference for details.
13 collection.putName("View", "T");
14}
15PDFDoc doc = new PDFDoc();
16AddPackage(doc, filename, "PDF");
17AddPackage(doc, imagename, "Image");
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);
1void AddPackage(PTPDFDoc *doc, NSString *file, NSString* desc)
2{
3 PTNameTree *files = [PTNameTree Create: [doc GetSDFDoc] name: @"EmbeddedFiles"];
4 PTFileSpec *fs = [PTFileSpec Create: [doc GetSDFDoc] path: file embed: true];
5 [files Put: [file dataUsingEncoding: NSUTF8StringEncoding] key_sz:(int)file.length value: [fs GetSDFObj]];
6 [fs SetDesc: desc];
7
8 PTObj * 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" name: @"T"];
15}
16PTPDFDoc *doc = [[PTPDFDoc alloc] init];
17AddPackage(doc, filename, @"PDF");
18AddPackage(doc, imagename, @"Image");
1function AddPackage($doc, $file, $desc)
2{
3 $files = NameTree::Create($doc->GetSDFDoc(), "EmbeddedFiles");
4 $fs = FileSpec::Create($doc->GetSDFDoc(), $file, true);
5 $files->Put($file, strlen($file), $fs->GetSDFObj());
6 $fs->SetDesc($desc);
7
8 $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$doc = new PDFDoc();
17AddPackage($doc, $filename, "PDF");
18AddPackage($doc, $imagename, "Image");
1def AddPackage(doc, file, desc):
2 files = NameTree.Create(doc.GetSDFDoc(), "EmbeddedFiles")
3 fs = FileSpec.Create(doc.GetSDFDoc(), file, True)
4 key = bytearray(file, "utf-8")
5 files.Put(key, len(key), fs.GetSDFObj())
6 fs.SetDesc(desc)
7
8 collection = doc.GetRoot().FindObj("Collection")
9 if collection is None:
10 collection = doc.GetRoot().PutDict("Collection")
11
12 # You could here manipulate any entry in the Collection dictionary.
13 # For example, the following line sets the tile mode for initial view mode
14 # Please refer to section '2.3.5 Collections' in PDF Reference for details.
15 collection.PutName("View", "T")
16doc = PDFDoc()
17AddPackage(doc, filename, "PDF")
18AddPackage(doc, imagename, "Image")
1def AddPackage(doc, file, desc)
2 files = NameTree.Create(doc.GetSDFDoc, "EmbeddedFiles")
3 fs = FileSpec.Create(doc.GetSDFDoc, file, true)
4 files.Put(file, file.length, fs.GetSDFObj)
5 fs.SetDesc(desc)
6
7 collection = doc.GetRoot.FindObj("Collection")
8 if collection.nil?
9 collection = doc.GetRoot.PutDict("Collection")
10 end
11
12 # You could here manipulate any entry in the Collection dictionary.
13 # For example, the following line sets the tile mode for initial view mode
14 # Please refer to section '2.3.5 Collections' in PDF Reference for details.
15 collection.PutName("View", "T")
16end
17doc = PDFDoc.new
18AddPackage(doc, filename, "PDF")
19AddPackage(doc, imagename, "Image")
1Sub AddPackage(ByRef doc As PDFDoc, ByVal file As String, ByVal desc As String)
2 Dim files As NameTree = NameTree.Create(doc.GetSDFDoc(), "EmbeddedFiles")
3 Dim fs As FileSpec = FileSpec.Create(doc, file, True)
4 files.Put(System.Text.Encoding.UTF8.GetBytes(file), fs.GetSDFObj())
5 fs.GetSDFObj().PutText("Desc", desc)
6
7 Dim collection As Obj = doc.GetRoot().FindObj("Collection")
8 If collection = Nothing then
9 collection = doc.GetRoot().PutDict("Collection")
10 End If
11
12 ' Manipulate any entry in the Collection dictionary.
13 ' For example, the following line sets the tile mode for initial view mode
14 ' Please refer to section '2.3.5 Collections' in PDF Reference for details.
15 collection.PutName("View", "T")
16End Sub
17Dim doc As PDFDoc = New PDFDoc()
18AddPackage(doc, filename, "PDF")
19AddPackage(doc, imagename, "Image")
PDF packages (portfolios)
Full code sample which illustrates how to create, extract, and manipulate PDF Packages (also known as PDF Portfolios).
Did you find this helpful?
Trial setup questions?
Ask experts on DiscordNeed other help?
Contact SupportPricing or product questions?
Contact Sales