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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

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

Downloading Blank PDFs as a ZIP

(1) ShareShare
ReportReport
Posted on by 34
Hi,
 
I want download multiple pdf files as zip. As per the below code it will download the file but with black pdfs.
 
I don't know what is the issue with the code.
 
does anyone know how to fix it?
 
Thanks in advance.
 
 

 
 
 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;
I have the same question (0)
  • Suggested answer
    Khushbu Rajvi. Profile Picture
    22,153 Super User 2026 Season 1 on at
    I replicated the same process on my system, and I successfully downloaded the zip file containing all the invoices. The data is also visible in the PDF files.
     
     
    One thing I noticed is that you used the report "Posted Sales Invoice" code, while I used the standard report from BC.
     
    I don’t think "Posted Sales Invoice" is a standard report. If it is a custom report, you should check that the layout is correctly assigned to the report.
     
    I strongly believe that there is issue with report and layout only. 
     
    Hope it will help you out.
     
    Regards,
    Khushbu Rajvi
     
     
  • Angel M. Reynoso Gonzalez Profile Picture
    4 on at
    Hello
    Once I had to do the same thing, this was the link that helped me. I hope it can also help. 
     
  • Netjacker2097 Profile Picture
    286 on at
    Hi,
     
    try this:
     
    thanks,
    M
     
    procedure BulkDownloadInvoice(var SalesInvoiceHeader: Record "Sales Invoice Header")
    var
        TempBlob: Codeunit "Temp Blob";
        OutS: OutStream;
        InS: InStream;
        RecRef: RecordRef;
        FldRef: FieldRef;
        DataCompression: Codeunit "Data Compression";
        FileManagement: Codeunit "File Management";
        ZipFileName: Text;
        PdfFileName: Text;
    begin
        ZipFileName := 'Sales Invoices_' + Format(CurrentDateTime) + '.zip';
        DataCompression.CreateZipArchive();
       
        if SalesInvoiceHeader.FindSet() then begin
            repeat
                // Create a new OutStream for each PDF
                TempBlob.CreateOutStream(OutS);
                RecRef.GetTable(SalesInvoiceHeader);
               
                Report.SaveAs(Report::"Posted Sales Invoice", '', ReportFormat::Pdf, OutS, RecRef);
                OutS.Flush(); // Ensure the stream is flushed
               
                TempBlob.CreateInStream(InS);
                PdfFileName := 'Invoice No_' + SalesInvoiceHeader."No." + ' - ' + SalesInvoiceHeader."Sell-to Customer Name" + '.pdf';
               
                DataCompression.AddEntry(InS, PdfFileName);
            until SalesInvoiceHeader.Next() = 0;
           
            // Save the final zip file
            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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,949 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,064 Super User 2026 Season 1

#3
Khushbu Rajvi. Profile Picture

Khushbu Rajvi. 559 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans