Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
354 views
in Technique[技术] by (71.8m points)

c# - 使用基于iTextSharp的模板创建PDF文档(Creating PDF Documents with iTextSharp based template)

I want to create a multiple-paged PDF document based on a PDF template using iTextSharp.

(我想使用iTextSharp基于PDF模板创建多页PDF文档。)

Unfortunately the template has only one page, but I want to multiplу it in the resulting document.

(不幸的是,模板只有一页,但是我想将其乘以结果文档。)

 public static void GeberateFromTamplate(string pathTamplate)
 {
     //string pathTamplate = Server.MapPath("PDFs");
     string pdfTemplate = pathTamplate + @"
ewTemplate.pdf";
     string newFile = pathTamplate + @"Filled-outForm.pdf";

     PdfReader pdfReader = new PdfReader(pdfTemplate);
     PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileStream(
         newFile, FileMode.Create));

     AcroFields pdfFormFields = pdfStamper.AcroFields;
     // set form pdfFormFields                                
     // 
     pdfFormFields.SetField("f1_01(0)", "1");
     pdfFormFields.SetField("f1_02(0)", "1");
     pdfFormFields.SetField("f1_03(0)", "1");
     pdfFormFields.SetField("f1_04(0)", "8");
     pdfFormFields.SetField("f1_05(0)", "0");
     pdfFormFields.SetField("f1_06(0)", "1");
     pdfFormFields.SetField("f1_07(0)", "16");
     pdfFormFields.SetField("f1_08(0)", "28");
     pdfFormFields.SetField("f1_09(0)", "Franklin A.");
     pdfFormFields.SetField("f1_10(0)", "Benefield");
     pdfFormFields.SetField("f1_11(0)", "532");
     pdfFormFields.SetField("f1_12(0)", "12");
     pdfFormFields.SetField("f1_13(0)", "1234");

     // The form's checkboxes
     pdfFormFields.SetField("c1_01(0)", "0");
     pdfFormFields.SetField("c1_02(0)", "Yes");
     pdfFormFields.SetField("c1_03(0)", "0");
     pdfFormFields.SetField("c1_04(0)", "Yes");

     pdfStamper.FormFlattening = false;

     // close the pdf
     pdfStamper.Close();
 }
  ask by Max translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can try to build the page using the following post:

(您可以尝试使用以下信息构建页面:)

itextsharp: how do i add a new page and write to it?

(itextsharp:如何添加新页面并写入页面?)

And then over each page you build you can apply your script.

(然后在构建的每个页面上可以应用脚本。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...