Docker deploys Laravel applications - export PDF using wkhtmltopdf

Keywords: PHP Laravel Google Docker github

Let's write about how to use this passage. wkhtmltopdf Export HTML as PDF.

I. Installation of fonts

WORKDIR /tmp

# Installation software
RUN set -eux \
    && apt-get update \
    && apt-get install -y --no-install-recommends wget unzip fontconfig

# Install Noto Sans SC font
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 
    
# Clean up useless dependency packages
RUN set -eux \
    && apt-get autoremove \
    && apt-get autoclean \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

Installation of wkhtmltopdf

WORKDIR /tmp

# Installation software
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

# Install 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 
    
# Clean up useless dependency packages
RUN set -eux \
    && apt-get autoremove \
    && apt-get autoclean \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

Three, installation barryvdh/laravel-snappy Expand

# https://packagist.org/packages/barryvdh/laravel-snappy
composer require barryvdh/laravel-snappy

Then, according to the laravel-snappy document configuration, the following is where we installed wkhtmltopdf:

SNAPPY_PDF_BINARY=/usr/local/bin/wkhtmltopdf
SNAPPY_IMAGE_BINARY=/usr/local/bin/wkhtmltoimage

So the installation is completed, the specific configuration and use of reference laravel-snappy documentation.

Related resources

Related reading

Posted by DarkEden on Wed, 09 Oct 2019 07:08:20 -0700