How to create a PDF document using the iText library?

Let us now understand how to create a PDF document using the iText library. You can create an empty PDF Document by instantiating the Document class. While instantiating this class, you need to pass a PdfDocument object as a parameter to its constructor. Following are the steps to create an empty PDF document.

How do I use the iTextSharp component in my code?

Select the file by browsing to the save directory and selecting the file iTextSharp.dll. To make the use of the component simple in code, add the following using statements in your code.

How do I create a PDF file in Java?

To create a PDF document, create an instance of the class Document and pass the page size and the page margins to the constructor. Then use that object and the file stream to create the PdfWriter instance enabling us to output text and other elements to the PDF file.

How do I instantiate a PDF Writer in Java?

Instantiate the PdfWriter class by passing a string value (representing the path where you need to create a PDF) to its constructor, as shown below. When an object of this type is passed to a PdfDocument (class), every element added to this document will be written to the file specified.

What is the pdfwriter class?

The PdfWriter class represents the Doc Writer for a PDF. This class belongs to the package com.itextpdf.kernel.pdf. The constructor of this class accepts a string, representing the path of the file where the PDF is to be created.

What is the use of allow_screenreaders in iText?

As of iText 2.0.7, use ALLOW_SCREENREADERS instead. Scheduled for removal at or after 2.2.0 The color number counter for the colors in the document. The compression level of the content streams. Contains the business logic for cryptography. The current page number. The direct content in this document.

You Might Also Like