Pdf Merge Issue in ItextSharp (After Merging Pdfs don't retain their Values)

前端 未结 1 528
死守一世寂寞
死守一世寂寞 2021-01-22 05:41

We are trying to merge three PDFs using ITextSharp. The problem is after merging we are able to get Data from the first PDF only, while the other two PDFs don\'t retain their va

相关标签:
1条回答
  • 2021-01-22 06:31

    I figured it out myself after little searching...Following is the solution...

    I have created the function to rename the Fields in the PDF,so that after merging the fields will be renamed.

    private static int counter = 0;
    private void renameFields(PdfReader pdfReader)
            {
                try
                {
                    string prepend = String.Format("_{0}", counter++);
                    foreach (DictionaryEntry de in pdfReader.AcroFields.Fields)
                    {
                        pdfReader.AcroFields.RenameField(de.Key.ToString(), prepend + de.Key.ToString());
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
    

    This function is called in "MergeFiles" function as follow...

              // Create a reader for a certain document
                 PdfReader reader = new PdfReader(sourceFiles[f]);
                 renameFields(reader);
              // Retrieve the total number of pages
                 int n = reader.NumberOfPages;
    
    0 讨论(0)
提交回复
热议问题