The Prince
PHP wrapper includes methods for converting files or strings into PDF. However, you probably have some PHP pages generating invoices for the browser, and you want to return a PDF instead. We don't yet offer a one-line call to do this, but it should be possible to do it using the
ob_start and
ob_get_clean functions, like this:
<?php
ob_start();
// your code to generate invoice HTML goes here
$out = ob_get_clean();
$prince = new Prince('/usr/bin/prince');
$prince->setHTML(1);
$prince->setLog('/tmp/prince.log');
header('Content-type: application/pdf');
$prince->convert_string_to_passthru($out);
?>
The ob_start function begins output buffering, so PHP will buffer up the HTML internally instead of returning it to the browser, then ob_get_clean wipes the buffer and returns it as a string so that the generated HTML can be converted to PDF by Prince and the PDF returned to the browser with an appropriate content-type so that the browser knows what to do with it.
How is that?