
有人可以建议怎么做吗?我已经看了一下itext文档,无法弄清楚从哪里开始.到目前为止,我仍然坚持如何将源pdf文件从pdfReader获取到document对象,我认为我可能以错误的方式接近它.
非常感谢
解决方法 最后,我使用pdfescape打开我现有的pdf文件,并将一些表单字段放在我需要放置字段的位置,然后再次保存以创建我的pdf文件.http://www.pdfescape.com
然后我找到了关于如何替换表单字段的博客文章:
http://www.johnnycode.com/blog/2010/03/05/using-a-template-to-programmatically-create-pdfs-with-c-and-itextsharp/
一切都很好!这是代码:
public static byte[] Generate(){ var templatePath = httpContext.Current.Server.MapPath("~/my_template.pdf"); // Based on: // http://www.johnnycode.com/blog/2010/03/05/using-a-template-to-programmatically-create-pdfs-with-c-and-itextsharp/ var reader = new pdfReader(templatePath); var outStream = new MemoryStream(); var stamper = new pdfstamper(reader,outStream); var form = stamper.AcroFIElds; var fIEldKeys = form.FIElds.Keys; foreach (string fIEldKey in fIEldKeys) { if (form.GetFIEld(fIEldKey) == "MyTemplatesOriginalTextFIEldA") form.SetFIEld(fIEldKey,"1234"); if (form.GetFIEld(fIEldKey) == "MyTemplatesOriginalTextFIEldB") form.SetFIEld(fIEldKey,"5678"); } // "Flatten" the form so it wont be editable/usable anymore stamper.FormFlattening = true; stamper.Close(); reader.Close(); return outStream.ToArray();} 总结 以上是内存溢出为你收集整理的使用itextsharp(或任何c#pdf库),如何打开PDF,替换一些文本,然后再次保存?全部内容,希望文章能够帮你解决使用itextsharp(或任何c#pdf库),如何打开PDF,替换一些文本,然后再次保存?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)