Warm tip: This article is reproduced from serverfault.com, please click

iText 7 how to set font for the entire documents in

发布于 2020-11-30 21:59:34

I am using iText 7 to create a PDF in a java Spring project. I know how to set a font for an element like a paragraph or cell in a table, as shown in the snippet below. How can I set a font and size for the entire document?

    PdfDocument pdfDoc = new PdfDocument(new PdfWriter(response.getOutputStream()));

    PdfFont font = PdfFontFactory.createFont(FontConstants.TIMES_ROMAN);
    Document document = new Document(pdfDoc);
    Paragraph p = new Paragraph().add("Paragraph 1").setFont(font);

    ...

Thank you!!

Questioner
Habtamu Assefa
Viewed
0
Bottle 2020-12-03 18:10:01

You can set font to Document like this:

Document document = new Document(pdfDoc).setFont(font).setFontSize(10);