Pass the PdfFont object as a parameter, as shown below. To set the color to the text invoke the setFontColor method of the Text class, as shown below. Create a Paragraph class object and add the above created text using its add method, as shown below. Add the paragraph to the document using the add method of the Document class, as shown below.
The following Java program demonstrates how to set color and font to text in a PDF using the iText library. It creates a PDF document with the name fonts. 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. To instantiate this class in writing mode , you need to pass an object of the class PdfWriter to its constructor. Instantiate the PdfDocument class by passing the above created PdfWriter object to its constructor, as shown below. By using setFontColor and setFont methods, we can set the color and font of the text respectively. The package which this class belongs to is com.
It accepts a string, that takes the path where the PDF should be created. As shown below, lets start with Instantiating the PdfWriter class by passing a string value to its constructor.
After creating this object and passing to a PdfDocument class will add every element added to this document to the file specified in the path. The package com. We have to pass an object of class PdfWriter to its constructor to instantiate this class in writing mode. Below is what a PdfDocument class Instantiation done by passing the above created PdfWriter object to its constructor. We have methods for each element like page, file attachment, font, event handler which are provided by its class once a PdfDocument object is created.
For creating a self-sufficient PDF the Document class of the package com. Object of the class PdfDocument is one of the constructors of this class. Follow the step below to instantiate the Document class by passing the object of the class PdfDocument created in earlier steps. Firstly, PdfFont object should be created.
It can be done through createFont method of the class PdfFontFactory of the package com. Using setFont method of the Text class to this method, the text font is set. Pass the PdfFont object as a parameter, as below. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog.
Stack Gives Back Safety in numbers: crowdsourcing data on nefarious IP addresses. Featured on Meta. New post summary designs on greatest hits now, everywhere else eventually. Related Hot Network Questions.
0コメント