All journal entries
phpServer RelatedWeb Development

Install wkhtmltopdf on Ubuntu and use with PHP

Install the wkhtmltopdf build sudo apt-get update sudo apt-get install xvfb sudo apt-get install wkhtmltopdf (tested in ubuntu 14.04 x64) Install PHP wrapper Install php wrapper from github using composer composer require mikehaertl/phpwkhtmltopdf

Install wkhtmltopdf on Ubuntu and use with PHP

Install the wkhtmltopdf build

sudo apt-get update
sudo apt-get install xvfb
sudo apt-get install wkhtmltopdf

(tested in ubuntu 14.04 x64)

Install PHP wrapper

Install php wrapper from github using composer

composer require mikehaertl/phpwkhtmltopdf
require __DIR__ . '/vendor/autoload.php';

use mikehaertl\wkhtmlto\Pdf;
// You can pass a filename, a HTML string, an URL or an options array to the constructor
$pdf = new Pdf(array(
    'no-outline',         // Make Chrome not complain
    'margin-top'    => 0,
    'margin-right'  => 0,
    'margin-bottom' => 0,
    'margin-left'   => 0,
    'viewport-size' => '1280x1024' // this is needed otherwise it will grab the mobile version of your website
));

// Add a page. To override above page defaults, you could add
// another $options array as second argument.
$pdf->addPage('http://www.example.com');

// On some systems you may have to set the path to the wkhtmltopdf executable
// $pdf->binary = 'C:\...';

if (!$pdf->saveAs('/path/to/page.pdf')) {
    echo $pdf->getError();
}

Start a build

Tell me where work is getting stuck.

Share the process, bottleneck or idea. I'll reply with a practical first step—not a generic sales pitch.

Sent securely to my inbox. Your details are only used to reply.