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

sharadchhetri

Tutorials On Linux, Unix & Open Source

  • Home
  • Linux Commands
  • Resources
    • Learn Linux
  • My WordPress plugins

Convert website page to pdf and image

August 23, 2015 by Sharad Chhetri

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:

  • Twitter
  • Facebook
  • More
  • Print
  • Email
  • LinkedIn
  • Reddit
  • Tumblr
  • Pinterest
  • Pocket
  • Telegram
  • WhatsApp
  • Mastodon

Related posts:

  1. How To Add duckduckgo Search engine in WordPress Blog or website
  2. Install pdfedit for editing pdf file in Ubuntu
  3. Configure Nginx for Jekyll / Octopress / pelican based static website
  4. Send nagios report as pdf file via email
  5. Search Keyword In Man Page Like We Search In vi / vim Editor
  6. Convert hyphen to underscore in between all filenames shell script
  7. How to convert rpm file into deb file
  8. How to convert float to integer number
  9. Convert new line to space by using sed command
  10. tr command to convert lines to space , tab and vertical tab

Filed Under: Linux Tagged With: linux command

Primary Sidebar

Our Social Media Presence

  • Facebook
  • GitHub
  • Twitter

Linux Command

What is Linux Internal And External Command

Linux Basic Commands With Examples For Every Beginner

tr command to convert lines to space , tab and vertical tab

smbpasswd command not found on CentOS 7 and RHEL 7

Solution : semanage command not found

Unix / Linux : How to print duplicate lines from file

More Posts from this Category

You Might Like These Articles!

simplecodesyntax wordpress plugin

SimpleCodeSyntax : My Another WordPress Plugin

Install Nginx

How To Install Nginx On Ubuntu 22.04 LTS

Install Latest Git package in Ubuntu Operating System

How To Always Install Latest Git Package In Ubuntu Operating System

Bash script for installing VirtualBox on Ubuntu 22.04 LTS Desktop

Install VirtualBox On Ubuntu 22.04 LTS Desktop (Bash Script)

libfuse

dlopen(): error loading libfuse.so.2 – Got Error On Ubuntu

Failed to open/create the internal network

VirtualBox Error: Failed to open/create the internal network

Always Useful Tips And Tricks

The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form

Nagios HTTP WARNING: HTTP/1.1 403 Forbidden

rsync all files,hidden files,symlinks,hardlinks to remotes Linux Server

How to put slider shortcode only in home page in WordPress

Yum Error database disk image is malformed

How to find swap partition or file in linux

df command not showing correct free space in linux

Explore 90+ Article On "Linux Tips And Tricks"

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

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