/** * This is the most simple way to change a PDF into a * portable collection. Choose one of the following names: * <ul> * <li>PdfName.D (detailed view) * <li>PdfName.T (tiled view) * <li>PdfName.H (hidden) * </ul> * Pass this name as a parameter and your PDF will be * a portable collection with all the embedded and * attached files as entries. * @param initialView can be PdfName.D, PdfName.T or PdfName.H */ public void MakePackage(PdfName initialView) { PdfCollection collection = new PdfCollection(0); collection.Put(PdfName.VIEW, initialView); stamper.MakePackage(collection); }
public void Write(Stream stream) { using (Document document = new Document()) { PdfWriter writer = PdfWriter.GetInstance(document, stream); document.Open(); document.Add(new Paragraph("This document contains a collection of PDFs")); PdfIndirectReference parentFolderObjectReference = writer.PdfIndirectReference; PdfIndirectReference childFolder1ObjectReference = writer.PdfIndirectReference; PdfIndirectReference childFolder2ObjectReference = writer.PdfIndirectReference; PdfDictionary parentFolderObject = GetFolderDictionary(0); parentFolderObject.Put(new PdfName("Child"), childFolder1ObjectReference); parentFolderObject.Put(PdfName.NAME, new PdfString()); PdfDictionary childFolder1Object = GetFolderDictionary(1); childFolder1Object.Put(PdfName.NAME, new PdfString("Folder 1")); childFolder1Object.Put(PdfName.PARENT, parentFolderObjectReference); childFolder1Object.Put(PdfName.NEXT, childFolder2ObjectReference); PdfDictionary childFolder2Object = GetFolderDictionary(2); childFolder2Object.Put(PdfName.NAME, new PdfString("Folder 2")); childFolder2Object.Put(PdfName.PARENT, parentFolderObjectReference); PdfCollection collection = new PdfCollection(PdfCollection.DETAILS); PdfCollectionSchema schema = CollectionSchema(); collection.Schema = schema; collection.Sort = new PdfCollectionSort(keys); collection.Put(new PdfName("Folders"), parentFolderObjectReference); writer.Collection = collection; PdfFileSpecification fs; PdfCollectionItem item; fs = PdfFileSpecification.FileEmbedded(writer, file1Path, File1, null); item = new PdfCollectionItem(schema); item.AddItem("Type", "pdf"); fs.AddCollectionItem(item); // the description is apparently used to place the // file in a particular folder. The number between the < and > // is used to put the file in the folder that has the matching id fs.AddDescription(GetDescription(1, File1), false); writer.AddFileAttachment(fs); fs = PdfFileSpecification.FileEmbedded(writer, file2Path, File2, null); item = new PdfCollectionItem(schema); item.AddItem("Type", "pdf"); fs.AddCollectionItem(item); fs.AddDescription(GetDescription(2, File2), false); writer.AddFileAttachment(fs); writer.AddToBody(parentFolderObject, parentFolderObjectReference); writer.AddToBody(childFolder1Object, childFolder1ObjectReference); writer.AddToBody(childFolder2Object, childFolder2ObjectReference); document.Close(); } }
public void Write(Stream stream, string[] pfade) { using (Document document = new Document()) { PdfWriter writer = PdfWriter.GetInstance(document, stream); document.Open(); document.Add(new Paragraph(" ")); PdfIndirectReference parentFolderObjectReference = writer.PdfIndirectReference; PdfCollection collection = new PdfCollection(PdfCollection.DETAILS); PdfCollectionSchema schema = CollectionSchema(); collection.Schema = schema; collection.Sort = new PdfCollectionSort(keys); collection.Put(new PdfName("Vorlagen BA"), parentFolderObjectReference); writer.Collection = collection; PdfFileSpecification fs; PdfCollectionItem item; int nummer = 1; foreach (string pfad in pfade) { String Filename = Path.GetFileName(pfad); fs = PdfFileSpecification.FileEmbedded(writer, pfad, string.Format("{0} - {1}", nummer, Filename), null); item = new PdfCollectionItem(schema); item.AddItem("Type", "pdf"); fs.AddCollectionItem(item); fs.AddDescription(GetDescription(Filename), false); writer.AddFileAttachment(fs); nummer++; } document.Close(); } }