HTML-PD4ML Java

时间:2016-05-12 12:49:02

标签: java dependency-management pd4ml

我尝试使用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." );
}

1 个答案:

答案 0 :(得分:0)

你应该在classpath上添加所有依赖于pd4ml

的jar

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

或使用google搜索pd4ml所需的所有jar,或者尝试逐个运行并添加jar

  

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

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