The example below shows how to combine a set of PDF documents
into a portfolio. See the Catalog.GetEmbeddedFiles
function for how to extract files from a portfolio.
string[] files = {
"../Rez/SignedDocument.pdf",
"../Rez/spaceshuttle.pdf",
"../Rez/Authorization.pdf",
"../Rez/Portfolio1.pdf",
};
using var doc = new Doc();
var fileSpecs = new List<Tuple<string, FileSpecification>>();
foreach (string file in files) {
byte[] data = null;
using (var subDoc = new Doc()) {
subDoc.Read(file);
data = subDoc.GetData();
}
var embedFile = new EmbeddedFile(doc.ObjectSoup, data);
embedFile.CompressFlate();
var fileSpec = new FileSpecification(doc.ObjectSoup);
fileSpec.EmbeddedFile = embedFile;
fileSpec.Uri = file;
string name = Path.GetFileName(file);
fileSpecs.Add(new Tuple<string, FileSpecification>(name, fileSpec));
}
fileSpecs.Sort((a, b) => a.Item1.CompareTo(b.Item1));
// we do not really need to delete existing files but we do so as an example
doc.SetInfo(doc.Root, "/Names*/EmbeddedFiles*/Names:Del", "");
foreach (var fileSpec in fileSpecs) {
doc.SetInfo(doc.Root, "/Names*/EmbeddedFiles*/Names*[]:Text", fileSpec.Item1);
doc.SetInfo(doc.Root, "/Names*/EmbeddedFiles*/Names*[]:Ref", fileSpec.Item2.ID);
}
// add placeholder text
doc.AddText("This is a Adobe Acrobat Portfolio file. Please use Adobe Acrobat software to open it.");
// save
doc.ObjectSoup.Catalog.Version = 17;
doc.SaveOptions.Linearize = false;
doc.SetInfo(doc.Root, "/Collection*/D:Text", files[0]);
doc.Save("createportfolio.pdf");