I recently posted a question regarding creating a PDF report that combined both Filemaker reports and PDF documents in batch mode. I needed to sequence two FM reports, followed by one or more PDF documents, then repeating the process as necessary until all reports and PDF's were combined into a final PDF package (in this case on my desktop). I credit Samuel Giles for the AppleScript code and explanation, and Myles Reilly of Core Technology for adapting the AppleScript part to my specific needs. Hope if anyone else ever needs to do this, this post will help get them started. Also, am assuming this is for someone who doesn't have a lot of experience in FM, so I add a lot of explanation. ONLY WORKS FOR MAC.
First, I created an interactive container field on FM into which I loaded my PDF's -- some were multiple pages, and some single page.
In a Filemaker script, I created reports and exported to the desktop, as follows:
Tell Filemaker where (path and name) the outputted document package will be stored:
Set Variable ($desktoppath ; Value: Get (Desktoppath) & "PDFPackage.pdf") ** The document name (in this example "PDFPackage.pdf") must match exactly the names of these Applescript files: outputFile, fileOne, inputOne
Create a report in Filemaker (Rpt 1), then:
Print Setup [Restore ; With dialog: off ] **this step sets the report orientation (landscape or portrait) as I have mixed report types **
Save Records as PDF [Restore ; With dialog: Off ; ""$desktoppath" ; Records being browsed ] **create first PDF and place on desktop. Note that the option to append is not used 1st time through. Any subsequent times you loop through this report, the report must be appended.
Create another report in Filemaker (Rpt2), then:
Print Setup [Restore ; With dialog: off ]
Save Records as PDF [Restore ; Append ; With dialog: Off ; ""$desktoppath" ; Records being browsed ] **append Rpt2 to the PDF on desktop
Get contents of the PDF in the container field and export to the desktop so that all pages of the PDF are available. Note that the name you give the output document must match exactly the name in the AppleScript variables FileTwo and inputTwo:
Set Variable [$exportpath ; Value: Get (Desktoppath) & "PDFDocument" ]
Export Field Contents [PDFDocumentContainer; "$exportpath" ] ** PDFDocumentContainer is the name of the container field in FM
Now, combine the PDF'd FM reports on your desktop with the PDF document sent to the desktop using an FM AppleScript script step and the AppleScript Automator (on a Mac under System > Library > Automater > Combine PDF Pages.action)
Perform AppleScript [ ] ** enter the AppleScript below (as a native AppleScript).
Loop through this routine as many times as necessary to combine reports and PDF's.
The AppleScript will create a temporary file on your desktop that is deleted when the script completes. The final combined document will be (in this example) PDFDocument.
The AppleScript to enter:
set outputFile to "~/Desktop/PDFPackage.pdf"
set fileOne to "~/Desktop/PDFPackage.pdf"
set fileTwo to "~/Desktop/PDFDocument.pdf"
tell application "Finder"
do shell script "mkdir ~/Desktop/FileMakerTemp"
set TempFolderPath to "~/Desktop/FileMakerTemp/"
do shell script "mv ~/Desktop/PDFPackage.pdf ~/Desktop/FileMakerTemp/PDFPackage.pdf"
do shell script "mv ~/Desktop/PDFDocument.pdf ~/Desktop/FileMakerTemp/PDFDocument.pdf"
set inputOne to TempFolderPath & "PDFPackage.pdf"
set inputTwo to TempFolderPath & "PDFDocument.pdf"
do shell script "/System/Library/Automator/Combine\\ PDF\\ Pages.action/Contents/Resources/join.py " & "-o " & "~/Desktop/PDfPackage.pdf" & " " & "~/Desktop/FileMakerTemp/PDFPackage.pdf" & " " & "~/Desktop/FileMakerTemp/PDFDocument.pdf"
do shell script "rm -rf ~/Desktop/FileMakerTemp"