小编tek*_*unt的帖子

@ font-face with Flying Saucer

我正在跳跃,有人可以帮助我...似乎我想要做的事情应该相当简单,但我现在已经打了一天超过一天的想法.我已经在StackOverflow和Internet上发现了大量信息,但没有任何帮助我解决这个问题.

我正在尝试使用itext-2.0.8和core-renderer-R8来创建带有嵌入字体的PDF.我试图从有效的XHTML生成PDF并使用@ font-face样式标记嵌入字体.我已经确认@ font-face标签通过在浏览器中打开文件来包含字体.我总是小心翼翼地保持TTF领域相对于XHTML/CSS doc.

为了尝试和完成我的工作,我创建了一个小的"Hello World"类型程序来尝试嵌入字体.我采取了两种不同的方法,但都无法产生预期的结果.我在http://christopherluft.com/FlyingSaucer.zip上放了一个这个小Eclipse程序的副本

该程序在两个实例中都生成PDF,但是没有按预期嵌入PDF.使用带有setDocument的文件的第一个方法不会产生错误,也不会产生任何字体.第二种方法生成PDF但在调试输出中显示java.net.MalformedURLException.

我尝试了各种路径和URL的多种排列; 然而,没有一个不能产生预期的结果.我怀疑是我对ITextRenderer.setDocument没有理解; 但是,我很难找到特定于我的用例的任何适当的文档.

我尝试的第一种方法是:

public static void main(String[] args) throws IOException, DocumentException {

    System.getProperties().setProperty("xr.util-logging.loggingEnabled",
            "true");
    XRLog.setLoggingEnabled(true);

    String inputFile = "sample.xhtml";
    String url = new File(inputFile).toURI().toURL().toString();
    String outputFile = "firstdoc.pdf";

    OutputStream os = new FileOutputStream(outputFile);

    ITextRenderer renderer = new ITextRenderer();
    renderer.setDocument(url);
    renderer.layout();
    renderer.createPDF(os);

    os.close();
}
Run Code Online (Sandbox Code Playgroud)

我使用的第二种方法(更接近我们在应用程序中使用它的实际方式)是:

public static void main(String[] args)  throws IOException, DocumentException {

    System.getProperties().setProperty("xr.util-logging.loggingEnabled", "true");
    XRLog.setLoggingEnabled(true);

    String inputFile = "sample.xhtml";
    String url = new File(inputFile).toURI().toURL().toString();

    DocumentBuilder documentBuilder;
    org.w3c.dom.Document xhtmlContent; …
Run Code Online (Sandbox Code Playgroud)

css itext font-face flying-saucer

6
推荐指数
1
解决办法
5760
查看次数

标签 统计

css ×1

flying-saucer ×1

font-face ×1

itext ×1