简体   繁体   English

iText 7 如何为整个文档设置字体

[英]iText 7 how to set font for the entire documents in

I am using iText 7 to create a PDF in a java Spring project.我正在使用 iText 7 在 java Z38008DD81C2F4AF7985ECF6DE 项目中创建 PDF 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!!谢谢!!

You can set font to Document like this:您可以像这样将字体设置为Document

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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