op.document.optimize

From PDF XChange PDF SDK
Jump to: navigation, search
(Created page with "Category:Editor {{#customTitle:op.document.optimize}} {{#parentPage:PXV:Operations|op.document.optimize|operation}} {{ToWrite}} {{ToReview}} == Overview == The operation...")
 
(Sample)
 
(5 intermediate revisions by 2 users not shown)
Line 2: Line 2:
 
{{#customTitle:op.document.optimize}}
 
{{#customTitle:op.document.optimize}}
 
{{#parentPage:PXV:Operations|op.document.optimize|operation}}
 
{{#parentPage:PXV:Operations|op.document.optimize|operation}}
{{ToWrite}}
 
 
{{ToReview}}
 
{{ToReview}}
  
 
== Overview ==
 
== Overview ==
The operation overview...
+
The operation allows to optimize the PDF document.
  
 
== Parameters ==
 
== Parameters ==
Line 16: 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.
 
|-
 
|-
 
| class="op_param_name" | Output
 
| class="op_param_name" | Output
 
| style="text-align:center;" | Array
 
| style="text-align:center;" | Array
| Array of <code>IUnknown</code>-based objects.
+
| Array of <code>IUnknown</code>-based objects. Not used.
 
|-
 
|-
 
| class="op_param_name" | [[PXV:op_document_optimize_Options|Options]]
 
| class="op_param_name" | [[PXV:op_document_optimize_Options|Options]]
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);
}