Extension:Pdf Export Dompdf

Overview
This extension is a modified version of the Pdf_Export Extension. See Extension:Pdf_Export for details.

I modified it because I wanted to do pdf-export on my shared hosting server. It was impossible to install htmldoc on it because I dont't have root access.

Searching the web, I found dompdf a html to pdf converter written in php5.

Installation

 * Install the original Pdf Export like on Extension:Pdf_Export
 * Overwrite $IP/extensions/PdfExport/PdfExport.php with the Code below
 * Install dompdf
 * you can download it from http://www.digitaljunkies.ca/dompdf
 * untar dompdf into $IP/extensions/dompdf (details and config at )
 * add require_once("extensions/PdfExport/PdfExport.php"); to your LocalSettings.php

Code
Put the following into $IP/extensions/PdfExport/PdfExport.php: ";

$bhtml = utf8_decode($bhtml); $bhtml = str_replace ($wgScriptPath, $wgServer . $wgScriptPath, $bhtml); $bhtml = str_replace ('/w/',$wgServer . '/w/', $bhtml); $css = " body {padding: 30px;} ";

$header_footer = "

if ( isset(\$pdf) ) {

\$font = Font_Metrics::get_font(\"verdana\"); \$size = 10; \$color = array(0,0,0); \$text_height = Font_Metrics::get_font_height(\$font, \$size);

\$foot = \$pdf->open_object; \$w = \$pdf->get_width; \$h = \$pdf->get_height;

// Draw a line along the bottom \$y = \$h - 2 * \$text_height - 24; \$pdf->line(16, \$y, \$w - 16, \$y, \$color, 1);

\$y += \$text_height;

\$text = \"$author, $date\"; \$pdf->text(16, \$y, \$text, \$font, \$size, \$color);

\$pdf->close_object; \$pdf->add_object(\$foot, \"all\");

\$text = \"Seite {PAGE_NUM}/{PAGE_COUNT}\";

\$width = Font_Metrics::get_text_width(\"Page 10/20\", \$font, \$size); \$pdf->page_text(\$w-5 - \$width, \$y, \$text, \$font, \$size, \$color); } ";

$html = "  ". utf8_decode($page). " $css $info ". utf8_decode($title->getText). " " . $bhtml. "$header_footer ";

//removed lines

//added by ah, using dompdf $html = str_replace ("src=\"/images", "src=\"images", $html); $html = str_replace ('', "", $html);

require_once("$IP/extensions/dompdf/dompdf_config.inc.php");

$dompdf = new DOMPDF; $dompdf->set_base_path("$IP/"); $dompdf->set_paper ("a4"); $dompdf->load_html($html); $dompdf->render; $dompdf->stream(utf8_decode($page) . ".pdf", array('Attachment'=>0));

}       } function wfSpecialPdf { global $IP, $wgMessageCache; # Add messages global $wgPdfExportMessages; foreach( $wgPdfExportMessages as $lang => $messages ) { $wgMessageCache->addMessages( $messages, $lang ); } } function wfSpecialPdfNav( &$skintemplate, &$nav_urls, &$oldid, &$revid ) { $nav_urls['pdfprint'] = array(                       'text' => wfMsg( 'pdf_print_link' ),                        'href' => $skintemplate->makeSpecialUrl( 'PdfPrint', "page=". wfUrlencode( "{$skintemplate->thispage}" ) )                ); return true; } function wfSpecialPdfToolbox( &$monobook ) { if ( isset( $monobook->data['nav_urls']['pdfprint'] ) ) if ( $monobook->data['nav_urls']['pdfprint']['href'] == '' ) { ?>msg( 'pdf_print_link' ); ?>data['nav_urls']['pdfprint']['href'] ) ?>">msg( 'pdf_print_link' ); ?><?php }       return true; }