Here's one issue I'm looking at and wonder why it doesn't work in batch PDFs but seem to work fine if we use single PDF document.
DropBox url is at https://www.dropbox.com/sh/uhoi3821eg1kcdk/AAC_x8zbI-HXBIu15-5_izqIa?dl=0
If you see the code we used "CreatePdfTemplate()", it works okay for 1 PDF file. So, with batch PDFs, we called "CreatePdfTemplate()" multiple times, so we know there's no bug in "CreatePdfTemplates()" because the 1 PDF file works. So, it seem there's some issue with the way the Quick-PDF's "MergeDocuemnt".
So anyone know what the problem is?
Thanks.
Code we use is
private int CreatePdfTemplate(PDFLibrary pdfApp, FormWriter formWriter, bool isDocuSign) { var formDescription = formWriter.Forms.Description; var pdfFilename = formDescription.ToLower().EndsWith(".pdf") ? $"{formDescription}" : $"{formDescription}.pdf"; var azureKeyName = $"{formWriter.Company.AcctNo}/PDF/{pdfFilename}"; var pdfBytes = new byte[] { };
formWriter.PdfTemplateLocation = pdfFilename;
using (var pdfFileStream = _amazonManagerService.GetPdfTemplate(azureKeyName)) using (var ms = new MemoryStream()) { pdfFileStream.CopyTo(ms); pdfBytes = ms.ToArray(); }
pdfApp.LoadFromString(pdfBytes, null); pdfApp.SetNeedAppearances(-1);
for (int fieldIX = 0; fieldIX < pdfApp.FormFieldCount(); fieldIX++) { var loopCounter = fieldIX + 1; var fieldName = pdfApp.GetFormFieldTitle(loopCounter); // FoxIt QuickPDF start with 1, not 0.
if (string.IsNullOrEmpty(fieldName)) { continue; } else if (fieldName.EndsWith(".")) // This indicate we have AcroForm field-name duplications. (FoxIt Quick PDF append the "." to it for unknown reasons). { fieldName = fieldName.Substring(0, (fieldName.Length - 1)); }
bool isString = true; // Do we really need this? (It is unused here & can be moved inside this "SendDpValuesToPdf" method instead). var fieldResult = _formService.SendDpValuesToPdf(fieldName, formWriter, ref isString); if (fieldResult.Value != null) { var fieldValue = fieldResult.Value.ToSafeString().Trim();
if (string.IsNullOrEmpty(fieldValue)) { continue; }
pdfApp.SetFormFieldValueByTitle(fieldName, fieldValue) ; } }
return pdfApp.SelectedDocument(); }
var pdfBytes = new byte[] { }; var pdfApp = _pdfEditorService.PdfInitialize(); var mainDocumentId = -1;
foreach (var (formWriter, index) in formWriters.WithLoopIndex()) { var tmpDocumentId = CreatePdfTemplate(pdfApp, formWriter, isDocuSign); if (index == 0) { mainDocumentId = tmpDocumentId; } else { pdfApp.SelectDocument(mainDocumentId); pdfApp.MergeDocument(tmpDocumentId); } }
pdfBytes = pdfApp.SaveToString();
return pdfBytes;
|