The html2pdf gives utility methods that help us to convert HTML files or content into PDF. That's not a recipe for success in our book, or any for that matter. when I create the document, I have the option to specify the page size, but I want different page sizes for different pages in my PDF. It creates a PDF document with the name tilingPdfPages.pdf and saves it in the path C:/itextExamples/. Document pdfDoc = new Document (PageSize.A4, 25, 25, 25, 15); PdfWriter pdfWriter = PdfWriter.GetInstance (pdfDoc, Response.OutputStream); pdfDoc.Open (); Here I created the Document and set the page size as . How to rotate a page while creating a PDF document? The next arguments are left, right, top and bottom margins respectively. Add a header to the PDF document. iText 7 represents the next level of SDKs for developers that want to take advantage of the benefits PDF can bring. . Add bookmarks, page numbers, watermarks, and other features to . The class structure is tough to understand. Step 3: Open the document now using. . Working with Page Size of PDF Document: Creating a Page of specified size, we must have to create a iTextSharp.text.Rectangle object and Passing the size as argument to its constructor. How to get page size of pdf document iText 7 In short The problem is due to your code accessing pages which iText already has flushed out of memory to the target file. In the next line, we will create the Document Object. Instantiate the Document class by passing the object of the class PdfDocument, as shown below. When using iText to generate a PDF, if I need to switch fonts many times the file size becomes too . pageSize can provide the width and height of the page directly. I expected to find a .toByteArray() method in the Document or PdfWriter classes, but there is none. by replacing try (Document document = new Document(pdf)) { by try (Document document = new Document(pdf, pdf.getDefaultPageSize(), false)) { Some explanations iText in Action, Second Edition - Manning Publications iText is a PDF library, an API that was developed to allow developers to do the following (and much more): Generate documents and reports based on data from an XML file or a database. Finally, close the document. The next arguments are left, right, top and bottom margins respectively. as well as custom page size. Rectangle: 612x792 (rot: 0 degrees) I want to get output in inches. The Document class of the package com.itextpdf.layout is the root element while creating a self-sufficient PDF. You can query a PdfReader instance to get the number of pages in the document, the rectangle defining the media box, the rotation of the page, and so on. Automate your document workflows using a scalable and cost-effective RESTful API. Create Text with various font size and style . /** * Use this method to get an instance of the <CODE>PdfWriter</CODE>. It . Java - Read and Write PDF with iText - HowToDoInJava 0. In this iText tutorial, we are writing various code examples to read a PDF file and write a PDF file.