For those who are awake!
Discount -15%
We use cookies
We use cookies to optimize our website. By continuing to browse the site, you agree to our use of cookies.
New design
Control panel
  • Русский
  • Українська
  • English
  • UAH
  • USD
  • RUB
  • EUR
  • 0-800-307-307 Hotline
  • +38 (044) 392-74-33 Kiev
  • +38 (057) 728-39-00 Kharkiv
  • +38 (056) 794-38-31 Dnipro
  • +38 (032) 229-58-93 Lviv
  • +38 (048) 738-57-70 Odessa
  • +38(093) 170-15-42  Life
  • +38 (067) 400-88-44 Kievstar
  • +1(888)393-24-51  USA, Toll free
  • +44(131)507-01-14  Great Britain
  • +7 (499) 348-28-61 Moscow

2.23.1.1. The wkhtmltopdf and wkhtmltoimage utilities

wkhtmltopdf - a set of two utilities command line for rendering HTML-files or web pages using the WebKit engine:

  • The wkhtmltopdf utility renders to PDF and comes in two flavors:
    • Version 0.10:
      /usr/local/bin/wkhtmltopdf-amd64
    • Version 0.12:
      /usr/local/bin/wkhtmltopdf
  • The wkhtmltoimage utility renders to an image file:
    /usr/local/bin/wkhtmltoimage

Utilities available on hosting default. The examples below use version 0.12 for the wkhtmltopdf utility. To use version 0.10, just replace the utility name with wkhtmltopdf on wkhtmltopdf-amd64.

View brief documentation:

  • wkhtmltopdf:
    wkhtmltopdf -h
  • wkhtmltoimage:
    wkhtmltoimage -h

View detailed documentation:

  • wkhtmltopdf:
    wkhtmltopdf -H
  • wkhtmltoimage:
    wkhtmltoimage -H

Launch format:

  • wkhtmltopdf:
    wkhtmltopdf <URL or path to the source HTML file> <path and name of the output PDF file>
  • wkhtmltoimage:
    wkhtmltoimage <URL or path to HTML source file> <path and name of output image file>

A simple example of converting a web page:

  • To PDF document:
    wkhtmltopdf http://google.com google.pdf

    Или:

    /usr/local/bin/wkhtmltopdf http://google.com google.pdf
  • To the image file:
    wkhtmltoimage http://google.com google.png

    Или:

    /usr/local/bin/wkhtmltoimage http://google.com google.png

Simple conversion example HTML-document:

  • To PDF document:
    wkhtmltopdf /home/example/way/to/file/document.html document.pdf

    Или:

    /usr/local/bin/wkhtmltopdf /home/example/way/to/file/document.html document.pdf

    Where example thisis hosting account name.

  • To the image file:
    wkhtmltoimage /home/example/way/to/file/document.html document.png

    Или:

    /usr/local/bin/wkhtmltoimage /home/example/way/to/file/document.html document.png

    Where example thisis hosting account name.

When generating a PDF document, you can add a header and footer from separate HTML-files:

wkhtmltopdf --header-html <path to HTML header> --footer-html <path to HTML footer> <path to source HTML file> <path and name of output PDF file>

If necessary, you can set indents for PDF documents:

wkhtmltopdf --margin-top 25mm --margin-bottom 25 mm --margin-left 15mm --margin-right 15mm --header-html <path to HTML header> --footer-html <path to HTML footer> <path to HTML source file> <path and name of output PDF file>

Examples of other useful options for wkhtmltopdf:

  • –encoding windows-1251 - explicit indication of the source encoding HTML-file.
  • –page-size A4 - the page format of the output PDF file.
  • –orientation Landscape - the page orientation of the output PDF file.

You can use utilities from PHP using the function exec.