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

 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;

            }
        }
    }

No comments:

Post a Comment