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
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.
Example
How to save an empty single page PDF document to a specified file path.
Using gdpicturePDF As New GdPicturePDF()
If gdpicturePDF.NewPDF() = GdPictureStatus.OK Then
Dim status As GdPictureStatus = gdpicturePDF.NewPage(500, 500)
If status = GdPictureStatus.OK Then
'If such a file exists, it will be overwritten.
status = gdpicturePDF.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
gdpicturePDF.CloseDocument()
End If
End Using
using (GdPicturePDF gdpicturePDF = new GdPicturePDF())
{
if (gdpicturePDF.NewPDF() == GdPictureStatus.OK)
{
GdPictureStatus status = gdpicturePDF.NewPage(500, 500);
if (status == GdPictureStatus.OK)
{
//If such a file exists, it will be overwritten.
status = gdpicturePDF.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");
}
}
gdpicturePDF.CloseDocument();
}
}
How to overwrite a currently opened PDF document.
Using gdpicturePDF As New GdPicturePDF()
'The file will load into memory.
Dim status As GdPictureStatus = gdpicturePDF.LoadFromFile("test.pdf", True)
If status = GdPictureStatus.OK Then
If gdpicturePDF.ClonePage(1) = GdPictureStatus.OK Then
'The file will be overwritten.
status = gdpicturePDF.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
gdpicturePDF.CloseDocument()
'The file will not load into memory.
status = gdpicturePDF.LoadFromFile("test.pdf", False)
If status = GdPictureStatus.OK Then
If gdpicturePDF.DeletePage(1) = GdPictureStatus.OK Then
'The file will not be overwritten.
status = gdpicturePDF.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
gdpicturePDF.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 gdpicturePDF = new GdPicturePDF())
{
//The file will load into memory.
GdPictureStatus status = gdpicturePDF.LoadFromFile("test.pdf", true);
if (status == GdPictureStatus.OK)
{
if (gdpicturePDF.ClonePage(1) == GdPictureStatus.OK)
{
//The file will be overwritten.
status = gdpicturePDF.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");
}
gdpicturePDF.CloseDocument();
//The file will not load into memory.
status = gdpicturePDF.LoadFromFile("test.pdf", false);
if (status == GdPictureStatus.OK)
{
if (gdpicturePDF.DeletePage(1) == GdPictureStatus.OK)
{
//The file will not be overwritten.
status = gdpicturePDF.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");
}
gdpicturePDF.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");
}
}
Example
Using gdpicturePDF As New GdPicturePDF()
If gdpicturePDF.NewPDF() = GdPictureStatus.OK Then
Dim status As GdPictureStatus = gdpicturePDF.NewPage(500, 500)
If status = GdPictureStatus.OK Then
'If such a file exists, it will be overwritten.
status = gdpicturePDF.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
gdpicturePDF.CloseDocument()
End If
End Using
using (GdPicturePDF gdpicturePDF = new GdPicturePDF())
{
if (gdpicturePDF.NewPDF() == GdPictureStatus.OK)
{
GdPictureStatus status = gdpicturePDF.NewPage(500, 500);
if (status == GdPictureStatus.OK)
{
//If such a file exists, it will be overwritten.
status = gdpicturePDF.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");
}
}
gdpicturePDF.CloseDocument();
}
}
Using gdpicturePDF As New GdPicturePDF()
'The file will load into memory.
Dim status As GdPictureStatus = gdpicturePDF.LoadFromFile("test.pdf", True)
If status = GdPictureStatus.OK Then
If gdpicturePDF.ClonePage(1) = GdPictureStatus.OK Then
'The file will be overwritten.
status = gdpicturePDF.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
gdpicturePDF.CloseDocument()
'The file will not load into memory.
status = gdpicturePDF.LoadFromFile("test.pdf", False)
If status = GdPictureStatus.OK Then
If gdpicturePDF.DeletePage(1) = GdPictureStatus.OK Then
'The file will not be overwritten.
status = gdpicturePDF.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
gdpicturePDF.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 gdpicturePDF = new GdPicturePDF())
{
//The file will load into memory.
GdPictureStatus status = gdpicturePDF.LoadFromFile("test.pdf", true);
if (status == GdPictureStatus.OK)
{
if (gdpicturePDF.ClonePage(1) == GdPictureStatus.OK)
{
//The file will be overwritten.
status = gdpicturePDF.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");
}
gdpicturePDF.CloseDocument();
//The file will not load into memory.
status = gdpicturePDF.LoadFromFile("test.pdf", false);
if (status == GdPictureStatus.OK)
{
if (gdpicturePDF.DeletePage(1) == GdPictureStatus.OK)
{
//The file will not be overwritten.
status = gdpicturePDF.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");
}
gdpicturePDF.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