Posted by: Elio Boezio
Not sure if this is the complete answer (and a year later, you've probably found another solution), but I've managed to automate printing documents to PDF using PDFCreator, by manipulating the registry and the default printer as follows:
! Set up path to archives folder
Set sReportArchive = sDocArchivesPath || cDocArchivesInvoices
! Set up filename
Set sFileName = cINV || SalStrRightX( "000000" || SalNumberToStrX( twInvoicePrint.colInvoiceNum, 0 ), 6 ) || ".PDF"
! Save the details of the default printer
Call SalPrtGetDefault( sPrtDeviceDefault, sPrtDriverDefault, sPrtPortDefault )
! Using Registry Utilities by Joe Meyer (download "Registry.zip", available from http://sqlweb.vnuk.org/index.htm - thanks for the tip, Tom Heaverlo!)
! Instantiated in MDI Window variables section as cBTRegistry: oRegistry
If oRegistry.OpenKey( '/Software/PDFCreator/Program/', FALSE )
! Set the registry entries for PDFCreator
Call oRegistry.WriteString( 'UseAutosave', '1' )
Call oRegistry.WriteString( 'AutosaveDirectory', sReportArchive )
Call oRegistry.WriteString( 'AutosaveFilename', sFileName )
Call oRegistry.CloseKey( )
! Set the default printer to PDFCreator
Call SalPrtSetDefault( 'PDFCreator', 'winspool', 'PDFCreator' )
! Print the report to PDF
Set hWndReport = SalReportPrint( hWndForm, sReportTemplate, sVars, sBinds, 1, RPT_PrintAll, 0, 0, nFlags )
! Reset the default printer back to original settings
Call SalPrtSetDefault( sPrtDeviceDefault, sPrtDriverDefault, sPrtPortDefault )
One probably wouldn't want to do this if you need to print thousands of invoices to individual PDF files (I only need to print a handful at a time, but I need a secure copy); however one could print a whole batch run to a single PDF, I guess).
Hope someone else finds this useful!