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

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested answer

Is there a way to download multiple files pdf dynamically with code AL

(0) ShareShare
ReportReport
Posted on by 47

I wanna save multiple pdf files in my local computer, So I used this method inside a codeunit and call it from a page:

DOWNLOADFROMSTREAM 

for i := 0 to 10 do begin
    // code to generate PDFs...
    TempBlob.CreateOutStream(pdfOutStream);
    FromBase64StringToStream(itemPDF, pdfOutStream);
    TempBlob.CreateInStream(pdfInStream);
    DownloadFromStream(pdfInStream, '', '', '', itemName);
end;

I run this code more than one time, But each time it download ONLY the first one PDF, but others don't want to be downloaded !?

I don't know why this happen?

is there another way/method to do that!?

I have the same question (0)
  • Suggested answer
    Nitin Verma Profile Picture
    21,696 Moderator on at
    RE: Is there a way to download multiple files pdf dynamically with code AL

    Hi,

    You can't download all PDF altogether, it will only download the first file only. To achive this you have to create them as Zip file and download that zip file.

    Please have a look below url.

    community.dynamics.com/.../bundle-reports-into-a-zip-file

  • Suggested answer
    Amit Baru Profile Picture
    3,037 on at
    RE: Is there a way to download multiple files pdf dynamically with code AL

    Hi,

    Use this link for more information.

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

    Regards

    Amit Sharma

    www.erpconsultors.com

  • Suggested answer
    YUN ZHU Profile Picture
    93,438 Super User 2025 Season 2 on at
    RE: Is there a way to download multiple files pdf dynamically with code AL

    Hi, hope the following helps.

    Dynamics 365 Business Central: FileManagement.BLOBExport only save last file? -> Adding multiple files into a zip file

    https://yzhums.com/20030/

    Thanks.

    ZHU

  • MadMax33 Profile Picture
    18 on at
    Is there a way to download multiple files pdf dynamically with code AL
    Hi  Yun Zhu,
    I follow your code it works perfectly.
    but is there any limitation max file size?
     
    if only 5-10 records ok.
    but I have 500 records (which each record need to generate 3 pdf files).
    some of the pdf file created are blank / cant open / starts from page 2.
     
    - File Empty
     
     
    File Cant Open
     
    any idea?
     
  • DJ-30080919-0 Profile Picture
    34 on at
    Is there a way to download multiple files pdf dynamically with code AL
    Hi YUN ZHU,
     
    I followed your code but it will download as zip file but the pdf files are blank. How can i fix it.  
    As the below screenshot all the pdf files are blank except the last pdf
     
     
     procedure BulkDownloadInvoice(var SalesInvoiceHeader: Record "Sales Invoice Header")
        var
            TempBlob: Codeunit "Temp Blob";
            OutS: OutStream;
            InS: InStream;
            RecRef: RecordRef;
            FldRef: FieldRef;
            RecordCounter: Integer;
            DataCompression: Codeunit "Data Compression";
            FileManagement: Codeunit "File Management";
            ZipFileName: Text;
            PdfFileName: Text;
        begin
            ZipFileName := 'Sales Invoices_' + Format(CurrentDateTime) + '.zip';
            DataCompression.CreateZipArchive();
            if SalesInvoiceHeader.FindFirst() then begin
                repeat
                    Commit();
                    TempBlob.CreateOutStream(OutS);
                    RecRef.GetTable(SalesInvoiceHeader);
                    FldRef := RecRef.Field(SalesInvoiceHeader.FieldNo("No."));
                    FldRef.SetRange(SalesInvoiceHeader."No.");
                    if RecRef.FindFirst() then begin
                        Report.SaveAs(Report::"Posted Sales Invoice", '', ReportFormat::Pdf, OutS, RecRef);
                        TempBlob.CreateInStream(InS);
                        PdfFileName := 'Invoice No:' + Format(SalesInvoiceHeader."No.") + ' - ' + Format(SalesInvoiceHeader."Sell-to Customer Name") + '.pdf';
                        DataCompression.AddEntry(InS, PdfFileName);
                    end;
                    Sleep(1000);
                until SalesInvoiceHeader.Next() = 0;
                TempBlob.CreateOutStream(OutS);
                DataCompression.SaveZipArchive(OutS);
                TempBlob.CreateInStream(InS);
                DownloadFromStream(InS, '', '', '', ZipFileName);
            end;
        end;

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
Sumit Singh Profile Picture

Sumit Singh 2,204

#2
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 1,933

#3
YUN ZHU Profile Picture

YUN ZHU 1,885 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans