web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

Save Sales-Invoice report as pdf in local directory

(0) ShareShare
ReportReport
Posted on by 109

So right now we are sending the report per email or we are printing and sending it to the customer.

Additionally we need to save the report in a directory.

Therefore we open the report again, go on print and select pdf.

The filename is always "Report"+[ReportID].pdf.

What I like to do is to save the report as "Invoice"+[Sales_Invoice_Header_No.].pdf in background when I send the report per email or print the report.

I was looking for a solution and I have found the SaveAsPdf function, but I wasn't able to make it work.

Since I only need the function for the invoice report, is it possible to use this function in the C/AL Editor or do I need to create a Codeunit (while looking for more information to the SaveAsPdf function I came across Codeunit)?

It would be really nice if someone could show me an example of how to use the function.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at

    You can directly use Report.SAVEASPDF. This will save the file to server-side (or to a network folder) and then you can move it locally:

    REPORT.SAVEASPDF(Number, FileName[, Record])  

    he path and name of the file that you want to save the report as. This path can be a local drive or mapped network directory, such as C:\MyReports\report206.pdf. For a network directory, you can also use the Universal Naming Convention (UNC) path, like \\servername\sharename\folder\filename.

    More info:

    docs.microsoft.com/.../saveaspdf-function--report-

  • Yupp90 Profile Picture
    109 on at

    I'm using the second function, but it doesn't work. I get false as return value, when I start the report.

    OnPostReport()

    Filename := 'C:\MyReports\test.pdf';

    ReturnValue := Report206.SAVEASPDF(Filename);

    MESSAGE('%1', ReturnValue);

    Am I missing something?

  • Suggested answer
    Suresh Kulla Profile Picture
    50,245 Super User 2025 Season 2 on at

    The report save the PDF on the server, so do you have the MyReports folder and does the user have permission to create files in that folder.

  • Yupp90 Profile Picture
    109 on at

    Thank you.

    I was able to fix the function.

    I thought, I could save the file directly into my folder.

    Now my function looks like this.

    OnPostReport()

    ClientFileName := 'C:\MyReports\' + "Sales Invoice Header"."No." + '.pdf';

    ServerFileName := COPYSTR(FileMgt.ServerTempFileName("Sales Invoice Header"."No." + '.pdf'),1, 250);

    InvoiceReport.SAVEASPDF(ServerFileName);

    FileMgt.DownloadToFile(ServerFileName, ClientFileName);

    FileMgt.DeleteServerFile(ServerFileName);

    ClientFileName -> DataType: Text

    ServerFileName -> DataType: Text

    InvoiceReport -> DataType: Report ; Sales - Invoice

    FileMgt -> DataType: Codeunit ; File Management

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics NAV (Archived)

#1
HoangNam Profile Picture

HoangNam 7

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans