Indicates whether the stream contains a PDF portfolio.
stream
Stream containing the data of a PDF document.
password
The password to use when loading this PDF file (if the file is encrypted); otherwise, use null.
true if the file is a PDF portfolio; otherwise, false.
A PDF file can be created as a portfolio which contains multiple files assembled into an integrated unit. In these types of documents, the file contains a single generic help page with text such as "For the best experience, open this PDF portfolio in a compatible viewer", any number of attachments, and a schema to control how to view the document.
Refer to PDFDocument.EmbeddedFiles for more information.
using Leadtools.WinForms;using Leadtools;using Leadtools.Codecs;using Leadtools.Controls;using Leadtools.Drawing;using Leadtools.ImageProcessing;using Leadtools.Pdf;using Leadtools.Svg;public static void ExtractAttachmentsAndStitch(string inputFileName, string outputFileName){File.Delete(outputFileName);// Get the number of embedded files (attachments) in the input fileint attachmentCount = PDFFile.GetEmbeddedFileCount(inputFileName, null);// If the file does not have any attachments we are doneif (attachmentCount == 0){File.Copy(inputFileName, outputFileName, true);return;}// To convert attachment files that are not PDFvar rasterCodecs = new RasterCodecs();rasterCodecs.ThrowExceptionsOnInvalidImages = false;var tempFiles = new List<string>();// Now, extract all the attachmentsfor (int attachmentNumber = 1; attachmentNumber <= attachmentCount; attachmentNumber++){// Extract this attachment to a temporary filestring tempFile = Path.GetTempFileName();PDFFile.ExtractEmbeddedFile(inputFileName, null, attachmentNumber, tempFile);// If attachment is not PDF, convert itRasterImageFormat format;int pageCount;using (CodecsImageInfo info = rasterCodecs.GetInformation(tempFile, true)){format = info.Format;pageCount = info.TotalPages;}if (format == RasterImageFormat.Unknown){// We do not know what to do with this attachment, log and ignore itConsole.WriteLine("Could not convert attachment file to PDF, ignoring");File.Delete(tempFile);}else if (format != RasterImageFormat.RasPdf){// Simple conversion using RasterImage.// TODO for the Example: A better way is to use the DocumentConverter to get true document conversion with all the// options availablestring tempPdfFile = Path.GetTempFileName();for (int pageNumber = 1; pageNumber <= pageCount; pageNumber++){using (RasterImage image = rasterCodecs.Load(tempFile, pageNumber)){rasterCodecs.Save(image, tempPdfFile, RasterImageFormat.RasPdfJpeg422, 0, 1, -1, -1, CodecsSavePageMode.Append);}}File.Copy(tempPdfFile, tempFile, true);File.Delete(tempPdfFile);tempFiles.Add(tempFile);}else{// TODO for the Example: Check if this file is PDF with attachments and call the function recursively.tempFiles.Add(tempFile);}}// Time to generate the final document, first the pages from the original document// Did we extract/convert any attachments?if (tempFiles.Count > 0){// Note that if the original document is PDF portfolio, then it does not contain real pages. Just a placeholder that should be ignoredif (!PDFFile.IsPortfolio(inputFileName, null)){PDFFile file = new PDFFile(inputFileName);file.MergeWith(tempFiles.ToArray(), outputFileName);}else{// This is portfolio, so we will ignore the original file and just merge the attachmentsstring firstFile = tempFiles[0];tempFiles.RemoveAt(0);PDFFile file = new PDFFile(firstFile);file.MergeWith(tempFiles.ToArray(), outputFileName);File.Delete(firstFile);}}else{// No, just copy the original file overFile.Copy(inputFileName, outputFileName, true);}// Clean upforeach (string tempFile in tempFiles)File.Delete(tempFile);rasterCodecs.Dispose();}