生成PDF

freemarker

使用freemarker从模板+数据,生成html文件。

Configuration cfg = new Configuration(Configuration.VERSION_2_3_28);
        try {
            cfg.setClassForTemplateLoading(this.getClass(), "/static/");
            Template template=cfg.getTemplate("content.html");
            PrintWriter pw = new PrintWriter(new File(destPath));
            template.process(params, pw);
            pw.close();//关闭流
        } catch (IOException e) {
            e.printStackTrace();
        } catch (TemplateException e) {
            e.printStackTrace();
        }

生成Docker镜像的Dockerfile

FROM kenkoooo/ubuntu-openjdk8

RUN apt-get update \
    && apt-get install -y \
        curl \
        xfonts-base \
        xfonts-75dpi \
    && apt-get clean

#安装wkhtmltox(0.12.5版本没有生成目录,改用wkhtmltox_0.12.6版本)
#可以在https://builds.wkhtmltopdf.org/0.12.6-dev/中寻找对应系统的版本
RUN curl "https://builds.wkhtmltopdf.org/0.12.6-dev/wkhtmltox_0.12.6-0.20180618.3.dev.e6d6f54.xenial_amd64.deb" -L -o "wkhtmltopdf.deb"
RUN dpkg -i ./wkhtmltopdf.deb
RUN apt-get install -f
RUN rm -rf wkhtmlto*
ENV LANG C.UTF-8

#安装chrome-headless
RUN apt-get install --assume-yes libxss1 libappindicator1 libindicator7
RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
RUN apt install --assume-yes ./google-chrome*.deb
RUN rm -rf google-chrome*

#安装chrome-driver
#可以在线下载chromedriver_linux64.zip
#RUN wget https://chromedriver.storage.googleapis.com/73.0.3683.68/chromedriver_linux64.zip
#也可以拷贝下载好的chromedriver_linux64.zip
COPY chromedriver_linux64.zip .
RUN unzip chromedriver_linux64.zip
RUN cp chromedriver /usr/local/bin/chromedriver
RUN chmod 755 /usr/local/bin/chromedriver
RUN rm -rf chromedriver_linux64*

发表评论