LoadFromFile Method (GdPicturePDF)
Loads the source document according to a file path you have specified. A PDF file is loaded straightforward, a text file is converted into the PDF document.
No other file formats are allowed. You can also specify, if the file will be loaded into memory or not according to the next file operation.
Be aware that the file is locked for another use if the parameter LoadInMemory is set to false.
'Declaration
Public Function LoadFromFile( _
ByVal As String, _
Optional ByVal As Boolean _
) As GdPictureStatus
Parameters
- FilePath
- The file path of the source document. Supported formats are text files and PDF files.
- LoadInMemory
- Specifies if the document content will be loaded into memory (true). Loading the document content directly into memory results in
a better manipulation performance, but it consumes more memory. If you load a file into memory, you can subsequently overwrite or delete the file.
The predefind value is false.
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.
How to load a text file and convert it into a PDF file.
Dim caption As String = "Example: LoadFromFile"
Using gdpicturePDF As New GdPicturePDF()
Dim status As GdPictureStatus = gdpicturePDF.LoadFromFile("Text_File.txt", False)
If status = GdPictureStatus.OK Then
status = gdpicturePDF.SaveToFile("PDF_File.pdf")
If status = GdPictureStatus.OK Then
MessageBox.Show("The PDF file has been saved successfully.", caption)
Else
MessageBox.Show("The file can't be saved. Status: " + status.ToString(), caption)
End If
gdpicturePDF.CloseDocument()
Else
MessageBox.Show("The file can't be opened. Status: " + status.ToString(), caption)
End If
End Using
string caption = "Example: LoadFromFile";
using (GdPicturePDF gdpicturePDF = new GdPicturePDF())
{
GdPictureStatus status = gdpicturePDF.LoadFromFile("Text_File.txt", false);
if (status == GdPictureStatus.OK)
{
status = gdpicturePDF.SaveToFile("PDF_File.pdf");
if (status == GdPictureStatus.OK)
{
MessageBox.Show("The PDF file has been saved successfully.", caption);
}
else
{
MessageBox.Show("The file can't be saved. Status: " + status.ToString(), caption);
}
gdpicturePDF.CloseDocument();
}
else
{
MessageBox.Show("The file can't be opened. Status: " + status.ToString(), caption);
}
}
How to utilize loading into memory feature for overwriting an existing file.
Dim caption As String = "Example: LoadFromFile"
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.", caption)
Else
MessageBox.Show("The file can't be saved. Status: " + status.ToString(), caption)
End If
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.", caption)
Else
MessageBox.Show("The file can't be saved. Status: " + status.ToString(), caption)
End If
End If
gdpicturePDF.CloseDocument()
Else
MessageBox.Show("The file can't be opened. Status: " + status.ToString(), caption)
End If
Else
MessageBox.Show("The file can't be opened. Status: " + status.ToString(), caption)
End If
End Using
string caption = "Example: LoadFromFile";
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.", caption);
}
else
{
MessageBox.Show("The file can't be saved. Status: " + status.ToString(), caption);
}
}
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.", caption);
}
else
{
MessageBox.Show("The file can't be saved. Status: " + status.ToString(), caption);
}
}
gdpicturePDF.CloseDocument();
}
else
{
MessageBox.Show("The file can't be opened. Status: " + status.ToString(), caption);
}
}
else
{
MessageBox.Show("The file can't be opened. Status: " + status.ToString(), caption);
}
}