我想使用 iTextSharp 创建基于 PDF 模板的多页 PDF 文档。不幸的是,模板只有一页,但我想在生成的文档中增加它。
public static void GeberateFromTamplate(string pathTamplate)
{
//string pathTamplate = Server.MapPath("PDFs");
string pdfTemplate = pathTamplate + @"\newTemplate.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();
}