我试图使用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添加到classpath中
更简单的解决方案-开始使用maven或gradle进行依赖性管理,并将pd4ml添加为依赖性。
或在Google上搜索pd4ml所需的所有罐子,或尝试逐一运行并添加罐子
Pd4Cmd执行需要在类路径中包含pd4ml.jar和ss_css2.jar。
(c)http://pd4ml.com/html-to-pdf-command-line-tool.htm
关于java - HTML-PD4ML Java,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37187411/