Example #1
0
 /**
  * Generate a PDF for the currently load()'d quote
  * Return the path to the file name for this quote.
  * @return bool
  */
 public static function generate_pdf($invoice_id)
 {
     if (!function_exists('convert_html2pdf')) {
         return false;
     }
     $invoice_id = (int) $invoice_id;
     $invoice_data = self::get_invoice($invoice_id);
     $invoice_html = self::invoice_html($invoice_id, $invoice_data, 'pdf');
     if ($invoice_html) {
         //echo $invoice_html;exit;
         $base_name = basename(preg_replace('#[^a-zA-Z0-9_]#', '', module_config::c('invoice_file_prefix', 'Invoice_')));
         if (isset($invoice_data['credit_note_id']) && $invoice_data['credit_note_id']) {
             $base_name = basename(preg_replace('#[^a-zA-Z0-9_]#', '', module_config::c('credit_note_file_prefix', 'Credit_Note_')));
         }
         $file_name = preg_replace('#[^a-zA-Z0-9]#', '', $invoice_data['name']);
         $html_file_name = _UCM_FOLDER . 'temp/' . $base_name . $file_name . '.html';
         $pdf_file_name = _UCM_FOLDER . 'temp/' . $base_name . $file_name . '.pdf';
         file_put_contents($html_file_name, $invoice_html);
         return convert_html2pdf($html_file_name, $pdf_file_name);
     }
     return false;
 }
Example #2
0
 }
 ob_end_clean();
 ob_start();
 $template = module_template::get_template_by_key($data_type['print_pdf_template']);
 if (!$template || $template->template_key != $data_type['print_pdf_template']) {
     echo "PDF template " . $data_type['print_pdf_template'] . " not found";
 } else {
     $template->assign_values($replace);
     echo $template->render('html');
 }
 $html_output = ob_get_clean();
 $pdf_name = basename(preg_replace('#[^a-zA-Z0-9_]#', '_', $data_type['data_type_name']));
 $html_file_name = _UCM_FOLDER . 'temp/data_' . $pdf_name . '.html';
 $pdf_file_name = _UCM_FOLDER . 'temp/data_' . $pdf_name . '.pdf';
 file_put_contents($html_file_name, $html_output);
 $pdf_file = convert_html2pdf($html_file_name, $pdf_file_name);
 @ob_end_clean();
 @ob_end_clean();
 // send pdf headers and prompt the user to download the PDF
 header("Pragma: public");
 header("Expires: 0");
 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
 header("Cache-Control: private", false);
 header("Content-Type: application/pdf");
 header("Content-Disposition: attachment; filename=\"" . basename($pdf_file) . "\";");
 header("Content-Transfer-Encoding: binary");
 $filesize = filesize($pdf_file);
 if ($filesize > 0) {
     header("Content-Length: " . $filesize);
 }
 // some hosting providershave issues with readfile()