Components | All | New | MacOS | Windows | Linux | iOS | ||||
Examples | Mac & Win | Server | Client | Guides | Statistic | FMM | Blog | Deprecated | Old |
DynaPDF.Optimize
Optimizes PDF.
Component | Version | macOS | Windows | Linux | Server | iOS SDK |
DynaPDF | 6.0 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |
Parameters
Parameter | Description | Example | Flags |
---|---|---|---|
The PDF reference. | |||
Flags | The flags to use. Can be a number with values from dynapdf documentation, see table on this page. |
"ConvertAllColors,ScaleImages" | Optional |
Min1BitRes | Minimum resolution before scaling for one bit images. Default is 100. Can be zero to disable. |
200 | Optional |
MinGrayRes | Minimum resolution before scaling for gray images. Default is 100. Can be zero to disable. |
200 | Optional |
MinColorRes | Minimum resolution before scaling for color images. Default is 100. Can be zero to disable. |
200 | Optional |
Res1BitImages | Resolution for 1 bit black & white images. Default is 150. |
150 | Optional |
ResGrayImages | Resolution for gray images. Default is 150. |
150 | Optional |
ResColorImages | Resolution for images with more than one color channel. Default is 150. |
150 | Optional |
Filter1Bit | Filter for black & white images. Can be Flate, JPEG, CCITT3, CCITT4, LZW, FlateBW or JP2K. Default is JPEG. |
"JPEG" | Optional |
FilterGray | Filter for gray images. Can be Flate, JPEG, CCITT3, CCITT4, LZW, FlateBW or JP2K. Default is JPEG. |
"JPEG" | Optional |
FilterColor | Filter for multi-channel images. Can be Flate, JPEG, CCITT3, CCITT4, LZW, FlateBW or JP2K. Default is JPEG. |
"JPEG" | Optional |
JPEGQuality | JPEG quality. Default is 80. |
80 | Optional |
JP2KQuality | JPEG 2000 quality Default is 80. |
80 | Optional |
MinLineWidth | Minimum line width for lines. Zero means no hair line removal. |
0 | Optional |
Result
Returns OK or error.
Description
Optimizes PDF.This repairs also a lot of errors in the PDF and can shrink the PDF size.
Name | Value | Description |
Default | 0 | Just rebuild the content streams. |
InMemory | 1 | Optimize the file fully in memory. Only useful for small PDF files. |
ConvertAllColors | 2 | If set, Separation, DeviceN, and NChannel color spaces will be converted to the device space. |
IgnoreICCBased | 4 | If set, ICCBased color spaces will be left unchanged. |
ScaleImages | 8 | Scale images as specified in the TOptimizeParams structure. |
SkipMaskedImages | 16 | Meaningful only if ofScaleImages is set. If set, don't scale images with a color mask. |
NewLinkNames | 32 | If set, rename all object links to short names like F1, F2 etc. |
DeleteInvPaths | 64 | Delete invisible paths. An invisible path is a path that was finished with the no-op operator "n". |
FlattenLayers | 128 | Flatten layers if any. |
DeletePrivateData | 256 | Delete private data objects from pages, templates, and images. |
DeleteThumbnails | 512 | Thumbnails can be deleted since PDF viewers can create thumbnails easily on demand. |
DeleteAlternateImages | 1024 | If set, alternate images will be deleted. |
NoImageSizeCheck | 2048 | Meaningful only if ofScaleImages is set. If set, do not check whether the scaled image is smaller as the original image. |
IgnoreZeroLineWidth | 4096 | Meaningful 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). |
AdjZeroLineWidthOnly | 8192 | Meaningful only if the parameter MinLineWidth of the TOptimizeParams structure is greater zero. |
CompressWithJBIG2 | 16384 | If set, 1 bit images are compressed with JBIG2 if not already compressed with this filter. |
NoFilterCheck | 32768 | Meaningful only, if the flag ofCompressWithJBIG2 is set. If set, re-compress all 1 bit images, also if already compressed with JBIG2. |
ConvertGrayTo1Bit | 65536 | Useful for scanned faxes since many scanners create gray images for black & white input. Special color spaces like Separation, DeviceN, and NChannel are ignored unless the flag ConvertAllColors is set too. |
ConvertToGray | 131072 | If set, images, text, and vector graphics are converted to DeviceGray. |
ConvertToRGB | 262144 | If set, images, text, and vector graphics are converted to DeviceRGB. |
ConvertToCMYK | 524288 | If set, images, text, and vector graphics are converted to DeviceCMYK. |
ReplaceJP2KWithJPEG | 1048576 | Meaningful only, if the flag ofConvertToGray, ofConvertToRGB, or ofConvertToCMYK is set. If set, JPEG 2000 compressed images (which are converted to another color space) will be compressed with JPEG instead JPEG 2000. JPEG 2000 compression is very slow and requires much memory. JPEG compression is around 10 times faster and produces almost identical results. |
ConvTextToOutlines | 4194304 | If set, texts of non-Type3 fonts are converted to outlines or vector graphics. The resulting file contains no fonts with exception of Type3 fonts, if any. Such files are large but avoid printing issues due to missing or damaged fonts. |
ConvNonEmbFontsOnly | 8388608 | Meaningful only, if the flag ofConvTextToOutlines is set. If set, text of non-embedded fonts are converted to outlines only. Embedded fonts remain embedded. |
IgnoreDeviceN | 16777216 | If set, DeviceN color spaces are left unchanged. |
IgnoreNChannel | 33554432 | If set, NChannel color spaces are left unchanged. |
IgnoreSeparation | 67108864 | If set, Separation color spaces are left unchanged. |
FailOnOverprinting | 134217728 | Meaningful only if a color conversion flag is set. If set, the function returns with a fatal error if an object with enabled overprinting was found on the page. The appearance of overprinted objects would change and make the page maybe unusable. Overprinted objects can be left unchanged (set the flag SkipOverprintedObj in this case) or Optimize() can return with a fatal error to avoid the creation of an invalid document. |
SkipOverprintedObj | 268435456 | Meaningful only if a color conversion flag is set. If set, objects that would be rendered with enabled overprinting are left unchanged to avoid color errors on the page. |
Optimizing can fix bug in FileMaker 14 with empty portals resulting in broken PDF files.
Added optimization parameters for version 4 of DynaPDF.
After optimize, please close PDF. If you need to further edit it, please import it again in a new environment.
Requires a Pro license of DynaPDF.
For all image operation, it is recommended to initialize color management with DynaPDF.InitColorManagement function.
If you have an open page, we close it automatically for you before doing the import.
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 [ MBS("DynaPDF.IsInitialized") ≠ 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 )
Optimizes with files input/output:
# Initialize DynaPDF if needed
If [ MBS("DynaPDF.IsInitialized") ≠ 1 ]
Perform Script [ “InitDynaPDF” ]
End If
# Clear current PDF document
Set Variable [ $pdf ; Value: MBS("DynaPDF.New") ]
# Load PDF from container
Set Variable [ $r ; Value: MBS("DynaPDF.OpenPDFFromFile"; $pdf; "C:\Users\Christian\Desktop\171206Y_C24555_Annie_PDFs\171206Y_C24555_Annie_WOprice.pdf") ]
Set Variable [ $r ; Value: MBS("DynaPDF.OpenOutputFile"; $pdf; "C:\Users\Christian\Desktop\171206Y_C24555_Annie_PDFs\171206Y_C24555_Annie_WOprice.optimized.pdf") ]
Set Variable [ $r ; Value: MBS("DynaPDF.ImportPDFFile"; $pdf; 1) ]
# Optimize
Set Variable [ $r ; Value: MBS("DynaPDF.Optimize"; $pdf; "FlattenLayers¶DeleteInvPaths¶ScaleImages¶NewLinkNames¶DeletePrivateData¶IgnoreZeroLineWidth¶DeleteAlternateImages¶DeleteThumbnails"; 50; 50; 50; 150; 150; 150; "JPEG"; "JPEG"; "JPEG") ]
# Save
Set Field [ Optimize PDF::Output PDF ; MBS("DynaPDF.Save"; $pdf; "Merged.pdf") ]
Set Variable [ $r ; Value: MBS("DynaPDF.Release"; $pdf) ]
Convert all colors to CMYK:
Set Variable [ $r ; Value: MBS("DynaPDF.InitColorManagement"; $pdf; "DeviceCMYK";
3;
"/System/Library/ColorSync/Profiles/Generic Gray Profile.icc";
"/System/Library/ColorSync/Profiles/Generic RGB Profile.icc";
"/System/Library/ColorSync/Profiles/Generic CMYK Profile.icc";
"/System/Library/ColorSync/Profiles/Generic CMYK Profile.icc"
)]
Set Variable [ $r ; Value: MBS("DynaPDF.Optimize"; $pdf; "ConvertToCMYK") ]
See also
- DynaPDF.ImportPDFFile
- DynaPDF.MarkTemplateAsWatermark
- DynaPDF.OpenOutputFile
- DynaPDF.OpenPDFFromContainer
- DynaPDF.OpenPDFFromFile
- DynaPDF.Parser.Create
- DynaPDF.Parser.WriteToPage
- DynaPDF.Release
- DynaPDF.Save
- IsError
Release notes
- Version 11.2
- Fixed an issue with DynaPDF.Optimize complaining about no open output file.
- Version 9.3
- Added flags for DynaPDF.Optimize: ConvertToGray, ConvertToRGB, ConvertToCMYK and ReplaceJP2KWithJPEG.
- Version 9.0
- Changed DynaPDF.Optimize to use in memory flag by default unless you change it.
- Version 8.2
- Added checks to DynaPDF.Optimize, DynaPDF.Print and DynaPDF.Save to complain if no pages are in document.
Example Databases
Blog Entries
- Unlocking the Power of PDFs in FileMaker with DynaPDF and the MBS FileMaker Plugin
- Can FileMaker do that?
- MBS FileMaker Plugin, version 13.3pr3
- Things you can do with DynaPDF
- DynaPDF Optimize command
- MBS FileMaker Plugin 9.3 - More than 5900 Functions In One Plugin
- Combine MBS functions to automate processes in FileMaker
- Custom function to optimize PDF in FileMaker via DynaPDF
- MBS FileMaker Plugin 6.0 for OS X/Windows
- Optimize PDF Script
FileMaker Magazin
This function checks for a license.
Created 18th January 2016, last changed 25th September 2024