GdPicture.NET.14.API
GdPicture14 Namespace / GdPicturePDF Class / SaveToFile Method / SaveToFile(String,Boolean,Boolean) Method
The file path where the currently loaded PDF document will be saved. If the specified file already exists, it will be overwritten.

You are allowed to overwrite the currently opened PDF document only if the document has been loaded into memory setting the LoadInMemory parameter to true in the previously called GdPicturePDF.LoadFromFile method.

Specifies if the toolkit has to pack the current document before the save process to reduce its size.

Set this parameter to true if you want to pack the PDF document before saving. Please note that the whole saving process can be as a result slower with some documents.

If you set this parameter to false, the PDF document will remain unpacked after the save process.

Specifies if the PDF document should be linearized when saving, that means if the PDF document should enable Fast Web View mode.

Set this parameter to true to enable optimized save for Fast Web View mode.

If you set this parameter to false, the PDF will not be optimized for Fast Web View mode when saving.

Example





In This Topic
SaveToFile(String,Boolean,Boolean) Method
In This Topic
Packs, linearizes and saves the currently loaded PDF document to a file according to a file path you have specified.

Please note that you can highly reduce the file size of the PDF document by enabling the use of the standard compression mechanism during saving.

Syntax
'Declaration
 
Public Overloads Function SaveToFile( _
   ByVal FilePath As String, _
   ByVal PackDocument As Boolean, _
   ByVal Linearize As Boolean _
) As GdPictureStatus
public GdPictureStatus SaveToFile( 
   string FilePath,
   bool PackDocument,
   bool Linearize
)
public function SaveToFile( 
    FilePath: String;
    PackDocument: Boolean;
    Linearize: Boolean
): GdPictureStatus; 
public function SaveToFile( 
   FilePath : String,
   PackDocument : boolean,
   Linearize : boolean
) : GdPictureStatus;
public: GdPictureStatus SaveToFile( 
   string* FilePath,
   bool PackDocument,
   bool Linearize
) 
public:
GdPictureStatus SaveToFile( 
   String^ FilePath,
   bool PackDocument,
   bool Linearize
) 

Parameters

FilePath
The file path where the currently loaded PDF document will be saved. If the specified file already exists, it will be overwritten.

You are allowed to overwrite the currently opened PDF document only if the document has been loaded into memory setting the LoadInMemory parameter to true in the previously called GdPicturePDF.LoadFromFile method.

PackDocument
Specifies if the toolkit has to pack the current document before the save process to reduce its size.

Set this parameter to true if you want to pack the PDF document before saving. Please note that the whole saving process can be as a result slower with some documents.

If you set this parameter to false, the PDF document will remain unpacked after the save process.

Linearize
Specifies if the PDF document should be linearized when saving, that means if the PDF document should enable Fast Web View mode.

Set this parameter to true to enable optimized save for Fast Web View mode.

If you set this parameter to false, the PDF will not be optimized for Fast Web View mode when saving.

Return Value

A member of the GdPictureStatus enumeration. If the method has been successfully followed, then the return value is GdPictureStatus.OK.

We strongly recommend always checking this status first.

Remarks
The pack mode is an option allowing the toolkit the removal of any unused PDF objects and to better compress some other objects before saving the PDF document. Using this option leads to the recreation of a brand new PDF document by cloning all existing pages of the current document onto a brand new document. You can also combine this parameter with the standard compression mechanism as well as you can benefit from using the GdPicturePDF.RemoveUnusedResources method to eliminate all unused resources from your saved PDF document.

Fast Web View restructures a PDF document for page-at-a-time downloading from web. With Fast Web View, the web server only sends the requested page, rather than the entire PDF. This is especially important with large documents that can take a long time to download.

This method requires the PDF Processing component to run.

Example
How to linearize and save the PDF document.
Dim caption As String = "Example: SaveToFile"
Dim gdpicturePDF As New GdPicturePDF()
If gdpicturePDF.LoadFromFile("test.pdf", False) = GdPictureStatus.OK Then
    gdpicturePDF.EnableCompression(True)
    If gdpicturePDF.GetStat() <> GdPictureStatus.OK Then
        GoTo [error]
    End If
    If gdpicturePDF.SaveToFile("compressed_pack_unlinearize.pdf", True, False) = GdPictureStatus.OK Then
        MessageBox.Show("Saving file with compression, with packing but without linearization has been successful.", caption)
    End If
            
    If gdpicturePDF.SaveToFile("compressed_pack_linearize.pdf", True, True) = GdPictureStatus.OK Then
        MessageBox.Show("Saving file with compression, with packing and with linearization has been successful.", caption)
    End If
    gdpicturePDF.CloseDocument()
            
    If gdpicturePDF.LoadFromFile("compressed_pack_unlinearize.pdf", False) = GdPictureStatus.OK Then
        Dim isLinearized As Boolean = gdpicturePDF.IsLinearized()
        If gdpicturePDF.GetStat() <> GdPictureStatus.OK Then
            GoTo [error]
        End If
        If isLinearized Then
            MessageBox.Show("This file is linearized.", caption)
        Else
            'This should be the correct case.
            MessageBox.Show("This file is not linearized.", caption)
        End If
    End If
    gdpicturePDF.CloseDocument()
            
    If gdpicturePDF.LoadFromFile("compressed_pack_linearize.pdf", False) = GdPictureStatus.OK Then
        Dim isLinearized As Boolean = gdpicturePDF.IsLinearized()
        If gdpicturePDF.GetStat() <> GdPictureStatus.OK Then
            GoTo [error]
        End If
        If isLinearized Then
            'This should be the correct case.
            MessageBox.Show("This file is linearized.", caption)
        Else
            MessageBox.Show("This file is not linearized.", caption)
        End If
    End If
Else
    MessageBox.Show("The file can't be loaded.", caption)
End If
[error]:
gdpicturePDF.Dispose()
string caption = "Example: SaveToFile";
GdPicturePDF gdpicturePDF = new GdPicturePDF();
if (gdpicturePDF.LoadFromFile("test.pdf", false) == GdPictureStatus.OK)
{
    gdpicturePDF.EnableCompression(true);
    if (gdpicturePDF.GetStat() != GdPictureStatus.OK) goto error;
    if (gdpicturePDF.SaveToFile("compressed_pack_unlinearize.pdf", true, false) == GdPictureStatus.OK)
    {
        MessageBox.Show("Saving file with compression, with packing but without linearization has been successful.", caption);
    }
            
    if (gdpicturePDF.SaveToFile("compressed_pack_linearize.pdf", true, true) == GdPictureStatus.OK)
    {
        MessageBox.Show("Saving file with compression, with packing and with linearization has been successful.", caption);
    }
    gdpicturePDF.CloseDocument();
            
    if (gdpicturePDF.LoadFromFile("compressed_pack_unlinearize.pdf", false) == GdPictureStatus.OK)
    {
        bool isLinearized = gdpicturePDF.IsLinearized();
        if (gdpicturePDF.GetStat() != GdPictureStatus.OK) goto error;
        if (isLinearized)
        {
            MessageBox.Show("This file is linearized.", caption);
        }
        else
        {
            //This should be the correct case.
            MessageBox.Show("This file is not linearized.", caption);
        }
    }
    gdpicturePDF.CloseDocument();
            
    if (gdpicturePDF.LoadFromFile("compressed_pack_linearize.pdf", false) == GdPictureStatus.OK)
    {
        bool isLinearized = gdpicturePDF.IsLinearized();
        if (gdpicturePDF.GetStat() != GdPictureStatus.OK) goto error;
        if (isLinearized)
        {
            //This should be the correct case.
            MessageBox.Show("This file is linearized.", caption);
        }
        else
        {
            MessageBox.Show("This file is not linearized.", caption);
        }
    }
}
else
{
    MessageBox.Show("The file can't be loaded.", caption);
}
error:
gdpicturePDF.Dispose();
See Also