op.document.optimize

From PDF XChange PDF SDK
Jump to: navigation, search


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);
}