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!

Debenu Quick PDF Library - PDF SDK Community Forum Homepage
Forum Home Forum Home > For Users of the Library > General Discussion
  New Posts New Posts RSS Feed - MergeDocument cause some fields not to work
  FAQ FAQ  Forum Search   Register Register  Login Login

MergeDocument cause some fields not to work

 Post Reply Post Reply
Author
Message
fletchsod View Drop Down
Team Player
Team Player


Joined: 11 Sep 20
Status: Offline
Points: 40
Post Options Post Options   Thanks (0) Thanks(0)   Quote fletchsod Quote  Post ReplyReply Direct Link To This Post Topic: MergeDocument cause some fields not to work
    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;
 
Back to Top
Ingo View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 29 Oct 05
Status: Offline
Points: 3524
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ingo Quote  Post ReplyReply Direct Link To This Post Posted: 09 Feb 21 at 7:12PM
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

Back to Top
fletchsod View Drop Down
Team Player
Team Player


Joined: 11 Sep 20
Status: Offline
Points: 40
Post Options Post Options   Thanks (0) Thanks(0)   Quote fletchsod Quote  Post ReplyReply Direct Link To This Post Posted: 09 Feb 21 at 7:19PM
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
Back to Top
Ingo View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 29 Oct 05
Status: Offline
Points: 3524
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ingo Quote  Post ReplyReply Direct Link To This Post Posted: 10 Feb 21 at 8:24PM
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

Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.01
Copyright ©2001-2014 Web Wiz Ltd.

Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. AboutContactBlogSupportOnline Store