Fixing document html to pdf see BT#1617 & #1909

skala
Julio Montoya 15 years ago
parent 3a8cbcb15e
commit 835bee23c4
  1. 3
      main/document/document.inc.php
  2. 15
      main/document/document.php
  3. 13
      main/inc/lib/document.lib.php
  4. 26
      main/inc/lib/pdf.lib.php
  5. 2
      main/newscorm/learnpath.class.php

@ -359,7 +359,8 @@ function build_edit_icons($curdirpath, $type, $path, $visibility, $id, $is_templ
} else {
$modify_icons .= '&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&curdirpath='.$curdirpath.'&amp;remove_as_template='.$id.$req_gid.'&amp;'.$sort_params.'"><img src="../img/wizard_gray_small.gif" border="0" title="'.get_lang('RemoveAsTemplate').'" alt=""'.get_lang('RemoveAsTemplate').'" /></a>';
}
$modify_icons .= '&nbsp;<a href="export_htmldoc2pdf.php?'.api_get_cidreq().'&curdirpath='.$curdirpath.'&amp;file='.urlencode($path).$req_gid.'"><img src="../img/file_pdf_small.gif" border="0" title="'.get_lang('Export2PDF').'" alt="" /></a>';
//$modify_icons .= '&nbsp;<a href="export_htmldoc2pdf.php?'.api_get_cidreq().'&curdirpath='.$curdirpath.'&amp;file='.urlencode($path).$req_gid.'"><img src="../img/file_pdf_small.gif" border="0" title="'.get_lang('Export2PDF').'" alt="" /></a>';
$modify_icons .= '&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&action=export_to_pdf&id='.$id.'"><img src="../img/file_pdf_small.gif" border="0" title="'.get_lang('Export2PDF').'" alt="" /></a>';
}
return $modify_icons;

@ -307,20 +307,21 @@ if (isset($_GET['action']) && $_GET['action'] == 'downloadfolder' && (api_get_se
//filter when I am into shared folder, I can donwload only my shared folder
if(is_any_user_shared_folder($_GET['path'],$current_session_id))
{
if(is_my_shared_folder($_user['user_id'], $_GET['path'], $current_session_id) || api_is_allowed_to_edit() || api_is_platform_admin())
{
if(is_any_user_shared_folder($_GET['path'],$current_session_id)) {
if(is_my_shared_folder($_user['user_id'], $_GET['path'], $current_session_id) || api_is_allowed_to_edit() || api_is_platform_admin()) {
require 'downloadfolder.inc.php';
}
}
else
{
} else {
require 'downloadfolder.inc.php';
}
}
if (isset($_GET['action']) && $_GET['action'] == 'export_to_pdf') {
DocumentManager::export_to_pdf($_GET['id'],$course_code);
}
// Slideshow inititalisation
$_SESSION['image_files_only'] = '';
$image_files_only = '';

@ -994,7 +994,7 @@ class DocumentManager {
* @param string $path
* @return int id of document / false if no doc found
*/
public static function get_document_data_by_id($id,$course_code) {
public static function get_document_data_by_id($id, $course_code) {
$course_info = api_get_course_info($course_code);
$TABLE_DOCUMENT = Database :: get_course_table(TABLE_DOCUMENT, $course_info['dbName']);
$id = intval($id);
@ -1686,7 +1686,7 @@ class DocumentManager {
* @param string destination course directory
* @return string new content html with replaced urls or return false if content is not a string
*/
function replace_urls_inside_content_html_from_copy_course($content_html, $origin_course_code, $destination_course_directory) {
function replace_urls_inside_content_html_from_copy_course($content_html, $origin_course_code, $destination_course_directory) {
if (!is_string($content_html)) {
return false;
@ -1755,6 +1755,13 @@ class DocumentManager {
}
return $content_html;
}
public function export_to_pdf($document_id, $course_code) {
require_once api_get_path(LIBRARY_PATH).'pdf.lib.php';
$course_data = api_get_course_info($course_code);
$document_data = self::get_document_data_by_id($document_id, $course_code);
$file_path = api_get_path(SYS_COURSE_PATH).$course_data['path'].'/document'.$document_data['path'];
PDF::html_to_pdf($file_path, $document_data['title'], $course_code);
}
}
//end class DocumentManager

@ -8,10 +8,8 @@ require_once _MPDF_PATH.'mpdf.php';
class PDF {
private function __construct() {
}
private function __construct() {
}
/**
* Converts an html file to a pdf
@ -19,7 +17,7 @@ class PDF {
* @param string course code
* @return string the pdf path
*/
public function html_to_pdf($html_file_array, $course_code = null) {
public function html_to_pdf($html_file_array, $pdf_name = '', $course_code = null) {
if (empty($html_file_array)) {
return false;
@ -55,8 +53,7 @@ class PDF {
$pdf->defaultheaderfontsize = 10; // in pts
$pdf->defaultheaderfontstyle = BI; // blank, B, I, or BI
$pdf->defaultheaderline = 1; // 1 to include line below header/above footer
$pdf->defaultheaderline = 1; // 1 to include line below header/above footer
$my_header = self::get_header($course_code);
$pdf->SetHeader($my_header);// ('{DATE j-m-Y}|{PAGENO}/{nb}|'.$title);
@ -173,9 +170,11 @@ class PDF {
foreach($elements as $item) {
$old_src = $item->getAttribute('src');
//$old_src= str_replace('../','',$old_src);
if (strrpos('http', $old_src) === false) {
$document_html= str_replace($old_src, $document_path.$old_src, $document_html);
}
if (strpos($old_src, 'http') === false) {
if (strpos($old_src, '/main/default_course_document') === false) {
$document_html= str_replace($old_src, $document_path.$old_src, $document_html);
}
}
}
}
@ -198,7 +197,12 @@ class PDF {
//var_dump($document_html);
$pdf->WriteHTML($document_html,2);
}
$output_file = 'pdf_'.date('Y-m-d-his').'.pdf';
if (empty($pdf_name)) {
$output_file = 'pdf_'.date('Y-m-d-his').'.pdf';
} else {
$output_file = $pdf_name.'.pdf';
}
$result = $pdf->Output($output_file, 'D'); /// F to save the pdf in a file
exit;
}

@ -8384,7 +8384,7 @@ EOD;
}
}
require_once api_get_path(LIBRARY_PATH).'pdf.lib.php';
$result = PDF::html_to_pdf($files_to_export, $this->cc);
$result = PDF::html_to_pdf($files_to_export, '', $this->cc);
return $result;
}

Loading…
Cancel
Save