這邊篇咱們寫一下如何用 wkhtmltopdf
導出 HTML
爲 PDF
。html
WORKDIR /tmp # 安裝軟件 RUN set -eux \ && apt-get update \ && apt-get install -y --no-install-recommends wget unzip fontconfig # 安裝 Noto Sans SC 字體 RUN wget https://fonts.google.com/download?family=Noto%20Sans%20SC -O Noto_Sans_SC.zip \ && unzip Noto_Sans_SC.zip -d /usr/share/fonts \ && fc-cache # 清理無用的依賴包 RUN set -eux \ && apt-get autoremove \ && apt-get autoclean \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
wkhtmltopdf
WORKDIR /tmp # 安裝軟件 RUN set -eux \ && apt-get update \ && apt-get install -y --no-install-recommends wget unzip \ libfontenc1 libjpeg62-turbo libx11-6 libx11-data libxau6 libxcb1 \ libxdmcp6 libxext6 libxfont1 libxrender1 x11-common xfonts-75dpi \ xfonts-base xfonts-encodings xfonts-utils # 安裝 wkhtmltopdf RUN wget https://downloads.wkhtmltopdf.org/0.12/0.12.5/wkhtmltox_0.12.5-1.stretch_amd64.deb -O wkhtmltox_0.12.5-1.stretch_amd64.deb \ && dpkg -i wkhtmltox_0.12.5-1.stretch_amd64.deb # 清理無用的依賴包 RUN set -eux \ && apt-get autoremove \ && apt-get autoclean \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
barryvdh/laravel-snappy
拓展# https://packagist.org/packages/barryvdh/laravel-snappy composer require barryvdh/laravel-snappy
而後根據 laravel-snappy
文檔配置,下邊是咱們安裝好的 wkhtmltopdf
位置:laravel
SNAPPY_PDF_BINARY=/usr/local/bin/wkhtmltopdf SNAPPY_IMAGE_BINARY=/usr/local/bin/wkhtmltoimage
如此就安裝完成了,具體配置及使用方法參考 laravel-snappy
文檔。git
Google Fontsgithub
wkhtmltopdfdocker
laravel-snappysegmentfault
示例代碼app