We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Save multiple PDFs to Stream

Thread ID:





141104 Nov 23,2018 04:37 PM UTC Nov 26,2018 11:51 AM UTC WinForms 1
Tags: PDF
Tu Huynh
Asked On November 23, 2018 04:37 PM UTC

I have problem when saving multiple PDFs ( more than 500 ) to Stream and get byte array to export PDF.

Here is the code I am using:

            byte[] ret = null;
            var isLoadedForm = false;
            using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(template))
                PdfLoadedForm loadedForm = loadedDocument.Form;
                if (loadedForm != null)
                    isLoadedForm = true;
                    foreach (var f in loadedForm.Fields)
                        if (!(f is PdfLoadedTextBoxField)) continue;
                        var ff = (PdfLoadedTextBoxField)f;
                        string v;
                        if (!data.TryGetValue(ff.Name, out v)) continue;
                        ff.Text = v;
                    loadedForm.Flatten = true;

                using (var mem = new MemoryStream())
                    ret = mem.ToArray();                    
            return ret;

I need to run this more than 500 times to get the byte array. But sometimes, loadedDocument.Save(mem) cannot be executed.
If I only run 30 times, this code works well.

Could you please help me to resolve this issue ? 
Thank you so much.

Karthikeyan Chandrasekar [Syncfusion]
Replied On November 26, 2018 11:51 AM UTC

Hi Tu Huynh, 
We have tried the provided code snippet with multiple PDFs (more than 250). It works find in our end and we were unable to reproduce the specified issue. We suspect that this could be the document specific issue. So kindly share us the PDF documents if any. If you have faced any exception in your sample, kindly share the stack trace details too. It will help us to provide the precise solution. 


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon