ITextsharp to edit existing pdf

2019-09-06 03:36发布

问题:

I downloaded the pdf from the below link

http://ap.meeseva.gov.in/DeptPortal/Application%20Forms%20New/Revenue-pdf/Income%20General%20Application%20Form.pdf

What I need is I would like to fill out the blanks with the given text, I tried with the following code

using (FileStream outFile = new FileStream(@"E:\\residence(VRO)1.pdf", FileMode.Create))
  {
     PdfReader pdfReader = new PdfReader(@"E:\\residence(VRO).pdf");
     PdfStamper pdfStamper = new PdfStamper(pdfReader, outFile);
     pdfStamper.FormFlattening = true;
     AcroFields af = pdfReader.AcroFields;
     string[] fields = pdfStamper.AcroFields.Fields.Select(x => x.Key).ToArray();
     for (int key = 0; key <= fields.Count() - 1; key++)
      {
      }
    }

But I am not getting the fields so can some one help me

回答1:

The so-called form you refer to, isn't a form. That is: it's not an interactive form. I took that PDF and I added interactive fields. Please download adapted.pdf and examine it to discover the differences.

Now when you run your code on it, you'll see the fields, and you will be able to fill out the form with Western text. You are currently using iTextSharp 5 or earlier. That version of iText doesn't support Hindi. Hindi wasn't introduced up until iText 7. Hence if you want to fill out the form using an Indic writing system (Devanagari, Tamil,...), you need iText 7 for C# and the pdfCalligraph add-on. Note that the pdfCalligraph add-on is kept closed source. You need a commercial license to use it.

We kept that part closed source because:

  • Too many companies are using iText without respecting the AGPL license and without purchasing a license,
  • As far as I know, no other free software supports Indic writing systems. We'd be giving away too much value if we released pdfCalligraph as open source software.

Summarized:

  1. your form is not a form. Make it a form.
  2. use software that can fill out such a form using an Indic writing system (e.g. iText 7 + the pdfCalligraph add-on).