当将大量html文件转换为pdf时,转换失败。对于相同的html文件,有时会起作用。主要是当有更多的文件时,会有一两个文件失败。
PdfTron版本:2016年9月,环境: Linux,Java 8
遵循本文,https://www.pdftron.com/pdfnet/samplecode/HTML2PDFTest.java.html
String inputHtml = "/myfolder/output.html";
String outputPdf = "/myfolder/output.pdf";
PDFNet.initialize();
PDFDoc doc = new PDFDoc();
HTML2PDF converter = new HTML2PDF();
converter.setLandscape(false);
converter.setPaperSize(9);
converter.insertFromHtmlString(new String(Files.readAllBytes(Paths.get(inputHtml))));
if (converter.convert(doc)) {
doc.initSecurityHandler();
doc.save(outputPdf, SDFDoc.e_linearized, null);
} else {
log.error("Conversion failed. HTTP Code: " + converter.getHTTPErrorCode() + "\n" + converter.getLog());
}输出
Conversion failed. HTTP Code: 0
Loading pages (1/6)
[> ] 0%
[======> ] 10%
[=================> ] 29%
[===================> ] 33%
[=====================> ] 36%
[============================================================] 100%
Counting pages (2/6)
[============================================================] Object 1 of 1
Resolving links (4/6)
[============================================================] Object 1 of 1
Loading headers and footers (5/6)
Printing pages (6/6)
[> ] Preparing
[==============================> ] Page 1 of 2
[============================================================] Page 2 of 2
Done
Post Process Error: Operation file seek failed
StdFile.cpp:478
DataWrite发布于 2017-01-20 16:54:09
使用中的临时文件夹很可能存在一些读/写权限问题。
请试试看以下几点。
PDFNet.setTempPath(folder_that_you_know_your_process_can_read_write);
PDFNet.initialize();发布于 2017-01-20 12:52:27
在java中,不能在表示路径的字符串中使用简单的反斜杠。字符串"\myfolder\output.pdf"等于"myfolderoutput.pdf"。使用双反斜杠()或正斜杠(/)
发布于 2022-05-16 11:47:05
对HTML2PDF模块中的库文件添加可执行权限对我有用(在macos上)
chmod a+x HTML2PDFMac/html2pdf_chromium.dylib
chmod a+x HTML2PDFMac/libswiftshader_libGLESv2.dylib
chmod a+x HTML2PDFMac/libswiftshader_libEGL.dylibhttps://stackoverflow.com/questions/41759768
复制相似问题