Do you own a Debenu Quick PDF Library version 7, 8, 9, 10, 11, 12, 13 or iSEDQuickPDF license? Upgrade to Debenu Quick PDF Library 14 today!
MergeDocument cause some fields not to work |
Post Reply |
Author | |
fletchsod
Team Player Joined: 11 Sep 20 Status: Offline Points: 40 |
Post Options
Thanks(0)
Posted: 09 Feb 21 at 6:04PM |
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; |
|
Ingo
Moderator Group Joined: 29 Oct 05 Status: Offline Points: 3524 |
Post Options
Thanks(0)
|
Hi Fletch,
if "some fields don't work" after merge i think you wanna merge files with identical formfieldnames? This won't work in a proper way with QuickPDF. So - for example - don't try to merge many invoices with the same structure to a catalogue. |
|
Cheers,
Ingo |
|
fletchsod
Team Player Joined: 11 Sep 20 Status: Offline Points: 40 |
Post Options
Thanks(0)
|
Ok, I get it now. I compared your answer to other posts issue someone else had & I now understand what you're trying to say.
Do you know of an API method that would properly rename the field title name? That include the field name duplication. We cannot change the field name on 500+ PDF, by the way. Thanks
Edited by fletchsod - 09 Feb 21 at 10:44PM |
|
Ingo
Moderator Group Joined: 29 Oct 05 Status: Offline Points: 3524 |
Post Options
Thanks(0)
|
In this function group you'll find all you need for renaming:
https://www.debenu.com/docs/pdf_library_reference/FormFields.php First you have to get all form field names in a loop. Second you can rename all names with new ones. FormFieldCount to get the number of fields in a pdf. GetFormFieldTitle in a loop gets all field names. FindFormFieldByTitle to get the special form field. SetFormFieldTitle to set a new name for the form field. Cheers and good luck, Ingo |
|
Cheers,
Ingo |
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |
Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. About — Contact — Blog — Support — Online Store