Jump to content

[TIP] Automated PDF Printing on OS X


Jeff Benjamin
 Share

This topic is 6225 days old. Please don't post here. Open a new topic instead.

Recommended Posts

I discovered a feature in OS X to greatly aid in the automated printing and post-processing of PDF's.

If you do not know about PDF Services, a built-in feature of OS X, learn about it here: http://www.apple.com/applescript/print/ .

Create a 'PDF Services' folder in your 'Library' folder. Any AppleScript application or alias files stored there can now be accessed thru the standard print dialog. The AppleScript can do anything you want with the resulting pdf file and does not need to know the name of the file or where is it located, because the file reference is passed to the script as a parameter. The beauty is that a reference to the AppleScript is saved in the FileMaker script print setup step. The AppleScript will then be executed every time the FileMaker script executes, just after the PDF is created.

This is a huge difference over most of the existing workarounds, I mean solutions, to automated pdf printing which have fixed file names and paths.

Following is an example script I created to show this capability. Note that the requirement is that you have FileMaker open with a db which contains a field named 'db_unique_id'.

If you want to learn more about this, attend Jimmy Jones' Devcon session on Applescript.

Enjoy!

Jeff Benjamin

Senior FileMaker Developer

FileMaker Inc.

http://www.filemaker.com

----------------------------------------------------------------------------

on open these_items

tell application "FileMaker Developer"

set theUniqueID to cell "db_unique_id" of current record

end tell

set this_file to item 1 of these_items

tell application "Finder"

set the file_name to the name of this_file

set the parent_folder to (the container of this_file) as alias

try

set thenewpath to make new folder at startup disk with properties {name:"PDF_OUTPUT_FOLDER"}

on error

set thenewpath to folder "PDF_OUTPUT_FOLDER" of startup disk

end try

set the name of this_file to "Reference_" & theUniqueID & ".pdf"

duplicate file this_file to thenewpath

end tell

end open

Platform: Mac OS X Panther

Link to comment
Share on other sites

  • 1 month later...
  • Newbies

Thanks...this was enormously helpful for a publishing project I'm working on! Follow-up question for you, though...when I make use of this AppleScript via the Print dialog box (manually) it works flawlessly. As soon as I use it via a ScriptMaker script (Print/No Dialog), I get a "-1753" error after the first record finishes processing (which takes about 20 seconds). Any ideas what might be causing this? I'm still at FM v. 6 and I'm going to try an upgrade to see if that somehow magically cures the problem but I thought you might have encountered something similar and could advise.

I was able to easily modify the script you posted to suit my needs...this is a stellar solution for producing mass PDFs!

Thanks!

Link to comment
Share on other sites

  • 1 month later...
  • 1 month later...
  • 2 weeks later...
  • Newbies

Thanks to this and several other Forums I was able to put together this Script. The Structure has been coppied from other Scripts. Please note that I am a very poor AppleScript programmer so if any logical errors have been entered I am sorry for that.

This Script creates both the PDF Services Folder and a complete Script so it can be run on a computer without a prior install. It copies its PDF files to a mounted server volume. If you want it to install locally just replace the code "disk theServerName" with "startup disk".

It needs to be installed as a Filemaker script with the following logic:

PerformAppleScript [....the following code...]

PageSetup[Restore,No dialog]

Print[No dialog]

You must Print at least once before setting the "No dialog" so that the print features are saved.

-- SET THE LOCAL VARIABLES MOST OF WHICH WILL LATER BE OVERWRITTEN

property theServerName : "Transfer"

property theLocalFolder : "PDF_OUTPUT_FOLDER"

property theAssignmentID : "AS_10009"

property theFileId : "test.pdf"

property theScriptName : "vdh_pdf_generate.scpt"

-- GET FILEMAKER FIELDS INTO LOCAL VARIABLES (NOTICE HOW 'TELL APPLICATION FILEMAKER PRO' IS NOT INCLUDED

-- THIS SOLVES THE 1753 ERROR THAT SO OFTEN OCCURS, DONT ASK ME WHY POSSIBLY BECAUSE WE ARE IN FILEMAKER

set theServerName to cell "server_name" of current record

set theLocalFolder to cell "local_folder" of current record

set theFileId to cell "file_id" of current record

set theAssignmentID to cell "assignment_id" of current record

-- SET UP SCRIPT FOR WRITING TO PDF SERVICES FOLDER

script ScriptFile

on open these_items

set this_file to item 1 of these_items

tell application "Finder"

set the file_name to the name of this_file

set the parent_folder to (the container of this_file) as alias

try

set thenewpath to make new folder at disk theServerName with properties {name:theLocalFolder}

on error

set thenewpath to folder theLocalFolder of disk theServerName

end try

try

set thenewpath to make new folder at thenewpath with properties {name:theAssignmentID}

on error

set thenewpath to folder theAssignmentID of thenewpath

end try

set the name of this_file to theFileId

duplicate file this_file to thenewpath with replacing

end tell

end open

end script

-- CREATE PDF Services FOLDER ON MACHINES THAT DONT HAVE IT ALREADY INSTALLED

tell application "Finder"

try

make new folder at (path to library folder) with properties {name:"PDF Services"}

end try

end tell

set TheFile to (path to library folder) & "PDF Services:"& theScriptName as string

-- WRITES SCRIPT TO PDF SERVICES FOLDER

store script ScriptFile in file TheFile replacing yes

Link to comment
Share on other sites

  • 3 months later...

For those looking for a much less-sophisticated, OSX only, solution, see post 141081 and its thread, which describe how to do automatically "Save as PDF..." using only FMP7. That post also describes how to set the desired name and location of the resulting PDF file using very simple AppleScripts.

Link to comment
Share on other sites

This topic is 6225 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.