BCL easyPDF SDK
easyPDF SDK Usermanual
PDF Creator Programming API  |  Download Free Trial  |  Contact Us to Purchase

OpenFile Method

Opens a physical (on disk) PDF file so that a series of operations may be performed on it.

Function OpenFile(InputFileName As String,
                  OutputFileName As String,
                  [Password As String]) As PDFProcessorHandle

PDFProcessorHandle OpenFile(string InputFileName, string OutputFileName, string Password)

PDFProcessorHandle OpenFile(String InputFileName, String OutputFileName, String Password) throws PDFProcessorException

Parameters

Return Values

Upon success, a handle of type PDFProcessorHandle to the file being opened is returned.

Remarks

OpenFile makes it possible to perform a series of operations on a PDF file without having to close and re-parse the PDF after each operation, thus optimizing performance.

The function returns a PDFProcessorHandle object, which can then be used to operate on the PDF. The handle must be closed after you are done, even if no modifications have been made to the PDF.

Note that the output file name must be specified upon file opening. If you do not plan to make any modifications to the PDF, simply make the output filename the same as the input.

Note on Password Parameter:

Supplying the owner password for an encrypted input PDF will always allow you to process it, thus the owner password is preferred if available. However, in some cases, just the user password will suffice. Whether the user password is sufficient depends on what functions you call on the PDF and what security settings it is encrypted with.

GetPageCount, GetPageRotation, and GetPageSize will always work with the user password.

Optimizing an encrypted file with OptimizeBeforeClose, removing encryption using CloseDecrypt or CloseMemDecrypt, or re-encrypting an encrypted file with different security settings (for example password and permissions) using CloseEncrypt or CloseMemEncrypt always require the owner password.

Other function calls, however, can succeed with only the user password if the required permissions have been granted via the user password. These are as follows.

AddAttachment, AddFreeText, AddHyperlink, AddNote, AddRubberStamp, AddSquareCircle: Work if the user password allows annotation modification permissions.

ExtractAllBookmarks, ExtractAllHyperlinks, GetDocumentInfo: Work if the user password allows extraction permissions.

RotatePages, AppendBookmark, DeleteAllBookmarks: Work if the user password allows either full editing or document assembly permissions.

SetDocumentInfo, SetDocumentInfoXMP, AddStamp, AddStamp2, AddTrueTypePDFText, AddWatermark: Work if the user password allows full editing permissions.

Example Usage in VBScript

Set oProcessor = CreateObject("easyPDF.PDFProcessor.8")
Set oProcessorHandle = oProcessor.OpenFile("C:\test\input.pdf", "C:\test\output.pdf")
oProcessorHandle.AddHyperlink 0, _
                              0, _
                              50, _
                              80, _
                              370, _
                              100, _
                              "http://www.bcltechnologies.com/", _
                              PRC_BORDERSTYLE_DASHLINE_MEDIUM, _
                              RGB(255, 0, 0)
oProcessorHandle.AddStamp "C:\test\image.jpg", _
                          0, _
                          PRC_STAMP_HPOS_CENTER, _
                          PRC_STAMP_VPOS_CENTER, _
                          PRC_STAMP_ZORDER_TOP, _
                          0, _
                          0, _
                          0, _
                          100
oProcessorHandle.Close

Example Usage in VB.NET

Dim oProcessor As PDFProcessor = Nothing
Dim oProcessorHandle As PDFProcessorHandle = Nothing
Try
   oProcessor = New PDFProcessor
      oProcessorHandle = oProcessor.OpenFile("C:\test\input.pdf", "C:\test\output.pdf", Nothing)
   oProcessorHandle.AddHyperlink(0, _
                                 0, _
                                 50, _
                                 80, _
                                 370, _
                                 100, _
                                 "http://www.bcltechnologies.com", _
                                 prcAnnotBorderStyle.PRC_BORDERSTYLE_DASHLINE_MEDIUM, _
                                 0)
   oProcessorHandle.AddStamp("C:\test\image.jpg", _
                             0, _
                             prcStampHPosition.PRC_STAMP_HPOS_CENTER, _
                             prcStampVPosition.PRC_STAMP_VPOS_CENTER, _
                             prcStampZOrder.PRC_STAMP_ZORDER_TOP, _
                             0, _
                             0, _
                             0, _
                             100)
Catch ex As System.Runtime.InteropServices.COMException
   MessageBox.Show(ex.Message)
Finally
   oProcessorHandle.Close()
End Try

Example Usage in C#

PDFProcessor oProcessor = null;
PDFProcessorHandle oProcessorHandle = null;
try
{
   oProcessor = new PDFProcessor();
      oProcessorHandle = oProcessor.OpenFile(@"C:\test\input.pdf", @"C:\test\output.pdf", null);
   oProcessorHandle.AddHyperlink(0, 
                                 0, 
                                 50, 
                                 80, 
                                 370, 
                                 100, 
                                 "http://www.bcltechnologies.com", 
                                 prcAnnotBorderStyle.PRC_BORDERSTYLE_DASHLINE_MEDIUM, 
                                 0);
   oProcessorHandle.AddStamp(@"C:\test\image.jpg", 
                             0, 
                             prcStampHPosition.PRC_STAMP_HPOS_CENTER, 
                             prcStampVPosition.PRC_STAMP_VPOS_CENTER, 
                             prcStampZOrder.PRC_STAMP_ZORDER_TOP, 
                             0,
                             0, 
                             0, 
                             100);
}
catch(System.Runtime.InteropServices.COMException ex)
{
   MessageBox.Show(ex.Message);
}
finally
{
oProcessorHandle.Close();
}