【问题标题】:PDFTron - HTML2PDF - Operation file seek failedPDFTron - HTML2PDF - 操作文件查找失败
【发布时间】:2017-01-20 09:07:11
【问题描述】:

将批量 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

【问题讨论】:

  • 你要重写路径\myfolder\output.pdf的文件吗?
  • @FahadSiddiqui,不,我不是 /myfolder/output.pdf 的例子。我每次都使用具有唯一 ID 的新文件名,

标签: java pdftron


【解决方案1】:

使用的临时文件夹很可能存在一些读/写权限问题。

请尝试以下方法。

PDFNet.setTempPath(folder_that_you_know_your_process_can_read_write);
PDFNet.initialize();

【讨论】:

    【解决方案2】:

    在 java 中,您不能在表示路径的字符串中使用简单的反斜杠。字符串"\myfolder\output.pdf" 等于"myfolderoutput.pdf"。使用双反斜杠 (\) 或正斜杠 (/)

    【讨论】:

    • 对不起,完全忽略反斜杠,即错字。更新的问题。
    猜你喜欢
    • 1970-01-01
    • 2012-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多