FM 11 on Mac OS X: Scripting FM-command "Save as PDF" - workaround

Discussion created by olafseifert on Jul 23, 2012
Latest reply on Jul 23, 2012 by steve_ssh

Hi everybody,


I got in trouble when trying to save a record as PDF out of a script: The currency-sign for "Euro" € (generated by FileMaker itself while "currency" was checked as an attribute for the corresponding field in the relevant layout) was lost: Only a blank square appeared on its place. Generating a PDF using the "Save as PDF"-Option of the Mac OS X-printing dialog works fine. The used font is a TrueType-font – a got lost, because I only found workarounds for problems using OpenType- or PostScript-fonts. The workarounds for those problems were: Use TrueType-fonts, instead :-/


Finally, I found a way to use the OS-side PDF-generating routine for my script using AppleScript and its shell-command "do shell script". Perhaps, this might be helpful for someone else:


First, I store the path for the target location in a global field called "var_filepathPDF" of a table called "init". The path starts and ends with a slash and spaces must not been escaped. The target might be a shared folder, for instance:


var_filepathPDF = "/Volumes/<name of share>/<folder level 1>/<folder level 2>/<target folder>/"


The first step in the script is to generate an individual filename for the final PDF:


Set Variable [ $filenamePDF; Value:<calculate an individual filename using field contents, time & date etc.> & ".pdf" ]


Now using the "Print" command with "No dialog" for let Mac OS X SAVE – and NOT print – the print-job to a PDF-file with a temporary filename "FM_PDF_tmp.pdf" in a suitable temporary location (I use "/Users/Shared/") - write a comment into your script, for there won't be any hint, what's really going on here - this script step looks like a normal printing command - though it's a saving command, in fact:


Print [ Current record; All Pages; Orientation: Portrait; Paper size: 8,26" x 11,69" ] [ Restore: <name of printing queue>; No dialog ]


Now FileMaker invokes AppleScript which then invokes a shell command with parameters calculated by FileMaker and converted by AppleScript. This step moves (not copies) the temporary file to the target location AND gives it its final naming. Important: Don't miss a double quote or backslash:


Perform AppleScript [ Calculated AppleScript: "do shell script "mv /Users/Shared/FM_PDF_tmp.pdf " & quoted form of "" & init::var_filepathPDF & $filenamePDF & """ ]

That's it.


Regards from Hamburg