ImageGear v26.0 - Updated
Saving
Developer 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#

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);
     }
}

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, for example, PDF:

C#


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);
    }
}
Is this page helpful?
Yes No
Thanks for your feedback.