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

OpenMem Method

Opens an in-memory PDF file so that a series of operations may be performed on it.

Function OpenMem(InputStream As Variant,
                 [Password As String]) As PDFProcessorHandle

PDFProcessorHandle OpenMem(byte[] InputStream, string Password)

PDFProcessorHandle OpenMem(byte[] InputStream, string Password) throws PDFProcessorException

Parameters

Return Values

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

Remarks

OpenMem makes it possible to perform a series of operations on an in-memory 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 PDF must fit in memory at least twice, along with the input PDF. With large PDFs, it is possible to run out of memory, in which case PDF processing will fail.

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 VB.NET

Dim inMem() As Byte = File.ReadAllBytes("C:\test\input.pdf")
Dim oProcessor As PDFProcessor = Nothing
Dim oProcessorHandle As PDFProcessorHandle = Nothing
Try
   oProcessor = New PDFProcessor
   oProcessorHandle = oProcessor.OpenMem(inMem, 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)
   Dim outMem() As Byte = oProcessorHandle.CloseMem()
   File.WriteAllBytes("C:\test\output.pdf", outMem)
Catch ex As System.Runtime.InteropServices.COMException
   MessageBox.Show(ex.Message)
Finally
   oProcessorHandle.Close()
End Try

Example Usage in C#

byte[] inMem = File.ReadAllBytes(@"C:\test\input.pdf");
PDFProcessor oProcessor = null;
PDFProcessorHandle oProcessorHandle = null;
try
{
   oProcessor = new PDFProcessor();
   oProcessorHandle = oProcessor.OpenMem(inMem, 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);
   byte[] outMem = (byte[])oProcessorHandle.CloseMem();
   File.WriteAllBytes(@"C:\test\output.pdf", outMem);
}
catch(System.Runtime.InteropServices.COMException ex)
{
   MessageBox.Show(ex.Message);
}
finally
{
   oProcessorHandle.Close();
}