1

我正在使用飞碟将 xhtml 转换为 pdf。我有一个在其中创建表的 xhtml。表格内容的字体系列被声明为 courier。使用飞碟为此 xhtml 生成 Pdf。生成的 pdf 不以 courier 字体显示表格内容。附件是生成的pdf的输入xhtml和截图。用于从 xhtml 转换为 pdf 的代码是:

    String inputFile = "samples/font.xhtml";
    String url = new File(inputFile).toURI().toURL().toString();
    String outputFile = "font.pdf";
    OutputStream os = new FileOutputStream(outputFile);
    ITextRenderer renderer = new ITextRenderer();
    renderer.setDocument(url);
    renderer.layout();
    renderer.createPDF(os);
    os.close();

应该怎么做才能以 courier 字体显示文本?

HTML 输入

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
       <title>My First Document</title>
        <style type="text/css"> b { color: green; } </style>
    </head>
    <body>
        <table>
       <tr>
         <td style="font-family: courier;">Hello World</td>
       </tr>
        </table>
     </body>
 </html>

在此处输入图像描述

4

1 回答 1

1

字体名称区分大小写。它适用于font-family: Courier. 您也可以使用font-family: monospace.

于 2013-06-06T07:48:07.247 回答