Tech Tip: Programmatically output a print job to PDF file on Mac
PRODUCT: 4D | VERSION: 14.3 | PLATFORM: Mac
Published On: February 17, 2015
Mac OS support printing to pdf files by default. When opening the print dialog, the pdf option can be seen in the drop down with the options of saving to pdf, or previewing in pdf.
To output a print to a pdf programmatically in 4D, use the command SET PRINT OPTION(9,3,$path) where $path is the path to the location of the pdf document. The pdf document specified in $path can be either an existing or a non-existing pdf file. If the file exists, it will be overwritten. If it does not exist, the file will be created.
Below is a quick sample of programatically printing all records of a table into a pdf document:
ALL RECORDS([Table_1]) $path:="Macintosh HD:Users:<Username>:Desktop:test.pdf" SET PRINT OPTION(Destination option;3;$path) If (OK=1) OPEN PRINTING JOB PRINT SELECTION([Table_1]) PAGE BREAK CLOSE PRINTING JOB End if |
Commented by John Foster on February 18, 2015 at 1:05 PM
This works great EXCEPT it adds an extra page to the print. If I print manually and select Open PDF in Preview then it only prints the single page of this report. Also is there a way to tell it to not open the document in preview and just save to disk?