How to combine PDF files into a PDF portfolio?

I am looking for functionality that creates a PDF portfolio:

Multiple PDFs packaged into one

The image shows the free Adobe Reader, which can be downloaded from Adobe (duh!). When I open this particular PDF file, I was surprised that it has all these features of Layout, Files and Attachment. This is definitely not a normal PDF merge. This is more like a package with several PDF files.

Can this be done? What is the search query for this PDF function?

+1
source share
2 answers

The term you are looking for is a PDF portfolio . You can create PDF files like this with iTextSharp. Here are a couple of C # examples from the iText book :

If you decide to download the KubrickMovies result file, change the extension to ".pdf". Just noticed it now - I'll try to fix the error this weekend.

+5
source

Here is a simple example to show how we can attach files to a new PDF file:

using System.Diagnostics; using System.IO; using iTextSharp.text; using iTextSharp.text.pdf; namespace PDFAttachment { class Program { static void Main(string[] args) { using (var pdfDoc = new Document(PageSize.A4)) { var pdfWriter = PdfWriter.GetInstance(pdfDoc, new FileStream("Test.pdf", FileMode.Create)); pdfDoc.Open(); pdfDoc.Add(new Phrase("Test")); var filePath = @"C:\path\logo.png"; var fileInfo = new FileInfo(filePath); var pdfDictionary = new PdfDictionary(); pdfDictionary.Put(PdfName.MODDATE, new PdfDate(fileInfo.LastWriteTime)); var fs = PdfFileSpecification.FileEmbedded(pdfWriter, filePath, fileInfo.Name, null, true, null, pdfDictionary); pdfWriter.AddFileAttachment("desc.", fs); } Process.Start("Test.pdf"); } } } 

Or into an existing PDF file:

 using System.Diagnostics; using System.IO; using iTextSharp.text; using iTextSharp.text.pdf; namespace PDFAttachment { class Program { static void Main(string[] args) { var reader = new PdfReader("Test.pdf"); using (var stamper = new PdfStamper(reader, new FileStream("newTest.pdf", FileMode.Create))) { var filePath = @"C:\path\logo.png"; addAttachment(stamper, filePath, "desc."); stamper.Close(); } Process.Start("newTest.pdf"); } private static void addAttachment(PdfStamper stamper, string filePath, string description) { var fileInfo = new FileInfo(filePath); var pdfDictionary = new PdfDictionary(); pdfDictionary.Put(PdfName.MODDATE, new PdfDate(fileInfo.LastWriteTime)); var pdfWriter = stamper.Writer; var fs = PdfFileSpecification.FileEmbedded(pdfWriter, filePath, fileInfo.Name, null, true, null, pdfDictionary); stamper.AddFileAttachment(description, fs); } } } 
0
source

Source: https://habr.com/ru/post/1441502/


All Articles