wecuro_blog/application/helpers/generatepdf_helper.202102251201.php

49 lines
1.2 KiB
PHP
Executable File

<?php defined('BASEPATH') OR exit('No direct script access allowed');
// generate pdf
function generate_pdf($name, $tpl, $data)
{
$ci = &get_instance();
$data['data'] = $data;
$html = '';
$ci->load->library('pdf');
foreach ($tpl as $value)
{
$ci->load->view($value, $data);
$html = $ci->output->get_output();
$ci->dompdf->loadHtml($html);
// setup size
$ci->dompdf->setPaper('A4', 'portrait');
// Render the HTML as PDF
}
// _die($html);
// Get output html
// add external css library
// $html .= '<link href="' . base_url() . 'assets/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">';
// Load pdf library
$ci->dompdf->render();
// echo $output = $ci->dompdf->output();
// Output PDF (1 = download and 0 = preview)
$ci->dompdf->stream($name, array("Attachment" => 0));
}
function generate_html($name, $tpl, $data)
{
$ci = &get_instance();
$data['data'] = $data;
$html = '';
$ci->load->library('pdf');
foreach ($tpl as $value)
{
$html = $ci->load->view($value, $data, true);
// Render the HTML as PDF
}
return $html;
}
?>