标签:creat .sh resource inf message button template 表单 read
背景
基于 PDF Template 预填充表单项,生成一份新的 PDF 文件,并保留表单域允许继续修改。
代码段
using iTextSharp.text.pdf; /* Code Snippet */ using (var dia = new SaveFileDialog()) { dia.Filter = @"PDF files|*.pdf"; dia.FileName = string.Format("PDF_{0}", DateTime.Today.ToString("yyyy-MM-dd")); if (dia.ShowDialog() == DialogResult.OK) { using (FileStream fsWrite = new FileStream(dia.FileName, FileMode.OpenOrCreate, FileAccess.Write)) { using (var reader = new PdfReader(@"\Templates\PDFTemplate\Template01.pdf")) { using (var stamper = new PdfStamper(reader, fsWrite)) { stamper.Writer.CloseStream = false; // 保留表单域,允许继续编辑 stamper.FormFlattening = false; // 更新表单域字段 var form = stamper.AcroFields; form.SetField("form1[0].#subform[0].flt_txtUserName[0]", "username"); stamper.Close(); } } } MessageBox.Show("Report has been exported", Resources.Common_Successed, MessageBoxButtons.OK, MessageBoxIcon.Information); } }
[.Net] - 使用 iTextSharp 生成基于模板的 PDF,生成新文件并保留表单域
标签:creat .sh resource inf message button template 表单 read
原文地址:http://www.cnblogs.com/jinzesudawei/p/7464090.html