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();
?>
The first thing I should probably mention is that yes, despite saying I wouldn't, I got an iPhone 3G relatively soon after release. I'll skip the reasons why for now, that's for a future posting. Naturally the first thing I did upon getting my iPhone was to plug in my own site's URL into the browser and see how it did - you can see the result in the screengrab.
You know what - it's not bad. The site looks roughly as it should, and with a bit of zooming and panning around all the content is accessible. However, on first load the text isn't really legible and it's not making the best usage of the limited screen space on the iPhone. Also, the large header graphic makes loading a bit strenuous over an EDGE connection when I'm not in 3G coverage.
Simon has been blogging recently (here and here), about 'mobilising' websites (and has written a good article on the subject for php|architect) so it's something I've been thinking about lately and I decided to see what it would take to improve the way the page was rendered on iPhone.
Today saw my debut over at Fifteensquared as one of their daily crossword blogging team. About once a week I'll be blogging a solution for the Guardian crossword, hopefully reasonably early on the day of publication.
It's been an interesting experience. On a normal day I'll buy the Guardian in the morning and do a couple of clues on the way in to work, then have it sitting on my desk for an occasional glance through the morning. When I have a free lunch I'll finish it off, usually with a bit of help from Paul if he's online. I hadn't realised how much pressure I'd be adding to myself by committing to solve it on a certain day.
I woke up this morning in a vague panic about whether I'd manage to fit it in. When I got the paper at my local corner shop, I turned straight to the crossword page and my heart sank - today's setter was Araucaria, possibly the hardest setter the Guardian use and certainly the most inventive. I normally consider it a bit of a triumph to finish his puzzles by the end of the day, let alone in the morning.
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.