In This Topic
    Save an optimized PDF
    In This Topic

    Introduction

    The following example demonstrates how to save an optimized PDF document.

    Save an optimized PDF document
    Copy Code
    public static void SaveOptimizedDocument()
    {
      Console.WriteLine( "=== SAVE OPTIMIZED DOCUMENT ===" );
    
      // Load a pdf document from a path.
      using( var pdfDoc = PdfDocument.Load( PdfDocumentsSample.PdfDocumentsSampleResourceDirectory + "Pdf_Sample.pdf" ) )
      {
        var outputFileName = "SaveOptimizedDocument.pdf";
        var outputPath = PdfDocumentsSample.PdfDocumentsSampleOutputDirectory + outputFileName;
    
        // Save the loaded document to a path with an optimized mode (Saves the Pdf document with only the needed objects).
        // Will eventually also compress the images.
        pdfDoc.SaveAs( outputPath, SaveOptions.Optimized );
        Console.WriteLine( $"Info exported to path: {outputFileName}" );
      }
    }

    See Also

    Secure a PDF document