1

我尝试使用 pd4ml 将 Html 转换为 pdf。在 lib 文件夹中加载 pd4ml.jar。我收到错误

错误。ss_css2.jar 不在类路径中。

我还需要下载其他 jar 吗?

我的代码是:

private void runConverter(String url, String outputPath)
        throws InvalidParameterException, MalformedURLException, IOException {  
    File output = new File(outputPath);  
    java.io.FileOutputStream fos = new java.io.FileOutputStream(output);  

    PD4ML pd4ml = new PD4ML();  

    pd4ml.setHtmlWidth(userSpaceWidth); // set frame width of "virtual web browser"   

    // choose target paper format and "rotate" it to landscape orientation  
    pd4ml.setPageSize(pd4ml.changePageOrientation(PD4Constants.A4));   

    // define PDF page margins  
    pd4ml.setPageInsetsMM(new Insets(topValue, leftValue, bottomValue, rightValue));   

    // source HTML document also may have margins, could be suppressed this way   
    // (PD4ML *Pro* feature):  
    pd4ml.addStyle("BODY {margin: 0}", true);  

    // If built-in basic PDF fonts are not sufficient or   
    // if you need to output non-Latin texts,  
    // TTF embedding feature should help (PD4ML *Pro*)  
    pd4ml.useTTF("c:/windows/fonts", true);  

    pd4ml.render(new URL(url), fos); // actual document conversion from URL to file  
    fos.close();  

    System.out.println( outputPath + "\ndone." );
}
4

1 回答 1

1

您应该将依赖于 pd4ml 的所有 jar 添加到类路径

更简单的解决方案 - 开始使用进行依赖管理,并添加 pd4ml 作为依赖项。

或者用谷歌搜索所有需要的 jars for pd4ml,或者尝试一一运行并添加 jars

Pd4Cmd 执行需要 pd4ml.jar 和 ss_css2.jar 在类路径中。

(c) http://pd4ml.com/html-to-pdf-command-line-tool.htm

于 2016-05-12T13:29:10.493 回答