ImageGear .NET v25.0 - Updated
Saving
User Guide > How to Work with... > Common Operations > Loading and Saving > Saving

ImGearFileFormats class provides the APIs needed to save a document/image. ImageGear only supports saving to a .NET Stream object that have the seek ability. If the save operation cannot be conducted, an exception with the following code is thrown: ImageGear.Core.ImGearErrorCodes.CANT_SAVE_FORMAT.

If the document size is close to 2GB, the System.OutOfMemoryException will be thrown.

Save a Single Page

Use the SavePage method to a save a single page as follows:

C#
Copy Code
using System.IO;
using ImageGear.Core;
using ImageGear.Formats;
public void SavePageToFile(ImGearPage loadedPage, string outputFilePath)
{
     // Save to JPG file.
     using (FileStream fileStream = new FileStream(outputFilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite))
     {
          ImGearFileFormats.SavePage(loadedPage, fileStream, 0, ImGearSavingModes.OVERWRITE, ImGearSavingFormats.JPG);
     }
}
VB.NET
Copy Code
Imports System.IO
Imports ImageGear.Core
Imports ImageGear.Formats
Public Sub SavePageToFile(loadedPage As ImGearPage, outputFilePath As String)
            ' Save to JPG file.
            Using fileStream As New FileStream(outputFilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite)
                        ImGearFileFormats.SavePage(loadedPage, fileStream, 0, ImGearSavingModes.OVERWRITE, ImGearSavingFormats.JPG)
            End Using
End Sub

Save a Document (Multiple Pages as a Document)

For this purpose, use the SaveDocument method. See What's the Best Format for...? for a list of the multi-page formats supported by ImageGear .NET, for example, PDF:

C#
Copy Code
using System.IO;
using ImageGear.Core;
using ImageGear.Formats;
public void SaveDocumentToFile(ImGearDocument loadedPDFDocument, string outputFilePath)
{
    // Save to PDF file.
    ImGearSaveOptions defaultSaveOptions = new ImGearSaveOptions();
    using (FileStream fileStream = new FileStream(outputFilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite))
    {
        ImGearFileFormats.SaveDocument(loadedPDFDocument, fileStream, 0, ImGearSavingModes.OVERWRITE, ImGearSavingFormats.PDF, defaultSaveOptions);
    }
}
VB.NET
Copy Code
Imports System.IO
Imports ImageGear.Core
Imports ImageGear.Formats
Public Sub SaveDocumentToFile(loadedPDFDocument As ImGearDocument, outputFilePath As String)
    ' Save to PDF file.
    Dim defaultSaveOptions As New ImGearSaveOptions()
    Using fileStream As New FileStream(outputFilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite)
        ImGearFileFormats.SaveDocument(loadedPDFDocument, fileStream, 0, ImGearSavingModes.OVERWRITE, ImGearSavingFormats.PDF, defaultSaveOptions)
    End Using
End Sub