將批量html文件轉換爲pdf時,獲取轉換失敗錯誤。對於同一個html文件,有時它可以工作主要是當有更多的文件時,有一兩個失敗。PDFTron - HTML2PDF - 操作文件查找失敗
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
你是否正在路徑'\ myfolder \ output.pdf'上重寫文件? –
@FahadSiddiqui,不,我不是/ myfolder/output.pdf只是例如。我每次都使用帶有唯一標識的新文件名, – Sheel