我试图使用pd4ml将Html转换为pdf。已在lib文件夹中加载pd4ml.jar。我得到错误
错误。ss_css2.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." );
}
您应该将依赖pd4ml 的所有jar添加到类路径中
更简单的解决方案-开始使用maven或gradle进行依赖关系管理,并添加pd4ml作为依赖关系。
或者在谷歌上搜索pd4ml所需的所有罐子,或者尝试逐个运行和添加罐子
Pd4Cmd执行需要pd4ml.jar和ss_css2.jar在类路径中。
(c)http://pd4ml.com/html-to-pdf-command-line-tool.htm