相关链接:
示例代码:
static void Main(string[] args) { BaseFont font = BaseFont.CreateFont(@"E:Test DemoPracticePDFContentfontssimfang.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); //获取PDF模板文件 string templateFile = @"E:Test DemoPracticePDFNew_Blank_Document.pdf"; //输出生成的PDF文件 string tempPDF = @"E:Test DemoPracticePDFoutput.pdf"; //创建 PdfReader using (PdfReader reader = new PdfReader(templateFile)) { using (PdfStamper stamper = new PdfStamper(reader, new FileStream(tempPDF, FileMode.Create))) { stamper.Writer.CloseStream = false; //进行PDF字段操作 AcroFields form = stamper.AcroFields; //填充PDF里的字段内容 form.SetFieldProperty("Name", "textfont", font, null); form.SetField("Name", "水电费"); stamper.FormFlattening = true; } } Console.WriteLine("ok"); Console.ReadKey(); }
Demo链接