GdPicture.NET.14
GdPicture14 Namespace / GdPicturePDF Class / LoadFromFileEx Method
The file path of the source document. Supported formats are text files and PDF files.
Specifies if the file should be opened in read/write access mode (true).

Setting this parameter to true allows you to subsequently save the modified parts of the handled PDF document to the same source file.

Example





In This Topic
LoadFromFileEx 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 an access to the loaded file, which can be read or read/write according to the next file operation. This method can be useful if you need to allow access to the required file from more sources.
Syntax
'Declaration
 
Public Function LoadFromFileEx( _
   ByVal FilePath As String, _
   ByVal OpenReadWrite As Boolean _
) As GdPictureStatus
public GdPictureStatus LoadFromFileEx( 
   string FilePath,
   bool OpenReadWrite
)
public function LoadFromFileEx( 
    FilePath: String;
    OpenReadWrite: Boolean
): GdPictureStatus; 
public function LoadFromFileEx( 
   FilePath : String,
   OpenReadWrite : boolean
) : GdPictureStatus;
public: GdPictureStatus LoadFromFileEx( 
   string* FilePath,
   bool OpenReadWrite
) 
public:
GdPictureStatus LoadFromFileEx( 
   String^ FilePath,
   bool OpenReadWrite
) 

Parameters

FilePath
The file path of the source document. Supported formats are text files and PDF files.
OpenReadWrite
Specifies if the file should be opened in read/write access mode (true).

Setting this parameter to true allows you to subsequently save the modified parts of the handled PDF document to the same source file.

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
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
This example shows you how to open a PDF document in read/write access mode. We add a text line on the document's first page and then we save this modification using incremental saving.
Dim caption As String = "Example: LoadFromFileEx"
Using gdpicturePDF As New GdPicturePDF()
    'The file access mode will be read/write.
    Dim status As GdPictureStatus = gdpicturePDF.LoadFromFileEx("test.pdf", True)
    If status = GdPictureStatus.OK Then
        Dim fontRes As String = gdpicturePDF.AddStandardFont(PdfStandardFont.PdfStandardFontCourier)
        status = gdpicturePDF.GetStat()
        If status = GdPictureStatus.OK Then
            If (gdpicturePDF.SetTextSize(20) = GdPictureStatus.OK) AndAlso
               (gdpicturePDF.DrawText(fontRes, 10, 10, "The quick brown fox jumps over the lazy dog.") = GdPictureStatus.OK) Then
                If gdpicturePDF.SaveToFileInc("test.pdf") = GdPictureStatus.OK Then
                    MessageBox.Show("The PDF file has been saved and overwritten successfully.", caption)
                End If
            End If
        End If
    Else
        MessageBox.Show("The file can't be loaded.", caption)
    End If
End Using
string caption = "Example: LoadFromFileEx";
using (GdPicturePDF gdpicturePDF = new GdPicturePDF())
{
    //The file access mode will be read/write.
    GdPictureStatus status = gdpicturePDF.LoadFromFileEx("test.pdf", true);
    if (status == GdPictureStatus.OK)
    {
        string fontRes = gdpicturePDF.AddStandardFont(PdfStandardFont.PdfStandardFontCourier);
        status = gdpicturePDF.GetStat();
        if (status == GdPictureStatus.OK)
        {
            if ((gdpicturePDF.SetTextSize(20) == GdPictureStatus.OK) &&
                (gdpicturePDF.DrawText(fontRes, 10, 10, "The quick brown fox jumps over the lazy dog.") == GdPictureStatus.OK))
            {
                if (gdpicturePDF.SaveToFileInc("test.pdf") == GdPictureStatus.OK)
                {
                    MessageBox.Show("The PDF file has been saved and overwritten successfully.", caption);
                }
            }
        }
    }
    else
    {
        MessageBox.Show("The file can't be loaded.", caption);
    }
}
How to merge two PDF documents using incremental saving feature. Incremental updates (see also PDF Reference) help to reduce memory usage and dramatically increase performance during the merging process. This example shows you how to load the PDF file to be able to save the result to the same source file.
Dim caption As String = "Example: LoadFromFileEx"
Dim oSrcPDF As New GdPicturePDF()
Dim oDstPDF As New GdPicturePDF()
'File access mode will be read/write.
Dim status As GdPictureStatus = oDstPDF.LoadFromFileEx("doc1.pdf", True)
If status = GdPictureStatus.OK Then
    'The file will not load into memory.
    status = oSrcPDF.LoadFromFile("doc2.pdf", False)
    If status = GdPictureStatus.OK Then
        Dim srcPageCount As Integer = oSrcPDF.GetPageCount()
        status = oSrcPDF.GetStat()
        If status = GdPictureStatus.OK Then
            For i As Integer = 1 To srcPageCount
                status = oDstPDF.ClonePage(oSrcPDF, i)
                If status <> GdPictureStatus.OK Then
                    MessageBox.Show("The ClonePage() method has failed on the page " + i.ToString() + " with the status:" + status.ToString(), caption)
                    Exit For
                End If
            Next
            If status = GdPictureStatus.OK Then
                If oDstPDF.SaveToFileInc("doc1.pdf") = GdPictureStatus.OK Then
                    MessageBox.Show("The PDF file has been overwritten and saved successfully.", caption)
                End If
            End If
        End If
    Else
        MessageBox.Show("The source file can't be loaded.", caption)
    End If
Else
    MessageBox.Show("The destination file can't be loaded.", caption)
End If
oDstPDF.Dispose()
oSrcPDF.Dispose()
string caption = "Example: LoadFromFileEx";
GdPicturePDF oSrcPDF = new GdPicturePDF();
GdPicturePDF oDstPDF = new GdPicturePDF();
//File access mode will be read/write.
GdPictureStatus status = oDstPDF.LoadFromFileEx("doc1.pdf", true);
if (status == GdPictureStatus.OK)
{
    //The file will not load into memory.
    status = oSrcPDF.LoadFromFile("doc2.pdf", false);
    if (status == GdPictureStatus.OK)
    {
        int srcPageCount = oSrcPDF.GetPageCount();
        status = oSrcPDF.GetStat();
        if (status == GdPictureStatus.OK)
        {
            for (int i = 1; i <= srcPageCount; i++)
            {
                status = oDstPDF.ClonePage(oSrcPDF, i);
                if (status != GdPictureStatus.OK)
                {
                    MessageBox.Show("The ClonePage() method has failed on the page " + i.ToString() + " with the status:" + status.ToString(), caption);
                    break;
                }
            }
            if (status == GdPictureStatus.OK)
            {
                if (oDstPDF.SaveToFileInc("doc1.pdf") == GdPictureStatus.OK)
                    MessageBox.Show("The PDF file has been overwritten and saved successfully.", caption);
            }
        }
    }
    else
        MessageBox.Show("The source file can't be loaded.", caption);
}
else
    MessageBox.Show("The destination file can't be loaded.", caption);
oDstPDF.Dispose();
oSrcPDF.Dispose();
See Also