In DynamicPDF Core Suite there are several ways to optimize a document; combining duplicate images, stripping out unneeded content, setting a high compression level or setting a document to be linearized (optimized for fast web viewing only). These items are discussed below.
One way to achieve an optimized PDF is to tell DynamicPDF Core Suite to combine the image data of any images that are shared throughout one or more PDF documents. In other words, if there was an Image_A inside PDF_A and the identical Image_A was inside PDF_B, then when you merge PDF_A and PDF_B merger can combine the image data content into one therefore reducing the overall file size of the output PDF. Setting a high compression level will also further increase the file size reduction potential.
The code below demonstrates how to combine a PDF's resources (Images) along with setting a high CompressionLevel.
DocumentOptimization optimization = new DocumentOptimization (true);
Document.Optimization = optimization;
Document.Compressionlevel = 9;
Dim optimization As DocumentOptimization = New DocumentOptimization(True)
Document.Optimization = optimization
Document.Compressionlevel = 9
Stripping Unneeded Content
MergeOptions mergeOptions = new MergeOptions();
mergeOptions.LogicalStructure = false;
mergeOptions.Outlines = false;
mergeOptions.EmbeddedFiles = false;
MergeDocument document = new MergeDocument(pdfFilePath, mergeOptions);
Dim MyMergeOptions As MergeOptions = New MergeOptions()
MyMergeOptions.LogicalStructure = False
MyMergeOptions.Outlines = False
MyMergeOptions.EmbeddedFiles = False
Dim Mydocument As MergeDocument = New MergeDocument(pdfFilePath, MyMergeOptions)
Linearizing the PDF (Fast Web View)
Setting the PDF file to be linearized will not optimize it in terms of file size (in fact, a linearized PDF will be just slightly larger than its non-linearized counterpart) but it allows the PDF, once on the server, to serve up pages to the browser as they are become available (as opposed to waiting for the entire file to be downloaded).
We can also optimize the PDF for fast web view using the below code.
MergeDocument.DefaultPdfFormat = PdfFormat.Linearized;
MergeDocument.DefaultPdfFormat = PdfFormat.Linearized