Monday, March 17, 2008

Printing directly to PDF in AX

References: AxaptaPedia

To achieve this task, we need to set some values to the printing settings before running the report like this:
// Variables
PrintJobSettings    printJobSettings;
ReportRun           myReportRun;

...


// Getting the report settings
printJobSettings = myReportRun.printJobSettings();

// Setting our parameters
printJobSettings.setTarget(PrintMedium::File);
printJobSettings.preferredTarget(PrintMedium::File);

printJobSettings.format(PrintFormat::PDF);
printJobSettings.preferredFileFormat(PrintFormat::PDF);

printJobSettings.fileName("c:\\attachment.pdf");

// Saving values
myReportRun.unpackPrintJobSettings(printJobSettings.packPrintJobSettings());

// Running the report
myReportRun.run();
Before running the report, we can set query's values:
query = myReportRun.query();
qbds = query.dataSourceNo(1);

qbds.range(1).value(_custTable.CustAccount);
qbds.range(2).value("");
qbds.range(3).value(queryvalue(NoYes::Yes));

myReportRun.run();
NOTE: For using a PDF Printer like "PDFCreator", simply set the deviceName like this:
myReportRun.deviceName("PDFCreator");

2 comments:

Aluguel de Computadores said...

Hello. This post is likeable, and your blog is very interesting, congratulations :-). I will add in my blogroll =). If possible gives a last there on my blog, it is about the Aluguel de Computadores, I hope you enjoy. The address is http://aluguel-de-computadores.blogspot.com. A hug.

Daniel Grau said...

Hi Oscar,

some great articles on your page!

one questions to the printers: Axapta PDF-writer does often not delivery apropriate PDF files (e.g. Calibri font, using numbers will mess it up pretty bad). Thus an external PDF-writer is considered often. You mentioned PDFCreator in your blog - but changing the device to this PDF-writer will not skip the dialog popping up, asking for the filename where to print, does it?
I would like to implement batch-printing (Order confirmation, invoices) directly with a PDF-writer. So far the only solution was to buy a pdf writer (cute pdf writer) where you can specify a specific path and filename to print to every time (so it doesn't need the user input). Can you think of any way to implement this with a freeware?

kind regards
Daniel


View My Stats