Now we can export images (jpg, jpeg, png, gif) in a PDF document using the LP to PDF export

skala
Julio Montoya 15 years ago
parent 0cea08caea
commit 5b96b6aa64
  1. 48
      main/inc/lib/pdf.lib.php

@ -50,6 +50,7 @@ class PDF {
//Converting the string into an array //Converting the string into an array
$html_file_array = array($html_file_array); $html_file_array = array($html_file_array);
} }
$course_data = array(); $course_data = array();
if (!empty($course_code)) { if (!empty($course_code)) {
$course_data = api_get_course_info($course_code); $course_data = api_get_course_info($course_code);
@ -65,50 +66,51 @@ class PDF {
//Formatting the pdf //Formatting the pdf
self::format_pdf($course_data); self::format_pdf($course_data);
foreach ($html_file_array as $html_file) { foreach ($html_file_array as $file) {
$html_title = ''; $html_title = '';
//if the array provided contained subarrays with 'title' entry, //if the array provided contained subarrays with 'title' entry,
// then print the title in the PDF // then print the title in the PDF
if (is_array($html_file) && isset($html_file['title'])) { if (is_array($file) && isset($file['title'])) {
$html_title = $html_file['title']; $html_title = $file['title'];
$html_file = $html_file['path']; $file = $file['path'];
} else { } else {
//we suppose we've only been sent a file path //we suppose we've only been sent a file path
$html_title = basename($html_file); $html_title = basename($file);
} }
if (empty($html_file) && !empty($html_title)) { if (empty($file) && !empty($html_title)) {
//this is a chapter, print title & skip the rest //this is a chapter, print title & skip the rest
if ($print_title) { if ($print_title) {
$this->pdf->WriteHTML('<html><body><h1>'.$html_title.'</h1></body></html>',2); $this->pdf->WriteHTML('<html><body><h3>'.$html_title.'</h3></body></html>',2);
} }
continue; continue;
} }
if (!file_exists($html_file)) { if (!file_exists($file)) {
//the file doesn't exist, skip //the file doesn't exist, skip
continue; continue;
} }
//it's not a chapter but the file exists, print its title //it's not a chapter but the file exists, print its title
if ($print_title) { if ($print_title) {
$this->pdf->WriteHTML('<html><body><h2>'.$html_title.'</h2></body></html>',2); $this->pdf->WriteHTML('<html><body><h3>'.$html_title.'</h3></body></html>',2);
} }
$file_info = pathinfo($html_file); $file_info = pathinfo($file);
$extension = $file_info['extension'];
if (in_array($extension, array('html', 'htm'))) {
$dirname = str_replace("\\", '/', $file_info['dirname']); $dirname = str_replace("\\", '/', $file_info['dirname']);
$filename = $file_info['basename']; $filename = $file_info['basename'];
$filename = str_replace('_',' ',$filename); $filename = str_replace('_',' ',$filename);
$extension = $file_info['extension'];
if (!($extension == 'html' || $extension == 'htm')) {
continue;
}
if ($extension == 'html') { if ($extension == 'html') {
$filename =basename($filename,'.html'); $filename =basename($filename,'.html');
} elseif($extension == 'htm'){ } elseif($extension == 'htm'){
$filename =basename($filename,'.htm'); $filename =basename($filename,'.htm');
} }
$document_html = @file_get_contents($html_file); $document_html = @file_get_contents($file);
$document_html = preg_replace($clean_search, '', $document_html); $document_html = preg_replace($clean_search, '', $document_html);
//absolute path for frames.css //TODO: necessary? //absolute path for frames.css //TODO: necessary?
@ -139,15 +141,6 @@ class PDF {
} }
} }
} }
//replace relative path by absolute path for resources
//$document_html= str_replace('src="/chamilo/main/default_course_document/', 'temp_template_path', $document_html);// before save src templates not apply
//$document_html= str_replace('src="/', 'temp_template_path', $document_html);// before save src templates not apply
//$document_html= str_replace('src="/chamilo/main/default_course_document/', 'temp_template_path', $document_html);// before save src templates not apply
//$src_http_www= 'src="'.api_get_path(WEB_COURSE_PATH).$course_data['path'].'/document/';
//$document_html= str_replace('src="',$src_http_www, $document_html);
//$document_html= str_replace('temp_template_path', 'src="/main/default_course_document/', $document_html);// restore src templates
api_set_encoding_html($document_html, 'UTF-8'); // The library mPDF expects UTF-8 encoded input data. api_set_encoding_html($document_html, 'UTF-8'); // The library mPDF expects UTF-8 encoded input data.
$title = api_get_title_html($document_html, 'UTF-8', 'UTF-8'); // TODO: Maybe it is better idea the title to be passed through $title = api_get_title_html($document_html, 'UTF-8', 'UTF-8'); // TODO: Maybe it is better idea the title to be passed through
// $_GET[] too, as it is done with file name. // $_GET[] too, as it is done with file name.
@ -156,8 +149,15 @@ class PDF {
$title = $filename; // Here file name is expected to contain ASCII symbols only. $title = $filename; // Here file name is expected to contain ASCII symbols only.
} }
if (!empty($document_html)) {
$this->pdf->WriteHTML($document_html,2); $this->pdf->WriteHTML($document_html,2);
} }
} elseif (in_array($extension, array('jpg','jpeg','png','gif'))) {
//Images
$image = Display::img($file);
$this->pdf->WriteHTML('<html><body>'.$image.'</body></html>',2);
}
}
if (empty($pdf_name)) { if (empty($pdf_name)) {
$output_file = 'pdf_'.date('Y-m-d-his').'.pdf'; $output_file = 'pdf_'.date('Y-m-d-his').'.pdf';

Loading…
Cancel
Save