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

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