Reference Guide
GdPicture14 Namespace / GdPicturePDF Class / SaveToFile Method / SaveToFile(String) 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 LoadFromFile method.

Example





In This Topic
    SaveToFile(String) Method
    In This Topic
    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 _
    ) As GdPictureStatus
    public GdPictureStatus SaveToFile( 
       string FilePath
    )
    public function SaveToFile( 
        FilePath: String
    ): GdPictureStatus; 
    public function SaveToFile( 
       FilePath : String
    ) : GdPictureStatus;
    public: GdPictureStatus SaveToFile( 
       string* FilePath
    ) 
    public:
    GdPictureStatus SaveToFile( 
       String^ FilePath
    ) 

    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 LoadFromFile method.

    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
    You have to specify a full file path with the correct file extension, which is "pdf".
    Example
    How to save an empty single page PDF document to a specified file path.
    Using oGdPicturePDF As New GdPicturePDF()
        If oGdPicturePDF.NewPDF() = GdPictureStatus.OK Then
            Dim status As GdPictureStatus = oGdPicturePDF.NewPage(500, 500)
            If status = GdPictureStatus.OK Then
                'If such a file exists, it will be overwritten.
                status = oGdPicturePDF.SaveToFile("new_file.pdf")
                If status = GdPictureStatus.OK Then
                    MessageBox.Show("The PDF file has been saved successfully.", "Example: SaveToFile")
                Else
                    MessageBox.Show("The file can't be saved. Status: " + status.ToString(), "Example: SaveToFile")
                End If
            End If
            oGdPicturePDF.CloseDocument()
        End If
    End Using
    using (GdPicturePDF oGdPicturePDF = new GdPicturePDF())
    {
        if (oGdPicturePDF.NewPDF() == GdPictureStatus.OK)
        {
            GdPictureStatus status = oGdPicturePDF.NewPage(500, 500);
            if (status == GdPictureStatus.OK)
            {
                //If such a file exists, it will be overwritten.
                status = oGdPicturePDF.SaveToFile("new_file.pdf");
                if (status == GdPictureStatus.OK)
                {
                    MessageBox.Show("The PDF file has been saved successfully.", "Example: SaveToFile");
                }
                else
                {
                    MessageBox.Show("The file can't be saved. Status: " + status.ToString(), "Example: SaveToFile");
                }
            }
            oGdPicturePDF.CloseDocument();
        }
    }
    How to overwrite a currently opened PDF document.
    Using oGdPicturePDF As New GdPicturePDF()
        'The file will load into memory.
        Dim status As GdPictureStatus = oGdPicturePDF.LoadFromFile("test.pdf", True)
        If status = GdPictureStatus.OK Then
            If oGdPicturePDF.ClonePage(1) = GdPictureStatus.OK Then
                'The file will be overwritten.
                status = oGdPicturePDF.SaveToFile("test.pdf")
                If status = GdPictureStatus.OK Then
                    MessageBox.Show("The PDF file has been overwritten and saved successfully.", "Example: SaveToFile")
                Else
                    MessageBox.Show("The file can't be saved. Status: " + status.ToString(), "Example: SaveToFile")
                End If
                oGdPicturePDF.CloseDocument()
                'The file will not load into memory.
                status = oGdPicturePDF.LoadFromFile("test.pdf", False)
                If status = GdPictureStatus.OK Then
                    If oGdPicturePDF.DeletePage(1) = GdPictureStatus.OK Then
                        'The file will not be overwritten.
                        status = oGdPicturePDF.SaveToFile("test.pdf")
                        If status = GdPictureStatus.OK Then
                            MessageBox.Show("The PDF file has been overwritten and saved successfully.", "Example: SaveToFile")
                        Else
                            MessageBox.Show("The file can't be saved. Status: " + status.ToString(), "Example: SaveToFile")
                        End If
                        oGdPicturePDF.CloseDocument()
                    End If
                Else
                    MessageBox.Show("The file can't be opened. Status: " + status.ToString(), "Example: SaveToFile")
                End If
            End If
        Else
            MessageBox.Show("The file can't be opened. Status: " + status.ToString(), "Example: SaveToFile")
        End If
    End Using
    using (GdPicturePDF oGdPicturePDF = new GdPicturePDF())
    {
        //The file will load into memory.
        GdPictureStatus status = oGdPicturePDF.LoadFromFile("test.pdf", true);
        if (status == GdPictureStatus.OK)
        {
            if (oGdPicturePDF.ClonePage(1) == GdPictureStatus.OK)
            {
                //The file will be overwritten.
                status = oGdPicturePDF.SaveToFile("test.pdf");
                if (status == GdPictureStatus.OK)
                {
                    MessageBox.Show("The PDF file has been overwritten and saved successfully.", "Example: SaveToFile");
                }
                else
                {
                    MessageBox.Show("The file can't be saved. Status: " + status.ToString(), "Example: SaveToFile");
                }
                oGdPicturePDF.CloseDocument();
                //The file will not load into memory.
                status = oGdPicturePDF.LoadFromFile("test.pdf", false);
                if (status == GdPictureStatus.OK)
                {
                    if (oGdPicturePDF.DeletePage(1) == GdPictureStatus.OK)
                    {
                        //The file will not be overwritten.
                        status = oGdPicturePDF.SaveToFile("test.pdf");
                        if (status == GdPictureStatus.OK)
                        {
                            MessageBox.Show("The PDF file has been overwritten and saved successfully.", "Example: SaveToFile");
                        }
                        else
                        {
                            MessageBox.Show("The file can't be saved. Status: " + status.ToString(), "Example: SaveToFile");
                        }
                        oGdPicturePDF.CloseDocument();
                    }
                }
                else
                {
                    MessageBox.Show("The file can't be opened. Status: " + status.ToString(), "Example: SaveToFile");
                }
            }
        }
        else
        {
            MessageBox.Show("The file can't be opened. Status: " + status.ToString(), "Example: SaveToFile");
        }
    }
    See Also