Save multiple PDFs to Stream
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())
{
loadedDocument.Save(mem);
ret = mem.ToArray();
}
loadedDocument.Close(true);
}
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.
SIGN IN To post a reply.
3 Replies
KC
Karthikeyan Chandrasekar
Syncfusion Team
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.
Regards,
Karthikeyan
WI
will
November 16, 2022 06:44 AM UTC
Go to File > New Document. Choose the option to Combine Files into a Single PDF. Drag the files that you want to combine into a single PDF into the file-list box,
Will
AA
Anitha Azhagesan
Syncfusion Team
November 17, 2022 05:45 AM UTC
Thanks for your suggestion. This is also one of the possibilities to achieve
SIGN IN To post a reply.
- 3 Replies
- 4 Participants
-
TH Tu Huynh
- Nov 23, 2018 04:37 PM UTC
- Nov 17, 2022 05:45 AM UTC