1

I need to add another page in a pdf file created using below code. the next page should also use the same template placed at path:

HostingEnvironment.MapPath("~/Content/InvoiceTemplate/invoiceTemplate.pdf")

I am using itextsharp library to create documents. Below is the code used to generate pdf.

public static void WriteInTemplate(List<Models.Statement> statementList)
{

    string invoiceNumber = statementList.FirstOrDefault().Invoice.ToString().Trim();
    string month = null;
    string day = null;
    string year = null;


    PdfReader pdfReader = new PdfReader(HostingEnvironment.MapPath("~/Content/InvoiceTemplate/invoiceTemplate.pdf"));
    FileStream fileStream = new FileStream(HostingEnvironment.MapPath("~/Content/reports/" + invoiceNumber + ".pdf"), FileMode.Create);
    PdfStamper pdfStamper = new PdfStamper(pdfReader, fileStream);


    AcroFields pdfFields = pdfStamper.AcroFields;


    pdfFields.SetField("BillToCompany", statementList.FirstOrDefault().BillToCompany.ToString().Trim().ToUpper());
    pdfFields.SetField("BillToContact", statementList.FirstOrDefault().BillToContact.ToString().Trim().ToUpper());
    pdfFields.SetField("CustomerId", statementList.FirstOrDefault().Customer_ID);
    pdfFields.SetField("InvoiceNumber", statementList.FirstOrDefault().Invoice.ToString().Trim());
    pdfFields.SetField("JobNumber", statementList.FirstOrDefault().JobNumber.ToString().Trim());
    pdfFields.SetField("Caller", statementList.FirstOrDefault().Caller.ToString().Trim());


    pdfStamper.FormFlattening = true; // generate a flat PDF 
    pdfStamper.Close();
    pdfReader.Close();
}
Chris Haas
  • 53,986
  • 12
  • 141
  • 274
14578446
  • 1,044
  • 7
  • 30
  • 50

1 Answers1

-1

You need to create a PDFDocument and then merge the files that you create into it. There is a very good example of this in this link: Merge PDFs using ITextSharp.

competent_tech
  • 44,465
  • 11
  • 90
  • 113