I wonder if it is really possible to build a HTML renderer (a significant part of HTML-to-PDF converter, which is much more than a HTML parser) in PHP? We've been working on such product in Java (HTML+CSS->PDF) since more than 5 years and the task is really untrivial despite the fact we may use all power of JDK.
PHP PDF classes make the task simplier (from computing perspective), but they require a PHP programmer to define document layouts, which is normally a task for less technically-, but more "artistic-" skilled persons.
The best alternative is to use PHP wrappers around native or cross-platform HTML-to-PDF applications.
Our solution looks like that in PHP code:
-
<?
-
if (array_key_exists('url', $_POST)) {
-
-
header('Content-type: application/pdf');
-
header('Content-disposition: inline');
-
//header('Content-disposition: attachment; filename=test.pdf');
-
-
// UNIX version
-
// Please make sure, that web user is allowed to write to ./stderr.txt.
-
// If not, please remove 2>>stderr.txt command-line suffix
-
-
passthru('java -Xmx512m -Djava.awt.headless=true -cp .:pd4ml_demo.jar Pd4Php \'' . $_POST['url'] . '\' 800 A4 2>>stderr.txt');
-
-
// Windows version
-
//passthru('java -Xmx512m -cp .;pd4ml_demo.jar Pd4Php ' . $_POST['url'] . ' 800 A4');
-
-
} else {
-
echo 'invalid usage';
-
}
-
?>
-
Here is some more info how to define, for example, "As PDF" button for your PHP pages:
http://pd4ml.com/php.htm