GdPicture.NET.14
GdPicture14 Namespace / GdPicturePDF Class / LoadFromFile Method
The file path of the source document. Supported formats are text files and PDF files.
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.
Example





In This Topic
LoadFromFile Method (GdPicturePDF)
In This Topic
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.
Syntax
'Declaration
 
Public Function LoadFromFile( _
   ByVal FilePath As String, _
   Optional ByVal LoadInMemory As Boolean _
) As GdPictureStatus
public GdPictureStatus LoadFromFile( 
   string FilePath,
   bool LoadInMemory
)
public function LoadFromFile( 
    FilePath: String;
    LoadInMemory: Boolean
): GdPictureStatus; 
public function LoadFromFile( 
   FilePath : String,
   LoadInMemory : boolean
) : GdPictureStatus;
public: GdPictureStatus LoadFromFile( 
   string* FilePath,
   bool LoadInMemory
) 
public:
GdPictureStatus LoadFromFile( 
   String^ FilePath,
   bool LoadInMemory
) 

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.

Remarks
If you need to use the read/write access mode when loading the file, please use the LoadFromFileEx method. Be aware that the required file is locked for another use if you set the parameter LoadInMemory to false.

The origin's location and the measurement unit for any loaded document are reset to their default values: PdfOrigin.PdfOriginBottomLeft, PdfMeasurementUnit.PdfMeasurementUnitPoint.

The document's first page is automatically set as the current page after loading.

Sometimes a PDF document can be password protected. You can use the IsEncrypted method to determine if a PDF is encrypted or not. If it is encrypted, you should use the SetPassword method to decrypt it with the user or owner password.

This method requires the PDF Processing component to run.

Example
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);
    }
}
See Also