我使用htmlToPdf创建了一个应用程序,该应用程序运行良好。但是,当我使用以下管道将其部署到我的码头工人时。
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文件夹,其中包含所需的文件作为例外
据我所知,您正在使用html2pdf库。
但是您忘记了此库在内部使用wkhtmltopdf。因此您可以使用该库。要在Java代码中使用它,可以在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");