| 1 |
<?php |
<?php |
| 2 |
/* $Id: print.pdf.inc,v 1.11 2008/06/04 14:31:58 jcnventura Exp $ */ |
/* $Id: print.pdf.inc,v 1.12 2008/06/16 17:27:48 jcnventura Exp $ */ |
| 3 |
|
|
| 4 |
require_once(drupal_get_path('module', 'print') .'/print.pages.inc'); |
require_once(drupal_get_path('module', 'print') .'/print.pages.inc'); |
| 5 |
|
|
| 56 |
} |
} |
| 57 |
|
|
| 58 |
function _print_pdf_tcpdf($print, $html, $filename) { |
function _print_pdf_tcpdf($print, $html, $filename) { |
| 59 |
|
global $base_url; |
| 60 |
$print_pdf_settings = variable_get('print_pdf_settings', print_pdf_settings_default()); |
$print_pdf_settings = variable_get('print_pdf_settings', print_pdf_settings_default()); |
| 61 |
|
|
| 62 |
|
define("K_TCPDF_EXTERNAL_CONFIG", TRUE); |
| 63 |
|
define("K_PATH_MAIN", realpath(dirname($print_pdf_settings['pdf_tool'])) ."/"); |
| 64 |
|
define("K_PATH_URL", $base_url ."/". dirname($print_pdf_settings['pdf_tool']) ."/"); |
| 65 |
|
define("K_PATH_FONTS", K_PATH_MAIN ."fonts/"); |
| 66 |
|
define("K_PATH_CACHE", K_PATH_MAIN ."cache/"); |
| 67 |
|
define("K_PATH_IMAGES", K_PATH_MAIN ."images/"); |
| 68 |
|
define("K_BLANK_IMAGE", K_PATH_IMAGES ."_blank.png"); |
| 69 |
|
define("K_CELL_HEIGHT_RATIO", 1.25); |
| 70 |
|
define("K_SMALL_RATIO", 2/3); |
| 71 |
|
|
| 72 |
require_once($print_pdf_settings['pdf_tool']); |
require_once($print_pdf_settings['pdf_tool']); |
| 73 |
|
|
| 74 |
$font_name = "dejavusans"; |
$font_name = "dejavusans"; |
| 77 |
$orientation = strtoupper($print_pdf_settings['page_orientation']{0}); |
$orientation = strtoupper($print_pdf_settings['page_orientation']{0}); |
| 78 |
|
|
| 79 |
// create new PDF document |
// create new PDF document |
| 80 |
$pdf = new TCPDF($orientation , PDF_UNIT, $print_pdf_settings['paper_size'], TRUE); |
$pdf = new TCPDF($orientation , "mm", $print_pdf_settings['paper_size'], TRUE); |
| 81 |
|
|
| 82 |
// set document information |
// set document information |
| 83 |
$pdf->SetAuthor(strip_tags($print["submitted"])); |
$pdf->SetAuthor(strip_tags($print["submitted"])); |
| 92 |
|
|
| 93 |
// set header and footer fonts |
// set header and footer fonts |
| 94 |
$pdf->setHeaderFont(Array($font_name, '', $font_size)); |
$pdf->setHeaderFont(Array($font_name, '', $font_size)); |
| 95 |
$pdf->setFooterFont(Array($font_name, '', PDF_FONT_SIZE_DATA)); |
$pdf->setFooterFont(Array($font_name, '', 8)); |
| 96 |
|
|
| 97 |
// set margins |
// set margins |
| 98 |
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); |
$pdf->SetMargins(15, 27, 15); |
| 99 |
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER); |
$pdf->SetHeaderMargin(5); |
| 100 |
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER); |
$pdf->SetFooterMargin(10); |
| 101 |
|
|
| 102 |
// set auto page breaks |
// set auto page breaks |
| 103 |
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); |
$pdf->SetAutoPageBreak(TRUE, 25); |
| 104 |
|
|
| 105 |
// set image scale factor |
// set image scale factor |
| 106 |
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); |
$pdf->setImageScale(4); |
| 107 |
|
|
| 108 |
//initialize document |
//initialize document |
| 109 |
$pdf->AliasNbPages(); |
$pdf->AliasNbPages(); |
| 114 |
preg_match("/<body>(.*)<\/body>/sim", $html, $matches); |
preg_match("/<body>(.*)<\/body>/sim", $html, $matches); |
| 115 |
$matches[1] = preg_replace("/.*?(<[^<]*?print-content.*?>)/sim", "$1", $matches[1]); |
$matches[1] = preg_replace("/.*?(<[^<]*?print-content.*?>)/sim", "$1", $matches[1]); |
| 116 |
|
|
| 117 |
$pdf->SetFont($font_name, 'B', $font_size * K_TITLE_MAGNIFICATION); |
$pdf->SetFont($font_name, 'B', $font_size * 1.3); |
| 118 |
$pdf->writeHTML($print["title"]); |
$pdf->writeHTML($print["title"]); |
| 119 |
|
|
| 120 |
if ($print["submitted"]) { |
if ($print["submitted"]) { |