Convert byte memory stream to PDF

Stimulsoft Reports.BLAZOR discussion
Post Reply
muhammadhunainnasir
Posts: 31
Joined: Wed Mar 12, 2025 9:44 pm

Convert byte memory stream to PDF

Post by muhammadhunainnasir »

Hi,

I convert generated PDF report to byte array like below :

Code: Select all

public byte[]? GenerateInvoiceReport(string? Invoice_ID)
{
        byte[]? pdfBytes = null;
        StiReport? taxInvoice = LoadReportFromDatabase("Tax Invoice");

        if (taxInvoice != null && Invoice_ID != null)
        {
            taxInvoice.RequestParameters = false;
            //Set invoice id
            taxInvoice.Dictionary.Variables["Invoice_ID"].Value = Invoice_ID;
            //Render report with new value
            taxInvoice.Render();
            
            // Export to PDF as byte[]
            using (var stream = new MemoryStream())
            {
                taxInvoice.ExportDocument(StiExportFormat.Pdf, stream);
                pdfBytes = stream.ToArray();
            }
            //StiReportResponse.PrintAsPdf(taxInvoice);   //Prints as PDF
            //StiReportResponse.ResponseAsPdf(taxInvoice); //Downloads file as PDF
        }
        return pdfBytes;
    }
    
Is there a possibility to convert byte[] back to pdf using stimulsoft ?

I tried uisng stiReport.LoadDocument but it throws error as it's not stimulsoft report and is pdf.
Lech Kulikowski
Posts: 7685
Joined: Tue Mar 20, 2018 5:34 am

Re: Convert byte memory stream to PDF

Post by Lech Kulikowski »

Hello,

Sorry, we did not exactly understand your question. Could you explain your issue in more detail?
You can export directly to PDF.

Thank you.
muhammadhunainnasir
Posts: 31
Joined: Wed Mar 12, 2025 9:44 pm

Re: Convert byte memory stream to PDF

Post by muhammadhunainnasir »

Is there a possibility to convert byte[] to pdf using stimulsoft library ?
Lech Kulikowski
Posts: 7685
Joined: Tue Mar 20, 2018 5:34 am

Re: Convert byte memory stream to PDF

Post by Lech Kulikowski »

Hello,

It’s not entirely clear what the issue is - your byte array is the PDF. Just save it to a file.
File.WriteAllBytes("invoice.pdf", pdfBytes);

Thank you.
muhammadhunainnasir
Posts: 31
Joined: Wed Mar 12, 2025 9:44 pm

Re: Convert byte memory stream to PDF

Post by muhammadhunainnasir »

No I actually want to perform a silent print. I will give you a background of what is happening and what I am trying to acheive:

1. I have a blazor server app that generates stimulsoft report and convert to pdf using the method I pasted in original question.
2. Then the byte array is sent to client machine using websocket and client is running background service that receives the byte array of pdf.
3. Then I want to silently print the received byte array without saving file on to machine.

I can use what you suggested but I don't want to save file in drive. Also, I want to use stiReport.Print option to print pdf file silently from background service.
Lech Kulikowski
Posts: 7685
Joined: Tue Mar 20, 2018 5:34 am

Re: Convert byte memory stream to PDF

Post by Lech Kulikowski »

Hello,

Please see the following article:
https://www.stimulsoft.com/en/documenta ... _print.htm

Thank you.
Post Reply