Posts tagged with 'php'

Delivering pages as PDF using PHP

HTML is great. It's the lingua franca of the web, and a fantastic format for exchange of hyperlinked information. However, it has its drawbacks - It typically relies on multiple external files, different browsers interpret it in different ways, and printing it is a bit of a minefield, even with the limited print CSS currently available.

So, sometimes it makes sense to present documents as a PDF as well. I've done so on this very site, with my CV, after finding that most recruitment sites won't except an HTML document, and recruiters just get confused when you attach one to an email (or send them a hyperlink).

The component I use is called dompdf. At its heart it is an HTML->PDF converter written completely in PHP, and is pretty simple to use. The code to convert some HTML to a PDF looks something like this:

<?php

// include in the dompdf library
require_once('dompdf_config.inc.php');
spl_autoload_register('DOMPDF_autoload');

// instance dompdf
$dompdf = new DomPDF();
$dompdf->set_paper('a4');

// tell the user-agent to expect a PDF
header('Content-type: application/pdf');

// load the HTML, convert it to PDF and output
$src file_get_contents('document.html');
$dompdf->load_html($src);
$dompdf->render();
echo 
$dompdf->output();

?>

Some thoughts on Zend PHP5 Certification

ZCE logo

I qualified as a ZCE yesterday. I guess the only tangible benefits of this is I get to write the letters on my CV / business cards and use this nifty logo, but I found the overall process of the certification pretty worthwhile.

The thing that's put me off certification in the past is the imagined cost, in terms of both time and money. I thought there'd be a dreary course covering things I already knew, and I'd be paying a premium for the privilege. In fact, I was completely wrong!

Once I looked into it, I found that although Zend offer a grueling 18-hour course for about £800 it's not a requirement for the certification itself, you can buy an exam voucher for about £100 and just turn up and take the test, so I did.

A new comments system

I've made a little comments system for this blog, and it gave me a chance to look a bit more into Doctrine.

I keep meaning to blog about how I put this site together, but for now I'll just say that it uses Zend Framework for MVC, with Doctrine for the ORM. To implement the comments form I used a great bit of code from CodeUtopia, written by Jani Hartikainen (a.k.a. 'zomg' on IRC) that ties together Doctrine objects and Zend_Form in quite a nice way.

I'm hoping to do a quite simple tutorial about how to implement a small blog, but that's for another time when I'm not busy revising for my ZCE!