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;
if (!data.TryGetValue(ff.Name, out v)) continue;
ff.Text = v;
loadedForm.Flatten = true;
using (var mem = new MemoryStream())
ret = mem.ToArray();
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.