Page 1 of 1

Convert byte memory stream to PDF

Posted: Wed Jan 28, 2026 9:19 am
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.

Re: Convert byte memory stream to PDF

Posted: Wed Jan 28, 2026 9:57 pm
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.

Re: Convert byte memory stream to PDF

Posted: Wed Jan 28, 2026 10:11 pm
by muhammadhunainnasir
Is there a possibility to convert byte[] to pdf using stimulsoft library ?

Re: Convert byte memory stream to PDF

Posted: Wed Jan 28, 2026 11:53 pm
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.

Re: Convert byte memory stream to PDF

Posted: Thu Jan 29, 2026 1:03 am
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.

Re: Convert byte memory stream to PDF

Posted: Thu Jan 29, 2026 8:06 am
by Lech Kulikowski
Hello,

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

Thank you.