PHP Classes

File: Overview

Recommend this page to a friend!
  Classes of PHP-4-Business   WKHTMLTOPDF HTML to PDF creator   Overview   Download  
File: Overview
Role: Documentation
Content type: text/plain
Description: Brief overview
Class: WKHTMLTOPDF HTML to PDF creator
Convert HTML to PDF using the Webkit engine
Author: By
Last change: comments
Date: 11 years ago
Size: 5,179 bytes
 

Contents

Class file image Download
/** * This class was produced by PHP-4-Business.co.uk and is based on the classes from * aur1mas <aur1mas@devnet.lt> -- https://github.com/aur1mas/Wkhtmltopdf * and * uuf6429@gmail.com / contact@covac-software.com -- http://code.google.com/p/wkhtmltopdf/wiki/IntegrationWithPhp * * Authorship and copyright of those classes is unclear - they both claim authorship although the code is largely identical! * From: * https://github.com/aur1mas/Wkhtmltopdf * @author Aurimas Baubkus aka aur1mas <aur1mas@devnet.lt> * @license Released under "New BSD license" * and * http://code.google.com/p/wkhtmltopdf/wiki/IntegrationWithPhp * @copyright 2010 Christian Sciberras / Covac Software. * @license None. There are no restrictions on use, however keep copyright intact. * Modification is allowed, keep track of modifications below in this comment block. * * * * Manual for wkhtmltopdf 0.10.0 rc2 * http://madalgo.au.dk/~jakobt/wkhtmltoxdoc/wkhtmltopdf_0.10.0_rc2-doc.html * * Raw settings * http://www.cs.au.dk/~jakobt/libwkhtmltox_0.10.0_doc/pagesettings.html * * * This class allows to use either the binary program ( http://code.google.com/p/wkhtmltopdf/ ) * or the PHP extension ( https://github.com/mreiferson/php-wkhtmltox ) * * Note: to use many of the useful parameters (e.g. headers and footers) you need a patched version of QT. * This is included within the statically compiled binary, but if you compile the binary yourself or compile the * PHP extension then you must patch QT yourself before compilation (see http://code.google.com/p/wkhtmltopdf/wiki/compilation) * * * Written and tested on Centos 5.4 + PHP 5.2.12 * * * Sample Usage * ------------ * <?php * try { * $wkhtmltopdf = new wkhtmltopdf(array('path' => APPLICATION_PATH . '/../public/uploads/')); * $wkhtmltopdf->setTitle("Title"); * $wkhtmltopdf->setHtml("Content"); * $wkhtmltopdf->output(wkhtmltopdf::MODE_DOWNLOAD, "file.pdf"); * } catch (Exception $e) { * echo $e->getMessage(); * } * ?> * * * Alternatively * ------------- * $headerhtml & $footerhtml will be repeated on each page * * <?php * $headerhtml = '<html><head></head><body><table width="100%" border="0"><tr><td width="100%"><img src="' . $_SERVER['HTTP_HOST'] . '/logo.png" /><span style="float:right;font-size:12px">Some Text</span></td></tr></table></body></html>'; * * $footerhtml = '<html><head></head><body><table width="100%" border="0"><tr><td width="100%" style="text-align:center;font-size:10px;color:blue;">1 Anystreet, Anytown, Anycounty&nbsp;&nbsp;&nbsp;tel: 01234 567890&nbsp;&nbsp;&nbsp;mail@address.co.uk</td></tr></table></body></html>'; * * $wkhtmloptions .= '--header-spacing 5 --footer-spacing 2 --grayscale --margin-top 15'; * * $pdf = new wkhtmltopdf(array( 'title' => 'Title', * 'html' => 'Content', * 'tmppath' => $_SERVER['DOCUMENT_ROOT'].'tmp', * 'binpath' => $_SERVER['DOCUMENT_ROOT'].'bin/', * 'header_html' => $headerhtml, * 'footer_html' => $footerhtml, * 'options' => $wkhtmloptions, * ) ); * $pdf->output('I', 'document.pdf'); * ?> * * * * PHP extension * ------------- * To use the PHP extension instantiate the object with the 'php' param. * Note: when using the PHP extension you must use the appropriate 'raw' parameters (e.g. 'header.center') and NOT * the binary ones (e.g. '--header-center'). * also make sure you put the param in the correct array - some settings are "global" and some are "object" (see the manual) * * $wkhtmloptions['global'] = array( 'colorMode' => 'grayscale', 'margin.top' => '15mm' ); * $wkhtmloptions['object'] = array( 'header.spacing' => '5mm', 'footer.spacing' => '2mm' ); * * $pdf = new wkhtmltopdf(array( 'title' => 'Title', * 'html' => 'Content', * 'tmppath' => $_SERVER['DOCUMENT_ROOT'].'tmp', * 'header_html' => $headerhtml, * 'footer_html' => $footerhtml, * 'options' => $wkhtmloptions, * ) ,'php'); * * $pdf->output('I', 'document.pdf'); * * * * * When using output() the mode param takes one of 4 values: * * 'D' (const MODE_DOWNLOAD = 'D') - Force the client to download PDF file * 'S' (const MODE_STRING = 'S') - Returns the PDF file as a string * 'I' (const MODE_EMBEDDED = 'I') - When possible, force the client to embed PDF file * 'F' (const MODE_SAVE = 'F') - PDF file is saved on the server. The path+filename is returned. * * But note that the user's browser settings may override what you ask for! * * */