java - PDFTron HTML 到 PDF 转换失败和错误代码 0
问题描述
下面是我们用来将 html 转换为 pdf 的代码。它在 Windows 环境下运行良好,但相同的代码在 linux 环境下无法运行。我还检查了 tempPath 目录是否具有读/写访问权限。“转换失败。HTTP 代码:0”converter.getLog() 为空
为下面的 pdftron 设置临时路径是行
PDFNet.setTempPath(tempPath);
utils.PdfViewerLicense.initialize();
将 Html 转换为 pdf 的代码
public static byte[] generatePDF(String pdfHtml) throws PDFNetException {
PDFDoc doc = null;
HTML2PDF converter = null;
byte [] bytes = null;
try {
converter = new HTML2PDF();
doc = new PDFDoc();
converter.setLandscape(false);
converter.insertFromHtmlString(pdfHtml);
if (converter.convert(doc)) {
bytes = doc.save( SDFDoc.e_linearized, null);
} else {
throw new PDFNetException("", 1L, "", "", "Conversion failed. HTTP Code: " + converter.getHTTPErrorCode() + "\n" + converter.getLog());
}
} catch (PDFNetException e) {
throw e;
}catch(Exception ex){
throw new PDFNetException("", 1L, "", "", ex.getMessage());
}finally {
if(converter!=null)
converter.destroy();
if(doc!=null)
doc.close();
}
return bytes;
}
解决方案
确保 HTML2PDF.so 文件至少对您正在运行的用户代理是可执行的(也许对每个人都是可执行的)。这应该在 html2pdf 下载附带的自述文件中进行描述。
推荐阅读
- selenium - 机器人框架定位器无法找到定位器
- r - 将大型数据框拆分为嵌套列表,并仅在 R 中保留有意义的非分组因素
- bash - 基于awk添加列结果
- javascript - 如何自动点击提交按钮 - 反应
- java - 从 JPA 到休眠的单表继承迁移问题
- shell - 如何使用软件包列表来确定是否需要在 Ubuntu 20.10 上进行 apt-get update?
- elixir - 将 JSON 数据更新到 postgresql db 的问题:** (Ecto.CastError) 预期参数是:map,得到:)
- c# - 除非调用 MessageBox.Show(),否则 WebBrowser 的打印方法在控制台应用程序中不起作用
- r - 无法按线型在 ggplot2 图例中分配自定义名称和样式
- matlab - 在matlab中更改矩阵的顺序