Skip to main content

Notifications

Announcements

No record found.

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 41

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!?

  • 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;
  • 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?
     
  • Suggested answer
    YUN ZHU Profile Picture
    79,326 Super User 2025 Season 1 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

  • Suggested answer
    Amit Baru Profile Picture
    3,027 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
    Nitin Verma Profile Picture
    21,465 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

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,278 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,011 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans