Saturday, April 20, 2019

Report.SaveAsPDF in Business Central (Workaround) - Download Report PDF in Business Central

Hello Friends,

As we know, Report.SaveAsPDF or Report.SaveAsExcel not supported in Business Central Cloud (SaaS) version.

We have an alternate code for solution. We can save Report in Stream objects than after convert to file using Blob Export function.

Here is the sample code to download work order report in PDF file with Customize file Name.


pageextension 50212 SalesOrderEx extends "Sales Order"
{
    layout
    {
        // Add changes to page layout here
    }

    actions
    {
        // Add changes to page actions here
        addlast("&Print")
        {
            action("Download Report")
            {
                ApplicationArea = All;
                Image = ExportFile;
                trigger OnAction()
                var
                    TempBlob_lRec: Record TempBlob temporary;
                    Out: OutStream;
                    RecRef: RecordRef;
                    FileManagement_lCdu: Codeunit "File Management";
                    SalesHeader_lRec: Record "Sales Header";
                begin
                    TempBlob_lRec.Blob.CreateOutStream(Out, TEXTENCODING::UTF8);
                    SalesHeader_lRec.Reset;
                    SalesHeader_lRec.SetRange("Document Type", Rec."Document Type");
                    SalesHeader_lRec.SetRange("No.", Rec."No.");
                    SalesHeader_lRec.FindFirst();
                    RecRef.GetTable(SalesHeader_lRec);
                    REPORT.SAVEAS(752, '', REPORTFORMAT::Pdf, Out, RecRef);
                    FileManagement_lCdu.BLOBExport(TempBlob_lRec, STRSUBSTNO('SalesOrder_%1.Pdf', "No."), TRUE);
                end;

            }
        }
    }


Hope this help someone to get solution of download pdf file in business central

Thank you for Reading...

Keep Sharing...Keep Growing....