Reputation: 1030
While converting bulk html files to pdf, getting Conversion failed error. For same html file sometimes it work. Mainly whenever more files are there one or two get failed.
PdfTron Version : September 2016, Environment : Linux, Java 8
Followed this article, 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());
}
Output
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
Upvotes: 1
Views: 1110
Reputation: 61
Adding executable permission on lib files present in HTML2PDF module worked for me(on macos)
chmod a+x HTML2PDFMac/html2pdf_chromium.dylib
chmod a+x HTML2PDFMac/libswiftshader_libGLESv2.dylib
chmod a+x HTML2PDFMac/libswiftshader_libEGL.dylib
Upvotes: 0
Reputation: 2570
Most likely there is some read/write permission issue with the temp folder being used.
Please try the following.
PDFNet.setTempPath(folder_that_you_know_your_process_can_read_write);
PDFNet.initialize();
Upvotes: 1
Reputation: 4049
In java you can't use simple backslashes in strings representing a path. The string "\myfolder\output.pdf"
is equal to "myfolderoutput.pdf"
. Either use double backslashes (\) or forward slashes (/)
Upvotes: 0