Java Code to Change the Font color, size and Style of text:
iText provides methods to set the Font, color,size etc .
Lets see the below example code for setting some of the properties of the PDF contents.
Make an object of class Paragraph for color and style features; pass the object of class Font as a parameter which determines the Font style, font size and Font color.
In the above example as you can see we are getting font style from getFamilyIndex, as this is an integer parameter, so we have to get this value from this function.
Output for the above Code:
Java Code to change size and Background color of PDF file:
Make an object of Rectangle with the appropriate size and set the background color of that page by using setBackgroundColor method.
You can create a page A4 size as below.
Document document=new Document(PageSize.A4,20,30,100,100);
20- left margin , 30-right margin , 100-Top margin , 100-Bottom margin
The Document describes a document’s page size, margins, and other important attributes. It works as a container for a document’s chapters, sections, images, paragraphs, and other content. Inside the constructor of Document we have encapsulated predefined page size.
Output of the above code:
Java Code for Setting Attributes for PDF:
While you generate a PDF, you may want to set its different attribute like: author name, title, file description, creation date, created by etc. iText jar can help you to set different attributes of a PDF file. Document object provide different methods to add various attributes to a PDF file.