The OptimizeDocument method is used to optimize the document before editing or exporting to other formats.
The text inside a PDF file is usually split into multiple parts, a single sentence or paragraph can consist of multiple pieces of text positioned independently inside the PDF document. This method attempts to regroup lines or paragraphs prior to exporting the PDF file into another format, or to make the file easier to edit.
Sub OptimizeDocument(Level As Integer)
void OptimizeDocument(int Level)
HRESULT OptimizeDocument(long Level)
Level
Optimization Level |
Value |
Description |
---|---|---|
No optimization |
0 |
Recommended when exporting to JPEG and Tiff formats. |
Line optimization |
1 |
Recommended when exporting to RTF format. |
Paragraph optimization |
2 |
Recommended when exporting to HTML format. |
Table optimization |
3 |
Recommended when exporting to Excel format. |
The screen shots below show the borders of text objects of a document at different stages of optimization.
See also the ExportToExcel, ExportToHTML, ExportToHTMLEx, ExportToJPeg, ExportToRTF, ExportToTiff, ExportToXPS sections.
<Flags>
Public Enum OPTIMIZATION_LEVEL
NO_OPTIMIZATION = 0
LINE_OPTIMIZATION = 1
PARAGRAPH_OPTIMIZATION = 2
TABLE_OPTIMIZATION = 3
End Enum
Sub Sample()
' Constants for Activation codes
Const strLicenseTo As String = "Amyuni PDF Creator Evaluation"
Const strActivationCode As String = "07EFCDAB010001004282943F2AF19A88F332D9E781E40460727DF8A42847A1BDE06DB61C71E94E2D90424BF8762385335F9D6884E9FC"
' Initializing PDFCreativeX Object
Dim pdf As ACPDFCREACTIVEX.PDFCreactiveX = New ACPDFCREACTIVEX.PDFCreactiveX()
' Set license key
pdf.SetLicenseKey(strLicenseTo, strActivationCode)
' Open an existent PDF file
Dim fileName As String = "c:\temp\PDFdocument.pdf"
Dim password As String = ""
pdf.Open(fileName, password)
' Optimization
Dim level As Integer = OPTIMIZATION_LEVEL.TABLE_OPTIMIZATION
pdf.OptimizeDocument(level)
' Exporting
Dim outFileName As String = "c:\temp\file.xls"
Dim options As ACPDFCREACTIVEX.acExcelExportOptions = ACPDFCREACTIVEX.acExcelExportOptions.acExcelExportOptionMultipleSheets
pdf.ExportToExcel(outFileName, options)
End Sub
[Flags]
public enum OPTIMIZATION_LEVEL
{
NO_OPTIMIZATION = 0,
LINE_OPTIMIZATION = 1,
PARAGRAPH_OPTIMIZATION = 2,
TABLE_OPTIMIZATION = 3
}
static void Sample()
{
// Constants for Activation codes
const string strLicenseTo = "Amyuni PDF Creator Evaluation";
const string strActivationCode = "07EFCDAB010001004282943F2AF19A88F332D9E781E40460727DF8A42847A1BDE06DB61C71E94E2D90424BF8762385335F9D6884E9FC";
// Initializing PDFCreativeX Object
ACPDFCREACTIVEX.PDFCreactiveX pdf = new ACPDFCREACTIVEX.PDFCreactiveX();
// Set license key
pdf.SetLicenseKey(strLicenseTo, strActivationCode);
// Open an existent PDF file
string fileName = @"c:\temp\PDFdocument.pdf";
string password = "";
pdf.Open(fileName, password);
// Optimization
int level = (int)OPTIMIZATION_LEVEL.TABLE_OPTIMIZATION;
pdf.OptimizeDocument(level);
// Exporting
string outFileName = @"c:\temp\file.xls";
ACPDFCREACTIVEX.acExcelExportOptions options = ACPDFCREACTIVEX.acExcelExportOptions.acExcelExportOptionMultipleSheets;
pdf.ExportToExcel(outFileName, options);
}
#include <iostream>
#import "c:\users\amyuni\pdfcreactivex.dll" no_namespace
using namespace std;
enum OPTIMIZATION_LEVEL
{
NO_OPTIMIZATION = 0,
LINE_OPTIMIZATION = 1,
PARAGRAPH_OPTIMIZATION = 2,
TABLE_OPTIMIZATION = 3
};
int main()
{
// Constants for Activation codes
bstr_t strLicenseTo = "Amyuni PDF Creator Evaluation";
bstr_t strActivationCode = "07EFCDAB010001004282943F2AF19A88F332D9E781E40460727DF8A42847A1BDE06DB61C71E94E2D90424BF8762385335F9D6884E9FC";
// Initialize the COM subsystem
CoInitialize(0);
// IPDFCreactiveXPtr is a smart pointer type defined in pdfcreactivex.tlh,
// the type library header file generated by the #import instruction above
IPDFCreactiveXPtr pdf;
// Create the PDFCreactiveX instance
pdf.CreateInstance(__uuidof(PDFCreactiveX));
// set license key
pdf->SetLicenseKey(_bstr_t(strLicenseTo), _bstr_t(strActivationCode));
// Open an existent PDF file
_bstr_t fileName = "c:\\temp\\PDFdocument.pdf";
_bstr_t password = "";
pdf->Open(fileName, password);
// Optimization
int level = (int)TABLE_OPTIMIZATION;
pdf->OptimizeDocument(level);
// Exporting
bstr_t outFileName = "c:\\temp\\file.xls";
acExcelExportOptions options = acExcelExportOptionMultipleSheets;
pdf->ExportToExcel(outFileName, options);
// destroy objects
pdf = NULL;
return 0;
}
' acExcelExportOptions
Const acExcelExportDecimalSeparator_Comma = 2
Const acExcelExportOptionMultipleSheets = 1
Const acExcelExportOptionSingleSheet = 0
' Optimization level
Const NO_OPTIMIZATION = 0
Const LINE_OPTIMIZATION = 1
Const PARAGRAPH_OPTIMIZATION = 2
Const TABLE_OPTIMIZATION = 3
' Constants for Activation codes
Const strLicenseTo = "Amyuni PDF Creator Evaluation"
Const strActivationCode = "07EFCDAB010001004282943F2AF19A88F332D9E781E40460727DF8A42847A1BDE06DB61C71E94E2D90424BF8762385335F9D6884E9FC"
' Initializing PDFCreativeX Object
Dim pdf
Set pdf = CreateObject("PDFCreactiveX.PDFCreactiveX.6.5")
' Set license key
pdf.SetLicenseKey strLicenseTo, strActivationCode
' Open an existent PDF file
Dim fileName
fileName = "c:\temp\PDFdocument.pdf"
Dim password
password = ""
pdf.Open fileName, password
' Optimization
Dim level
level = TABLE_OPTIMIZATION
pdf.OptimizeDocument level
' Exporting
Dim outFileName
outFileName = "c:\temp\file.xls"
Dim options
options = acExcelExportOptionMultipleSheets
pdf.ExportToExcel outFileName, options
' destroy objects
Set pdf = Nothing