ImageGear .NET - Updated
Load and Save a PDF
User Guide > How to Work with... > Formats with Additional Functionality > PDF > How to... > Load and Save a PDF

This section provides information about the following:

Loading a Password Protected PDF

To load a password protected PDF refer to Use PDF Security.

Saving as a PDF

ImageGear .NET PDF component provides the ImGearPDFSaveOptions class that defines options for saving raster pages and documents to specific PDF formats like PDF/A. This class is derived from the regular ImGearSaveOptions class and could be used with the regular ImGearFileFormats.SavePage and ImGearFileFormats.SaveDocument methods that take ImGearSaveOptions parameter.

When using SaveDocument with ImGearPDFDocument or ImGearDocument with vector data as input, ImageGear ignores specific compression settings.

The following sample code demonstrates how to use the ImGearPDFSaveOptions class for saving raster document to PDF/A:

C#
Copy Code
        ImGearDocument doc = null;
        // Load raster document.
        using (FileStream fileStream = new FileStream(infile, FileMode.Open, FileAccess.Read, FileShare.Read))
        {
            doc = ImGearFileFormats.LoadDocument(fileStream, 0, -1);
        }
        // Specify PDF/A options for saving.
        ImGearPDFSaveOptions pdfOptions = new ImGearPDFSaveOptions();
        pdfOptions.PreflightOptions = new ImGearPDFPreflightConvertOptions(ImGearPDFPreflightProfile.PDFA_1A_2005, 0, -1);
        pdfOptions.PreflightOptions.OutputIntentColorProfile = ImGearColorProfileManager.RgbProfile;
        // Save to PDF/A file.
        using (FileStream fileStream = new FileStream(outfile, FileMode.OpenOrCreate, FileAccess.ReadWrite))
        {
            ImGearFileFormats.SaveDocument(doc, fileStream, 0, ImGearSavingModes.OVERWRITE, ImGearSavingFormats.PDF_DEFLATE, pdfOptions);
        }
VB.NET
Copy Code
        Dim doc As ImGearDocument
        ' Load raster document.
        Using fileStream As FileStream = New FileStream(infile, FileMode.Open, FileAccess.Read, FileShare.Read)
            doc = ImGearFileFormats.LoadDocument(fileStream, 0, -1)
        End Using
        ' Specify PDF/A options for saving.
        Dim pdfOptions As ImGearPDFSaveOptions = New ImGearPDFSaveOptions()
        pdfOptions.PreflightOptions = New ImGearPDFPreflightConvertOptions(ImGearPDFPreflightProfile.PDFA_1A_2005, 0, -1)
        pdfOptions.PreflightOptions.OutputIntentColorProfile = ImGearColorProfileManager.RgbProfile
        ' Save to PDF/A file.
        Using fileStream As FileStream = New FileStream(outfile, FileMode.OpenOrCreate, FileAccess.ReadWrite)
            ImGearFileFormats.SaveDocument(doc, fileStream, 0, ImGearSavingModes.OVERWRITE, ImGearSavingFormats.PDF_DEFLATE, pdfOptions)
        End Using
You can also use this approach for converting PDF files to PDF/A which would be effectively the same as using ImGearPDFPreflight.Convert for the original PDF document.

Reducing File Size when Saving a PDF

In order to reduce the size of a PDF document, use the ImageGear PDF Filter Control Parameters "SaveFlags". For this purpose, combine the following ImGearPDFSaveFlags:

C#
Copy Code
ImGearPDFSaveFlags saveFlags = ImGearPDFSaveFlags.ADD_FLATE | ImGearPDFSaveFlags.REPLACE_LZW | ImGearPDFSaveFlags.REMOVE_ASCII_FILTERS | ImGearPDFSaveFlags.COMPRESSED | ImGearPDFSaveFlags.OPTIMIZE_XOBJECTS | ImGearPDFSaveFlags.OPTIMIZE_CONTENT_STREAMS | ImGearPDFSaveFlags.OPTIMIZE_FONTS;
ImGearControlParameter parameter = ImGearFileFormats.Filters.Get(ImGearFormats.PDF).Parameters.GetByName("SaveFlags");
parameter.Value = saveFlags;
VB.NET
Copy Code
Dim saveFlags As ImGearPDFSaveFlags = ImGearPDFSaveFlags.ADD_FLATE Or ImGearPDFSaveFlags.REPLACE_LZW Or ImGearPDFSaveFlags.REMOVE_ASCII_FILTERS Or ImGearPDFSaveFlags.COMPRESSED Or ImGearPDFSaveFlags.OPTIMIZE_XOBJECTS Or ImGearPDFSaveFlags.OPTIMIZE_CONTENT_STREAMS Or ImGearPDFSaveFlags.OPTIMIZE_FONTS
Dim parameter As ImGearControlParameter = ImGearFileFormats.Filters.[Get](ImGearFormats.PDF).Parameters.GetByName("SaveFlags")
parameter.Value = saveFlags
When the Save Compressed PDF functionality provided in ImageGear is used, you do not need to explicitly set these Save Flags. In this case, the saving operation is executed with these flags activated in order to obtain higher compression rates.

Saving a Password Protected PDF

To save a password protected PDF refer to Use PDF Security.

Exporting OCR Recognized Data to a PDF Output

See Export to a PDF Document for more information.

Saving a PDF as Other Supported Formats

See Convert... for more information.