I've just discovered a great html2pdf converter here:

http://www.rustyparts.com/pdf.php

Previously, I've used the pdfview module, which makes use of the html2fpdf code, and it produces some really ugly pdfs because it doesn't pay attention to css. The one above requires perl, html2ps, and another library, so it's not so fun to install, and the rendering is a little slower but the results are truly impressive.

I won't volunteer to write a new module (i actually implemented it in the theme), but if anyone else cares, you can bug me and I'll provide more details.

Comments

Phillip Mc’s picture

thanks for posting that.

it looks very interesting. Much more drupal friendly than the pdfview.module which is great, but, very difficult to theme the output at the moment.

Do you have any more details? Care to share your theme code you used to integrate it?

Phil

adixon’s picture

i implemented it kind of like the print-friendly mechanism (in the old civicspace theme). In other words, i generate the usual output from page.tpl.php, with some modifications, and then at the bottom of the page.tpl.php, i have the following code, which grabs the html output, processes it through the html2ps code and then outputs it. The normal page has a little link on it which just appends ?pdfview=1 to the current url to trigger the pdf output. This approach means any page can be pdf'd.

  if( isset( $_GET['pdfview'] ) ) {
    $output = ob_get_contents();
    ob_end_clean();
    require_once('misc/HTML_ToPDF-3.5/HTML_ToPDF.php');
    $tmpdir = variable_get('file_directory_temp', FILE_DIRECTORY_TEMP);
    $pdfFile = tempnam($tmpdir,'pdf');
    $pdf =& new HTML_ToPDF($output, $GLOBALS['base_url'], $pdfFile);
    $pdf->setHtml2Ps($_SERVER['DOCUMENT_ROOT'].'/misc/html2ps/bin/html2ps');
    $pdf->setMakeAbsoluteImageUrls(FALSE);
    # $pdf->setDebug(1);
    // 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 (is_a($result, 'HTML_ToPDFException')) {
      die($result->getMessage());
    }
    else {
      $title = $title ? html_entity_decode($title) : '<WHATEVER>';
      $filename = strtr(strip_tags($title), " .,?!&#", "_______");
      header("Content-Disposition: attachment; filename=". $filename .".pdf");
      header("Content-Type: application/pdf");
      print @file_get_contents($pdfFile);
      @unlink($pdfFile);
      die();
    }
  }