Reference Guide
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.

    Example
    How to load a text file and convert it into a PDF file.
    Dim caption As String = "Example: LoadFromFile"
    Using oGdPicturePDF As New GdPicturePDF()
        Dim status As GdPictureStatus = oGdPicturePDF.LoadFromFile("Text_File.txt", False)
        If status = GdPictureStatus.OK Then
            status = oGdPicturePDF.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
            oGdPicturePDF.CloseDocument()
        Else
            MessageBox.Show("The file can't be opened. Status: " + status.ToString(), caption)
        End If
    End Using
    string caption = "Example: LoadFromFile";
    using (GdPicturePDF oGdPicturePDF = new GdPicturePDF())
    {
        GdPictureStatus status = oGdPicturePDF.LoadFromFile("Text_File.txt", false);
        if (status == GdPictureStatus.OK)
        {
            status = oGdPicturePDF.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);
            }
            oGdPicturePDF.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 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.", caption)
                Else
                    MessageBox.Show("The file can't be saved. Status: " + status.ToString(), caption)
                End If
            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.", caption)
                    Else
                        MessageBox.Show("The file can't be saved. Status: " + status.ToString(), caption)
                    End If
                End If
                oGdPicturePDF.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 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.", caption);
                }
                else
                {
                    MessageBox.Show("The file can't be saved. Status: " + status.ToString(), caption);
                }
            }
            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.", caption);
                    }
                    else
                    {
                        MessageBox.Show("The file can't be saved. Status: " + status.ToString(), caption);
                    }
                }
                oGdPicturePDF.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