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

OptimizeBeforeClose Property

Gets/Sets the flag that indicates whether to optimize the PDF file when its file handle is closed.

Type

Boolean

Remarks

By default, this property inherits its state from the OptimizeAfterEachProcess property of the PDFProcessor object at the time OpenFile or OpenMem is called. If OptimizeAfterEachProcess is not set, then the default value of OptimizeBeforeClose is False.

If this property is set to True, then the Optimize method of the PDFProcessor object is automatically called when the handle to the PDF is closed.

Note that the PDFProcessorHandle class itself has no optimization function. Thus, the only way to optimize its output is to set OptimizeBeforeClose to True before calling Close or CloseMem, or to write its output to disk and then call Optimize from the PDFProcessor object on the physical file. The former approach is more efficient.

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.OptimizeBeforeClose = True
     
oProcessorHandle.Close
   

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)
      oProcessorHandle.OptimizeBeforeClose = True
   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);
      oProcessorHandle.OptimizeBeforeClose = true;
   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();
}