Print PDF file to printer

Source : Palle Agermark on AX

ATTENTION : That’s work ONLY if you have Adobe Reader installed !

Just write this code (and adapt) :

static void pdfprint(Args _args)
{ 
    str                 adobeExe; 
    str                 adobeParm; 

    PrintJobSettings    printJobSettings = new PrintJobSettings(); 
    Dialog              dialog = new Dialog(); 
    DialogField         dialogFileName; 
    ;
    dialogFilename  = dialog.addField(typeid(FilenameOpen));

    if (dialog.run()) 
    {     
        printJobSettings.printerSettings('SysPrintForm');     
        adobeExe = WinAPI::findExecutable(dialogFileName.value());
       
        adobeParm = strFmt(' /t "%1" "%2" "%3" "%4"',
                           dialogFileName.value(),
                           printJobSettings.printerPrinterName(),
                           printJobSettings.printerDriverName(),
                           printJobSettings.printerPortName());

        WinAPI::shellExecute(adobeExe,  adobeParm); 
    }
}
Advertisements

Print a report to PDF into a folder

From this Source

My personal code for generate a PDF from a standard report (SalesInvoice, …)

private void generatePDF()
{
    ReportRun           report;
    RecordSortedList    list        = new RecordSortedList(tableNum(MyTable));
    FileName            fileName    = "C:/test.pdf";
    PrintJobSettings    settings;
    ;

    list.ins(myTable);

    report = new ReportRun(new Args(ReportStr(MyReport)));

    report.args().caller(null);
    report.args().object(List);

    settings    = report.printJobSettings();
    settings.format(PrintFormat::PDF_EMBED_FONTS);
    settings.setTarget(PrintMedium::File);
    settings.viewerType(ReportOutputUserType::PDFEmbedFonts);
    settings.fileName(fileName);
    settings.lockDestinationProperties(true);

    report.run();
}