Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate pdf using itext and have bold in particular row

Tags:

java

itext

Hi I am able to generate pdf containing table with data using iText. How do I bold specific data in a particular row?

like image 453
Laxminarayan Alas Avatar asked Dec 29 '11 14:12

Laxminarayan Alas


1 Answers

First you instantiate a font object with the required details. Here you will specify whether it is Bold.

Font boldFont = new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD);
Font normalFont = new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.ITALIC);

Then use the font in whatever you want to use it.

In order to add a table cell with Bold font.

PdfPTable table=new PdfPTable(1);

PdfPCell pdfWordCell = new PdfPCell();
Phrase firstLine = new Phrase("text goes here", boldFont );
Phrase secondLine = new Phrase("normal text goes here", normalFont );

pdfWordCell.addElement(firstLine );
pdfWordCell.addElement(secondLine );

table.addCell(  pdfWordCell );

Example to create a paragraph with bold text.

Paragraph title = new Paragraph("Title of the document", boldFont );

You can use the same instance everywhere depending on whether the API allows it. Go through the documentation to figure out what allows Font manipulation.

See here for more examples.

http://www.vogella.de/articles/JavaPDF/article.html

like image 198
kensen john Avatar answered Oct 13 '22 00:10

kensen john