Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

itextsharp : Adding multiple pages

Tags:

c#

pdf

itextsharp

I'm using the DirectContent method of absolutely positioning elements on my PDF. I need to iterate over a list of records and build one page per record in my PDF.

How do I tell itextsharp to insert a new page and "draw" to that page?

        // 72point per inch
        // we want 7x10
        iTextSharp.text.Rectangle pageSize = new iTextSharp.text.Rectangle(504, 720);

        Document doc = new Document(pageSize);
        PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(@"C:\temp\backPages.pdf", FileMode.Create));

        doc.Open();
        PdfContentByte cb = writer.DirectContent;

        // "DRAW" IMAGES AND TEXT 
        ...
        //various .Add's called here
        ...
        // Done with drawing images & text
        doc.Close();
like image 972
BoxOfNotGoodery Avatar asked Dec 29 '22 14:12

BoxOfNotGoodery


1 Answers

Easily enough its the Document.NewPage() function.

I saw some really odd "solutions" on other sites, hope this helps someone else.

like image 146
BoxOfNotGoodery Avatar answered Jan 09 '23 10:01

BoxOfNotGoodery