ITextsharp to edit existing pdf

孤街醉人 提交于 2019-12-25 07:58:26

问题


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).


来源:https://stackoverflow.com/questions/39559507/itextsharp-to-edit-existing-pdf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!