nikita soloman
nikita soloman

Reputation: 13

itext pdf change default font size in Paragraph not working

while using itext5 in android to display pdf from XHTML am trying to change the font size but it's not reflecting. I would like to know the substitutes(or hack) for CSS as itext5 is not supporting CSS.

 preparedText = output.toString("UTF-8");

 list = XMLWorkerHelper.parseToElementList(preparedText, null);
//   URL path      =Thread.currentThread().getContextClassLoader().getResource("fontname");
//    FontFactory.register(path.toString(), "test_font");
  Font titleFont = FontFactory.getFont(FontFactory.HELVETICA_BOLD,7f);
  paragraph.setFont(titleFont);
  paragraph.addAll(list);
  publishProgress(88);
            // write to document
            document.open();
            document.newPage();
            Paragraph p= new Paragraph(paragraph);
            p.setFont(titleFont);
            document.add(p);
            document.close();

Upvotes: 1

Views: 3070

Answers (1)

mkl
mkl

Reputation: 96064

The font you set in a paragraph applies to all text added to the paragraph afterwards, it does not change the previously added text. To set the font of the text you add to a paragraph in the constructor, there is a constructor that also accepts a font parameter.

Thus, instead of

Paragraph p= new Paragraph(paragraph);
p.setFont(titleFont);

use

Paragraph p = new Paragraph(paragraphText, titleFont);

or

Paragraph p = new Paragraph();
p.setFont(titleFont);
p.add(paragraphText);

Upvotes: 4

Related Questions