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

  • Yupp90 Profile Picture
    109 on at
    RE: Save Sales-Invoice report as pdf in local directory

    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

  • Suggested answer
    Suresh Kulla Profile Picture
    47,773 on at
    RE: Save Sales-Invoice report as pdf in local directory

    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
    RE: Save Sales-Invoice report as pdf in local directory

    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
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at
    RE: Save Sales-Invoice report as pdf in local directory

    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-

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics NAV (Archived)

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans
Liquid error: parsing "/forums/thread/details/?threadid=44e8682a-ea1f-40a2-a076-02b80753a965'%22,..))" - Too many )'s.