【问题标题】:Docker throws exception - Html2Pdf libraryDocker 抛出异常 - Html2Pdf 库
【发布时间】:2020-02-27 13:44:30
【问题描述】:

我使用htmlToPdf 创建了一个应用程序,该应用程序运行良好。但是当我使用下面的管道将它部署到我的 docker 时。

FROM openjdk:8-slim

RUN apt-get update && apt-get install -y --no-install-recommends \
      libc6 \
      libx11-6 \
      libxext6 \
      libxrender1 \
      libstdc++6 \
      libssl1.0 \
      libfreetype6 \
      fontconfig \
   && apt-get clean \
   && rm -rf /var/lib/apt/lists/*

我添加这些库是因为它需要它们正确运行。但它仍然显示文档中显示的相同错误。

这是:

Caused by: java.lang.UnsatisfiedLinkError: Unable to load library '/tmp/io.woo.htmltopdf/wkhtmltox/0.12.5/libwkhtmltox.so': Native library (tmp/io.woo.htmltopdf/wkhtmltox/0.12.5/libwkhtmltox.so) not found in resource path 

我检查了 docker 容器的 /tmp 文件夹,它包含所需的文件作为例外

【问题讨论】:

    标签: java wkhtmltopdf html-to-pdf


    【解决方案1】:

    正如我所见,您正在为 html2pdf 库而苦苦挣扎。

    但是你忘记了这个库在内部使用wkhtmltopdf。所以你可以使用那个库。要在您的 java 代码中使用它,您可以使用任何包装器。

    这是该包装器的链接:https://github.com/jhonnymertz/java-wkhtmltopdf-wrapper

    例如:

    Pdf pdf = new Pdf();
    
    pdf.addPageFromString("<html><head><meta charset=\"utf-8\"></head><h1>Müller</h1></html>");
    pdf.addPageFromUrl("http://www.google.com");
    
    // Add a Table of Contents
    pdf.addToc();
    
    // The `wkhtmltopdf` shell command accepts different types of options such as global, page, headers and footers, and toc. Please see `wkhtmltopdf -H` for a full explanation.
    // All options are passed as array, for example:
    pdf.addParam(new Param("--no-footer-line"), new Param("--header-html", "file:///header.html"));
    pdf.addParam(new Param("--enable-javascript"));
    
    // Add styling for Table of Contents
    pdf.addTocParam(new Param("--xsl-style-sheet", "my_toc.xsl"));
    
    // Save the PDF
    pdf.saveAs("output.pdf");
    

    【讨论】:

    • 如果能提供现有库的解决方案就更好了。
    猜你喜欢
    • 2022-01-22
    • 2013-05-24
    • 1970-01-01
    • 2011-05-30
    • 1970-01-01
    • 2011-02-25
    • 2012-01-24
    相关资源
    最近更新 更多