Tech Tip: Unable to print to PDF
PRODUCT: 4D | VERSION: 20 | PLATFORM: Mac & Win
Published On: July 9, 2025
New 4D developers usually begin with the pair of commands SET PRINT OPTION and a command from the print family, like Print Form or PRINT SELECTION to print PDF files.
var $pdfpath : Text $pdfpath:=System folder(Desktop)+"test.pdf" SET PRINT OPTION(Destination option;3;$pdfpath) ALL RECORDS([Table_1]) PRINT SELECTION([Table_1];*) |
While this code might seem correct at first glance, it might print to paper instead.
The command SET CURRENT PRINTER is essential to choose the correct PDF driver. Here is a corrected code extracted from the documentation:
var $pdfpath : Text $pdfpath:=System folder(Desktop)+"test.pdf" SET CURRENT PRINTER(Generic PDF driver) SET PRINT OPTION(Destination option;3;$pdfpath) ALL RECORDS([Table_1]) PRINT SELECTION([Table_1];*) SET CURRENT PRINTER("") |
Do not forget to pass an empty string to SET CURRENT PRINTER. This will set the current 4D printer to system's default.