【问题标题】:Generate pdf using itext and have bold in particular row使用 itext 生成 pdf 并在特定行中加粗
【发布时间】:2011-12-29 14:22:30
【问题描述】:

您好,我可以使用 iText 生成包含数据的 pdf 表格。如何将特定行中的特定数据加粗?

【问题讨论】:

    标签: java itext


    【解决方案1】:

    首先,您使用所需的详细信息实例化一个字体对象。在这里您将指定它是否为粗体。

    Font boldFont = new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD);
    Font normalFont = new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.ITALIC);
    

    然后在任何你想使用的字体中使用它。

    为了添加一个粗体的表格单元格。

    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 );
    

    创建带有粗体文本的段落的示例。

    Paragraph title = new Paragraph("Title of the document", boldFont );
    

    您可以在任何地方使用同一个实例,具体取决于 API 是否允许。浏览文档以找出允许进行字体操作的内容。

    更多示例请参见此处。

    http://www.vogella.de/articles/JavaPDF/article.html

    【讨论】:

    • 嗨,我不想要单元格粗体中的完整文本。我希望前 2 行数据以粗体显示,然后保持正常。试着帮我解决这个问题
    • 使用 addElement,添加多个元素。我已经编辑了我的答案
    猜你喜欢
    • 1970-01-01
    • 2015-10-13
    • 1970-01-01
    • 2011-08-04
    • 2014-09-01
    • 1970-01-01
    • 2013-04-13
    • 1970-01-01
    • 2012-01-02
    相关资源
    最近更新 更多