First off, I should point out that I *hate* PDFs.
When the format was first launched, I remember a review of it, and the article posed the question "What is the point?" It was inconclusive, and I have still not worked out what the point of a PDF is. Does it stop the receiver from editing the document? - No. Is it easier to transmit ? - No. Is it easier to write software for ? - Definitely No. Is it in some way more secure? - No. Is it easier to read ? - No, more difficult. Is it more portable than HTML? - No.
Notwithstanding, people expect to be able to transmit documents as PDFs. Adobe have done a wonderful marketing job, and it isn't my place to unilaterally open everyones' eyes to the pointlessness of their proprietary document format.
The solution? The applications produce html (probably from within the database), then have the facility to convert it to pdf at application level. The user can then transmit the PDF as an email attachment or file it somewhere as they see fit. Production of XML, direct import into google apps and other machine-readable formats will follow later.
To perform the translation, I am using dompdf v 0.5.1. This is a free, downloadable set of classes specifically for converting html to pdf, it is all done natively in php and requires no further downloads. It has limited font support (suggest stick with Helvetica), but understands CSS, tables and graphics, and even some support for inline scripting.
Here's an example bit of conversion code:
<?php
require_once("dompdf_config.inc.php");
$dompdf = new DOMPDF();
$dompdf->load_html_file("test.htm");
$dompdf->render();
$dompdf->stream("sample".time().".pdf");
?>
require_once("dompdf_config.inc.php");
$dompdf = new DOMPDF();
$dompdf->load_html_file("test.htm");
$dompdf->render();
$dompdf->stream("sample".time().".pdf");
?>
And it seems pretty happy to convert something like this:
<html>
<head>
<style>
td {font-family:Helvetica;font-size:10px;background-color:#ffffff;border-style:solid;border:thin solid #c0c0c0}
th {font-family:Helvetica;font-size:30px;background-color:#e0e0e0;border:thin solid #c0c0c0}
table {border:none;border-spacing:0;border-collapse:collapse;}
h1 {font-family:Helvetica;font-size:20px}
</style>
</head>
<h1>A Heading</h1>
<table width="100%">
<tr>
<tH>a</tH>
<tH>b</tH>
<tH>c</tH>
</tr>
<tr>
<td>d</td>
<td>e</td>
<td>f</td>
</tr>
</table>
<img src=".\coldhot.jpg">
</html>
<head>
<style>
td {font-family:Helvetica;font-size:10px;background-color:#ffffff;border-style:solid;border:thin solid #c0c0c0}
th {font-family:Helvetica;font-size:30px;background-color:#e0e0e0;border:thin solid #c0c0c0}
table {border:none;border-spacing:0;border-collapse:collapse;}
h1 {font-family:Helvetica;font-size:20px}
</style>
</head>
<h1>A Heading</h1>
<table width="100%">
<tr>
<tH>a</tH>
<tH>b</tH>
<tH>c</tH>
</tr>
<tr>
<td>d</td>
<td>e</td>
<td>f</td>
</tr>
</table>
<img src=".\coldhot.jpg">
</html>
Here's some more documentation.
No comments:
Post a Comment