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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With