Wkhtmltopdf – TecAdmin https://tecadmin.net How to guide for System Administrator's and Developers Fri, 21 Jun 2013 10:14:55 +0000 en-US hourly 1 https://wordpress.org/?v=6.1.1 Convert HTML to PDF using Qtwebkit with PHP https://tecadmin.net/convert-html-to-pdf-using-qtwebkit-with-php/ https://tecadmin.net/convert-html-to-pdf-using-qtwebkit-with-php/#comments Fri, 21 Jun 2013 10:14:55 +0000 https://tecadmin.net/?p=1626 Wkhtmltopdf is a very useful application to create pdf from html (webpage). This article will help to create pdf of a webpage using php script and Linux command line tool. Step 1: Install wkhtmltopdf in Linux Download wkhtmltopdf from google code and install to linux system. # cd /opt # wget https://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.9.9-static-i386.tar.bz2 # tar xjf [...]

The post Convert HTML to PDF using Qtwebkit with PHP appeared first on TecAdmin.

]]>
Wkhtmltopdf is a very useful application to create pdf from html (webpage). This article will help to create pdf of a webpage using php script and Linux command line tool.

Step 1: Install wkhtmltopdf in Linux

Download wkhtmltopdf from google code and install to linux system.

# cd /opt
# wget https://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.9.9-static-i386.tar.bz2
# tar xjf wkhtmltopdf-0.9.9-static-i386.tar.bz2
# mv wkhtmltopdf-i386 /usr/bin/wkhtmltopdf
# chown apache:apache /usr/bin/wkhtmltopdf
# chmod +x /usr/bin/wkhtmltopdf
Step 2: Create Pdf Using Command Line

First check wkhtmltopdf script it its properly working from command line. Below command will create pdf of http://google.com web page.

# /usr/bin/wkhtmltopdf http://google.com google.pdf
Step 3: PHP Code to Create Pdf Using wkhtmltopdf

Use below block of php code to generate pdf from html ( webpage ). This script required to be enabled shell_exec function for Apache. Most of shared hosting provides doesn’t allow this function.

Create a file name getPdf.php using below code and put it on your website document root

<?php

$url = $_GET['url'];    // Website URL to Create pdf
$name = $_GET['pdf'];   // Output pdf name

$command = "/usr/bin/wkhtmltopdf ";
$pdf_dir = "/var/www/html/pdfs/";     // Pdf files will be saved here
$ex_cmd = "$command $url " . $pdf_dir . $name;
$output = shell_exec($ex_cmd);

?>

Open Following url to generate pdf of website ( html ).

Syntax:
http://youdomain.com/getPdf.php?url=<website url>&pdf=<pdf name>

Example:
https://tecadmin.net/getPdf.php?url=http://google.com&pdf=google.pdf


The post Convert HTML to PDF using Qtwebkit with PHP appeared first on TecAdmin.

]]>
https://tecadmin.net/convert-html-to-pdf-using-qtwebkit-with-php/feed/ 1