4

I want to create a multiple-paged PDF document based on a PDF template using iTextSharp. 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 + @"\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();
 }
mmmmmm
  • 32,227
  • 27
  • 88
  • 117
Max
  • 417
  • 7
  • 21
  • Based on which criteria you want to multiply "it in a resulted document"? Also, Explain that you want results to be multiple document files or a single pdf file with multiple pages based on same template? – Ebad Masood Jun 20 '12 at 06:15
  • Hi ebad86. Need create single pdf file with multiple pages based on same template – Max Jun 20 '12 at 07:09
  • You can use PDFConcatenate to combine document based on template. Look at similar problem [here](http://stackoverflow.com/questions/20485886/converting-multiple-images-into-multiple-pages-pdf-using-itextsharp/) – febriyana.sudrajat Dec 11 '13 at 00:37

1 Answers1

-1

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

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

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

Community
  • 1
  • 1
Denis
  • 11,796
  • 16
  • 88
  • 150