Exemple #1
0
  Creating the PDF from local HTML file....  Note that we customize the headers and footers!<br />
<?php 
// Require the class
require_once dirname(__FILE__) . '/../HTML_ToPDF.php';
// Full path to the file to be converted
$htmlFile = dirname(__FILE__) . '/test.html';
// The default domain for images that use a relative path
// (you'll need to change the paths in the test.html page
// to an image on your server)
$defaultDomain = 'www.rustyparts.com';
// Full path to the PDF we are creating
$pdfFile = dirname(__FILE__) . '/timecard.pdf';
// Remove old one, just to make sure we are making it afresh
@unlink($pdfFile);
// Instnatiate the class with our variables
$pdf = new HTML_ToPDF($htmlFile, $defaultDomain, $pdfFile);
// Set headers/footers
$pdf->setHeader('color', 'blue');
$pdf->setFooter('left', 'Generated by HTML_ToPDF');
$pdf->setFooter('right', '$D');
$result = $pdf->convert();
// Check if the result was an error
if (PEAR::isError($result)) {
    die($result->getMessage());
} else {
    echo "PDF file created successfully: {$result}";
    echo '<br />Click <a href="' . basename($result) . '">here</a> to view the PDF file.';
}
?>
</body>
</html> 
Exemple #2
0
<head>
  <title>Testing HTML_ToPDF</title>
</head>
<body>
  Creating the PDF from remote web page...<br />
<?php 
// Require the class
require_once dirname(__FILE__) . '/../HTML_ToPDF.php';
// Full path to the file to be converted (this time a webpage)
// change this to your own domain
$htmlFile = 'http://www.example.com/index.html';
$defaultDomain = 'www.example.com';
$pdfFile = dirname(__FILE__) . '/test2.pdf';
// Remove old one, just to make sure we are making it afresh
@unlink($pdfFile);
$pdf = new HTML_ToPDF($htmlFile, $defaultDomain, $pdfFile);
// Set that we do not want to use the page's css
$pdf->setUseCSS(false);
// Give it our own css, in this case it will make it so
// the lines are double spaced
$pdf->setAdditionalCSS('
p {
  line-height: 1.8em;
  font-size: 12pt;
}');
// We want to underline links
$pdf->setUnderlineLinks(true);
// Scale the page down slightly
$pdf->setScaleFactor('.9');
// Make the page black and light
$pdf->setUseColor(false);
Exemple #3
0
  What CSS properties and blocks can be used can be found at 
  <a href="http://www.tdb.uu.se/~jan/html2psug.html">http://www.tdb.uu.se/~jan/html2psug.html</a>
  </h6>
  Inserting a page break..<br /><br />
  <!--NewPage-->
  Now on to page 2!
</body>
</html>
<?php 
// Write the buffered HTML file
$fp = fopen($htmlFile, 'w');
fwrite($fp, ob_get_contents());
fclose($fp);
ob_end_flush();
// Let the class generate a unique PDF filename
$pdf = new HTML_ToPDF($htmlFile, $defaultDomain);
// Example setup if running under windows:
// $pdf->setHtml2Ps('perl c:\html2ps\bin\html2ps');
// $pdf->setPs2Pdf('c:\ghostscript\bin\ps2pdf');
// Could turn on debugging to see what exactly is happening
// (commands being run, images being grabbed, etc.)
// $pdf->setDebug(true);
// Convert the file
$result = $pdf->convert();
// Check if the result was an error
if (PEAR::isError($result)) {
    die($result->getMessage());
} else {
    // Move the generated PDF to the web accessible file
    copy($result, $linkToPDFFull);
    unlink($result);