简体   繁体   中英

Generate pdf using itext and have bold in particular row

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM