Topics   All   Mac OS X (Only)   Windows (Only)   Linux (Only, Not)   iOS (Only, Not)  
Components   Crossplatform Mac & Win   Server (Not)   Client   Old   Guides   Examples
New in version: 6.1   6.2   6.3   6.4   6.5   7.0   7.1   7.2   7.3   7.4    Statistic  

DynaPDF.Optimize

Optimizes PDF.

Component Version macOS Windows Server FileMaker Cloud FileMaker iOS SDK
DynaPDF 6.0 Yes Yes Yes Yes Yes

MBS( "DynaPDF.Optimize"; PDF { ; Flags; Min1BitRes; MinGrayRes; MinColorRes; Res1BitImages; ResGrayImages; ResColorImages; Filter1Bit; FilterGray; FilterColor; JPEGQuality; JP2KQuality; MinLineWidth } )

Parameters

Parameter Description Example value
PDF The PDF reference returned from DynaPDF.New. $pdf
Flags Optional
The flags to use. Can be a number with values from dynapdf documentation.
Or text containing flag values: InMemory, ConvertAllColors, IgnoreICCBased, ScaleAllImages, ScaleImages, NewLinkNames and DeleteInvPaths.
"ConvertAllColors,ScaleImages"
Min1BitRes Optional
Minimum resolution before scaling for one bit images.
Default is 100.
Can be zero to disable.
200
MinGrayRes Optional
Minimum resolution before scaling for gray images.
Default is 100.
Can be zero to disable.
200
MinColorRes Optional
Minimum resolution before scaling for color images.
Default is 100.
Can be zero to disable.
200
Res1BitImages Optional
Resolution for 1 bit black & white images.
Default is 150.
150
ResGrayImages Optional
Resolution for gray images.
Default is 150.
150
ResColorImages Optional
Resolution for images with more than one color channel.
Default is 150.
150
Filter1Bit Optional
Filter for black & white images.
Can be Flate, JPEG, CCITT3, CCITT4, LZW, FlateBW or JP2K.
Default is JPEG.
"JPEG"
FilterGray Optional
Filter for gray images.
Can be Flate, JPEG, CCITT3, CCITT4, LZW, FlateBW or JP2K.
Default is JPEG.
"JPEG"
FilterColor Optional
Filter for multi-channel images.
Can be Flate, JPEG, CCITT3, CCITT4, LZW, FlateBW or JP2K.
Default is JPEG.
"JPEG"
JPEGQuality Optional
JPEG quality.
Default is 80.
80
JP2KQuality Optional
JPEG 2000 quality
Default is 80.
80
MinLineWidth Optional
Minimum line width for lines.
Zero means no hair line removal.
0

Result

Returns OK or error.

Description

Optimizes PDF.
This repairs also a lot of errors in the PDF.

Possible flags:
Default0Just rebuild the content streams.
InMemory1Optimize the file fully in memory. Only useful for small PDF files.
ConvertAllColors2If set, Separation, DeviceN, and NChannel color spaces will be converted to the device space.
IgnoreICCBased4If set, ICCBased color spaces will be left unchanged.
ScaleImages8Scale also 1 bit images.
SkipMaskedImages16Meaningful only if ofScaleImages is set. If set, don't scale images with a color mask.
NewLinkNames32If set, rename all object links to short names like F1, F2 etc.
DeleteInvPaths64Delete invisible paths. An invisible path is a path that was finished with the no-op operator "n".
FlattenLayers128Flatten layers if any.
DeletePrivateData256Delete private data objects from pages, templates, and images. For example Indesign may store the original Photoshop image within the PDF file.
DeleteThumbnails512Thumbnails can be deleted since PDF viewers can create thumbnails easily on demand.
DeleteAlternateImages1024If set, alternate images will be deleted.
NoImageSizeCheck2048Meaningful only if ofScaleImages is set. If set, do not check whether the scaled image is smaller as the original image.
IgnoreZeroLineWidth4096Meaningful only if the parameter MinLineWidth of the TOptimizeParams structure is greater zero. If set, ignore line width operators with a value of zero (zero means one device unit).

Optimizing can fix bug in FileMaker 14 with empty portals resulting in broken PDF files.
Added optimization parameters for version 4 of DynaPDF. Requires a Pro license of DynaPDF.

See also Optimize function in DynaPDF manual.

Examples

Optimize by scaling images:

MBS( "DynaPDF.Optimize"; $pdf; "ScaleImages,IgnoreICCBased" )

Optimize with defaults:

MBS( "DynaPDF.Optimize"; $pdf)

Merge PDFs and optimize:

#Initialize DynaPDF if needed
If [$$DynaPDFInited ≠ 1]
    Perform Script [“InitDynaPDF”]
End If
#Clear current PDF document
Set Variable [$pdf; Value:MBS("DynaPDF.New")]
#For writing to file instead of container, pass path here:
// Set Variable [$r; Value:MBS("DynaPDF.OpenOutputFile"; $pdf; "/Users/cs/Desktop/test.pdf")]
#Load PDF from container
Go to Record/Request/Page [First]
Set Variable [$destPage; Value:1]
Loop
    #Read from file
    // Set Variable [$r; Value:MBS("DynaPDF.OpenPDFFromFile"; $pdf; "/Users/cs/Desktop/input.pdf")]
    #or container
    Set Variable [$r; Value:MBS("DynaPDF.OpenPDFFromContainer"; $pdf; Merge PDFs::InputPDF)]
    #Import all pages
    Set Variable [$r; Value:MBS("DynaPDF.ImportPDFFile"; $pdf; $destpage)]
    If [GetAsNumber($r) >0]
        Set Variable [$destPage; Value:$r+1]
    End If
    Go to Record/Request/Page [Next; Exit after last]
End Loop
#Repair & Optimize PDF
Set Variable [$r; Value:MBS("DynaPDF.Optimize"; $pdf)]
#Save to container
Set Field [Merge PDFs::FinalPDF; MBS("DynaPDF.Save"; $pdf; "Merged.pdf")]
Set Variable [$r; Value:MBS("DynaPDF.Release"; $pdf)]

Custom function for easy optimization:

# Custom Function OptimizePDF(InputPDF)
#
# Optimizes PDF and returns either new one or old one in case of error.

Let ([
PDF = MBS("DynaPDF.New");
OpenResult = MBS("DynaPDF.OpenPDFFromContainer"; PDF; InputPDF);
OpenError = MBS("IsError");
ImportResult = MBS("DynaPDF.ImportPDFFile"; PDF);
ImportError = MBS("IsError");
Options = "FlattenLayers DeleteInvPaths ScaleImages NewLinkNames DeletePrivateData IgnoreZeroLineWidth DeleteAlternateImages DeleteThumbnails";
OptimizeResult = MBS("DynaPDF.Optimize"; PDF; Options; 50; 50; 50; 150; 150; 150; "JPEG"; "JPEG"; "JPEG");
OptimizeError = MBS("IsError");
OutputPDF = MBS("DynaPDF.Save"; PDF; GetAsText(InputPDF));
SaveError = MBS("IsError");
ReleaseError = MBS("DynaPDF.Release"; PDF);

Result = If(
    // all okay?
    OpenError = 0 and ImportError = 0 and OptimizeError = 0 and SaveError = 0 and MBS( "Container.GetSize"; OutputPDF; "PDF " ) > 0;
    // than return new PDF
    OutputPDF;
    // return old PDF
    InputPDF)
 
];
result )

See also

Example Databases


DynaPDF.OpenPDFFromFile   -   DynaPDF.PageLink

Feedback: Report problem or ask question.




Links
MBS Xojo Chart Plugins