如何使用itextsharp将表单域添加到现有的pdf?

前端之家收集整理的这篇文章主要介绍了如何使用itextsharp将表单域添加到现有的pdf?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何使用itextsharp将表单域添加到现有的pdf?

我有一个现有的pdf文档,我想添加表单域,而不创建副本并写出一个新的文档.

解决方法

经过进一步审查,该领域的裁决被推翻.原来,如果您形成平坦的压模,字段不显示生成的文档(因为它们缺乏“外观”设置). BTW,形状平整防止形式字段的进一步编辑.现在我们可以将外观添加到窗体中,但是更简单的方法是使用TextField类,而不用担心明确设置“外观”对象.
  1. public void ABetterWayToAddFormFieldToExistingPDF( )
  2. {
  3. PdfReader reader = new PdfReader(@"c:\existing.pdf");
  4.  
  5. FileStream out = new FileStream(@"C:\existingPlusFields.pdf",FileMode.Create,FileAccess.Write);
  6.  
  7. PdfStamper stamp = new PdfStamper(reader,out);
  8.  
  9. TextField field = new TextField(stamp.Writer,new iTextSharp.text.Rectangle(40,500,360,530),"some_text");
  10.  
  11. // add the field here,the second param is the page you want it on
  12. stamp.AddAnnotation(field.GetTextField(),1);
  13.  
  14. stamp.FormFlattening = true; // lock fields and prevent further edits.
  15.  
  16. stamp.Close();
  17. }

猜你在找的HTML相关文章