The AL developer preview is still evolving with frequent updates. Follow us on the Dynamics NAV Team Blog for the announcements.
SAVEASPDF Method (Report)
Saves a report as a .pdf file.
[Ok :=] REPORT.SAVEASPDF(Number, FileName[, Record]) [Ok :=] ReportVariable.SAVEASPDF(FileName)
The ID of the report that you want to run.
The path and name of the file that you want to save the report as.
Specifies which record to use in the report. Any filters that have been applied to the record that you specify will be used.
The report that you want to run.
Property Value/Return Value
true if the report was saved; otherwise, false.
If you omit this optional return value, then run-time errors can occur. If you include a return value, it is assumed that you will handle any errors.
You can use the SAVEASPDF method on the global REPORT object or on Report variables. If, at design time, you do not know the specific report that you want to run, then use the global REPORT object and specify the report number in the Number parameter. If you do know which report you want to run, then create a Report variable, set the Subtype of the variable to a specific report, and use this variable when you call the SAVEASPDF method.
When you call SAVEASPDF, the report is generated and saved to "FileName." A Saving to PDF window shows the status of the process. Note that the request page will not be shown.
The FileName parameter specifies a location on the computer that is running Dynamics 365 for Financials service. If you call this method from a client, such as from an action on a page, then use the DOWNLOAD Method (File) to download the .pdf file from the computer that is running Dynamics 365 for Financials service to the computer that is running the client.
By default, when a report uses an RDLC report layout at runtime, fonts are embedded in the generated PDF. You can specify whether fonts are embedded in the PDF for RDLC reports by changing the Report PDF Font Embedding setting in the Dynamics 365 for Financials service instance configuration or changing the PDFFontEmbedding property in report objects.
This example shows how to use the SAVEASPDF method to save a specific report as a PDF file on the computer that is running Dynamics 365 for Financials service. It requires that you create the following variables.
|Report206||Report||Sales - Invoice|
Filename := 'C:\MyReports\report206.pdf'; ReturnValue := Report206.SAVEASPDF(Filename);