op.document.optimize

From PDF XChange PDF SDK
Jump to: navigation, search
(Sample)
 
(2 intermediate revisions by the same user not shown)
Line 5: Line 5:
  
 
== Overview ==
 
== Overview ==
The operation allows to optimize PDF document.
+
The operation allows to optimize the PDF document.
  
 
== Parameters ==
 
== Parameters ==
Line 15: Line 15:
 
| class="op_param_name" | Input
 
| class="op_param_name" | Input
 
| style="text-align:center" | Array
 
| style="text-align:center" | Array
| Array of <code>IUnknown</code>-based objects.
+
| Array of <code>IUnknown</code>-based objects that should contain the [[PXV:IPXC_Document|IPXC_Document]] that will be optimized. Note that only the first element from the array will be evaluated.
The first element of array contain the [[PXV:IPXC_Document|IPXC_Document]] which will be optimized. This document will be rewritten resulting document. The other elements are ignored.
+
 
|-
 
|-
 
| class="op_param_name" | Output
 
| class="op_param_name" | Output
Line 26: Line 25:
 
| Dictionary with options of the operation.
 
| Dictionary with options of the operation.
 
|}
 
|}
 +
 +
== Sample ==
 +
<pre class="brush:c#">//C#
 +
private void OptimizeDocument(PDFXEdit.IPXV_Document Doc, PDFXEdit.IPXV_Inst Inst)
 +
{
 +
int nID = Inst.Str2ID("op.document.optimize", false);
 +
PDFXEdit.IOperation Op = Inst.CreateOp(nID);
 +
var input = Op.Params.Root["Input"];
 +
//The document can be optimized only when it's not opened in the Editor Control (it does not have the correspondent IPXV_Document)
 +
PDFXEdit.IAFS_Inst fsInst = (PDFXEdit.IAFS_Inst)Inst.GetExtension("AFS");
 +
PDFXEdit.IAFS_Name impPath = fsInst.DefaultFileSys.StringToName("D:\\TestFile_res.pdf");
 +
//We save it on disk
 +
Doc.CoreDoc.WriteTo(impPath);
 +
PDFXEdit.IPXC_Inst pxcInst = (PDFXEdit.IPXC_Inst)Inst.GetExtension("PXC");
 +
PDFXEdit.IPXC_Document resDoc = pxcInst.OpenDocumentFrom(impPath, null);
 +
//Then pass it to the optimization operation
 +
input.Add().v = resDoc;
 +
PDFXEdit.ICabNode options = Op.Params.Root["Options"];
 +
PDFXEdit.ICabNode images = options["Images"];
 +
images["Enabled"].v = true;
 +
images["ReducedOnly"].v = true;
 +
PDFXEdit.ICabNode comp = images["Comp"];
 +
comp["Color.JPEGQuality"].v = 0;
 +
comp["Grayscale.JPEGQuality"].v = 0;
 +
Op.Do();
 +
//And save the optimized document again to the same file
 +
resDoc.WriteTo(impPath);
 +
}
 +
</pre>

Latest revision as of 06:09, 19 April 2016


Overview

The operation allows to optimize the PDF document.

Parameters

Name Type Description
Input Array Array of IUnknown-based objects that should contain the IPXC_Document that will be optimized. Note that only the first element from the array will be evaluated.
Output Array Array of IUnknown-based objects. Not used.
Options Dictionary Dictionary with options of the operation.

Sample

//C#
private void OptimizeDocument(PDFXEdit.IPXV_Document Doc, PDFXEdit.IPXV_Inst Inst)
{
	int nID = Inst.Str2ID("op.document.optimize", false);
	PDFXEdit.IOperation Op = Inst.CreateOp(nID);
	var input = Op.Params.Root["Input"];
	//The document can be optimized only when it's not opened in the Editor Control (it does not have the correspondent IPXV_Document)
	PDFXEdit.IAFS_Inst fsInst = (PDFXEdit.IAFS_Inst)Inst.GetExtension("AFS");
	PDFXEdit.IAFS_Name impPath = fsInst.DefaultFileSys.StringToName("D:\\TestFile_res.pdf");
	//We save it on disk
	Doc.CoreDoc.WriteTo(impPath);
	PDFXEdit.IPXC_Inst pxcInst = (PDFXEdit.IPXC_Inst)Inst.GetExtension("PXC");
	PDFXEdit.IPXC_Document resDoc = pxcInst.OpenDocumentFrom(impPath, null);
	//Then pass it to the optimization operation
	input.Add().v = resDoc;
	PDFXEdit.ICabNode options = Op.Params.Root["Options"];
	PDFXEdit.ICabNode images = options["Images"];
	images["Enabled"].v = true;
	images["ReducedOnly"].v = true;
	PDFXEdit.ICabNode comp = images["Comp"];
	comp["Color.JPEGQuality"].v = 0;
	comp["Grayscale.JPEGQuality"].v = 0;
	Op.Do();
	//And save the optimized document again to the same file
	resDoc.WriteTo(impPath);
}