• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
sharadchhetri

sharadchhetri

AI, Linux, Cloud and DevOps

  • Home
  • Resources
    • Learn Linux
    • Articles
  • My Projects & Work
    • My Nagios Plugin
    • My Dockerhub Repo
    • My WordPress plugins
    • My Github Repos
  • Facebook Page
  • Contact
  • Privacy Policy
  • About Me
You are here: Home / Articles / Convert website page to pdf and image

Convert website page to pdf and image

August 23, 2015 by Sharad Chhetri Leave a Comment

To convert website page to pdf and image is very useful for various reasons. This kind of requirement you may have seen while making any report and we need to convert website page to pdf or image.

Recently, we got requirement to create website page to pdf for some report. Actually the report was displaying on web page only and through script we want to automate that web report should be sent via email as a attached pdf file. To accomplish this we have use the utility called wkhtmltopdf and wkhtmltoimage.

wkhtmltopdf and wkhtmltoimage are open source (LGPLv3) command line tools to render HTML into PDF and various image formats using the Qt WebKit rendering engine. These run entirely “headless” and do not require a display or display service. (Reference taken from official website)

Install the wkhtmltopdf and wkhtmltoimage on CentOS 7 / Ubuntu 14.04 LTS

On CentOS 7.x/ RHEL 7.x, use the below given command to install. On RHEL 7.x and CentOS 7.x, first install epel repo.

yum install epel-release
yum install wkhmtltopdf

On Ubuntu 14.04 LTS, use below given command as per your Operating System architecture.

For 32 bit Ubuntu 14.04 LTS system,

wget http://download.gna.org/wkhtmltopdf/0.12/0.12.2.1/wkhtmltox-0.12.2.1_linux-precise-i386.deb
sudo dpkg -i wkhtmltox-0.12.2.1_linux-precise-i386.deb

For 64 bit Ubuntu 14.04 LTS system,

wget http://download.gna.org/wkhtmltopdf/0.12/0.12.2.1/wkhtmltox-0.12.2.1_linux-precise-amd64.deb
sudo dpkg -i wkhtmltox-0.12.2.1_linux-precise-amd64.deb

You can also explore the Download page of wkhtmltopdf for your Operating System.

How to use wkhtmltopdf and wkhtmltoimage

We are sharing some of the example here which is generally used. Please do note, replace the example URL, username, password, output file name (eg. test.pdf,test.png)and other parameter values as per your scenario cases and requirement.

Example 1: Without using any extra parameter we are using here wkhtmltopdf and wkhtmltoimage command.

For PDF file :

wkhtmltopdf https://sharadchhetri.com /tmp/test.pdf

For image file:

wkhtmltoimage https://sharadchhetri.com /tmp/test.png

Example 2: In case the URL has HTTP authentication then you can provide username and password in command line.

For PDF file :

wkhtmltopdf --username GiveYourUserName --password GiveYourPasword https://sharadchhetri.com /tmp/test.pdf

For image file:

wkhtmltoimage --username GiveYourUserName --password GiveYourPasword https://sharadchhetri.com /tmp/test.png

Example 3: Adding Table Of Content in pdf

wkhtmltopdf toc https://sharadchhetri.com/ sharad.pdf

Given below is example output of ‘Table Of Content’ –
sharad.pdf

You can explore and use multiple options available with wkhtmltopdf and wkhtmltoimage , to read more visit http://wkhtmltopdf.org/usage/wkhtmltopdf.txt

Share this:

  • Share on X (Opens in new window) X
  • Share on Facebook (Opens in new window) Facebook
  • More
  • Print (Opens in new window) Print
  • Email a link to a friend (Opens in new window) Email
  • Share on LinkedIn (Opens in new window) LinkedIn
  • Share on Reddit (Opens in new window) Reddit
  • Share on Tumblr (Opens in new window) Tumblr
  • Share on Pinterest (Opens in new window) Pinterest
  • Share on Telegram (Opens in new window) Telegram
  • Share on WhatsApp (Opens in new window) WhatsApp
  • Share on Mastodon (Opens in new window) Mastodon

Articles

Learn tar command and know about its precaution
Managing Jenkins plugins : command and GUI
How to install wordpress on LAMP stack ( Ubuntu 14.04 LTS Server )
How to create Ubuntu docker base image
Your own analytics server like google analytics with Piwik
Essential Linux Commands Every Beginner Should Know | With Examples
Install osTicket ( Open source ticketing tool ) on Ubuntu 14.04 LTS
How To Upgrade Ubuntu 16.04 To 18.04 LTS Desktop
Ubuntu / Debian : gpg error the following signatures couldn’t be verified
Install and setup multisite drupal on CentOS 6.5
RSA key authentication in Linux : Passwordless login
How To Install pip3 / pip2 In Linux
Send nagios report as pdf file email
How to install Jenkins on Ubuntu 18.04 LTS server
How to install GIMP 2.10 on Ubuntu / Debian

Filed Under: Articles Tagged With: linux command

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Articles

  • Install n8n docker in Ubuntu for practicing
  • Bash Script: MySQL Database backup to AWS S3
  • Automate no touch Jenkins setup wizard on docker (jcac)
  • How to run and configure Jenkins in Docker container
  • Complete Guide: How to install Nagios Monitoring on AlmaLinux / Rocky Linux
  • Install KVM on Ubuntu 24.04 LTS ( Bash Script )
  • How to install GIMP 2.10 on Ubuntu / Debian
  • 5 ways to check Ubuntu version of system (commands and GUI)
  • How To Solve Forgot MySQL / MariaDB Root Password
  • Create Self Hosted Build Agent Docker Image for Azure DevOps

Copyright © 2026 ยท
The material in this site cannot be republished either online or offline, without our permission.
Proudly Blogging From India.

  • Contact
  • About Me
  • My WordPress plugins
  • Privacy Policy