Beispiel #1
0
 /**
  * Load a HTML file
  *
  * @param string $file
  * @return static
  */
 public function loadFile($file)
 {
     $this->init();
     $this->dompdf->load_html_file($file);
     $this->rendered = false;
     return $this;
 }
/**
 * Create a PDF
 *
 * The minimum required to create a PDF is some HTML provided as a string.
 * This is easily done in CI by providing the contents of a view.
 *
 * Example:
 * ------------------------------------------------------
 *   $this->load->helper('pdf_creation');
 *   $html = $this->load->view(
 *             'pdf_template', 
 *             ( isset( $view_data ) ) ? $view_data : '', 
 *             TRUE 
 *   );
 *   pdf_create( $html );
 * ------------------------------------------------------
 *
 * @param  string  HTML to be used for making a PDF
 * @param  array   Configuration options
 */
function pdf_create($html, $config = array())
{
    $defaults = array('output_type' => 'stream', 'filename' => microtime(TRUE) . '.pdf', 'upload_dir' => FCPATH . 'upload_directory/pdfs/', 'load_html' => TRUE, 'html_encoding' => '', 'load_html_file' => FALSE, 'output_compression' => 1, 'set_base_path' => FALSE, 'set_paper' => FALSE, 'paper_size' => 'letter', 'paper_orientation' => 'portrait', 'stream_compression' => 1, 'stream_attachment' => 1);
    // Set options from defaults and incoming config array
    $options = array_merge($defaults, $config);
    // Remove any previously created headers
    if (is_php('5.3.0') && $options['output_type'] == 'stream') {
        header_remove();
    }
    // Load dompdf
    require_once "dompdf/dompdf_config.inc.php";
    // Create a dompdf object
    $dompdf = new DOMPDF();
    // Set supplied base path
    if ($options['set_base_path'] !== FALSE) {
        $dompdf->set_base_path($options['set_base_path']);
    }
    // Set supplied paper
    if ($options['set_paper'] !== FALSE) {
        $dompdf->set_paper($options['paper_size'], $options['paper_orientation']);
    }
    // Load the HTML that will be turned into a PDF
    if ($options['load_html_file'] !== FALSE) {
        // Loads an HTML file
        $dompdf->load_html_file($html);
    } else {
        // Loads an HTML string
        $dompdf->load_html($html, $options['html_encoding']);
    }
    // Create the PDF
    $dompdf->render();
    // If destination is the browser
    if ($options['output_type'] == 'stream') {
        $dompdf->stream($options['filename'], array('compress' => $options['stream_compression'], 'Attachment' => $options['stream_attachment']));
    } else {
        if ($options['output_type'] == 'string') {
            return $dompdf->output($options['output_compression']);
        } else {
            // Get an instance of CI
            $CI =& get_instance();
            // Create upload directories if they don't exist
            if (!is_dir($options['upload_path'])) {
                mkdir($options['upload_path'], 0777, TRUE);
            }
            // Load the CI file helper
            $CI->load->helper('file');
            // Save the file
            write_file($options['upload_path'] . $options['filename'], $dompdf->output());
        }
    }
}
Beispiel #3
0
        }
        $outfile = "dompdf_out.pdf";
        # Don't allow them to set the output file
        $save_file = false;
        # Don't save the file
        break;
}
$dompdf = new DOMPDF();
if ($file == "-") {
    $str = "";
    while (!feof(STDIN)) {
        $str .= fread(STDIN, 4096);
    }
    $dompdf->load_html($str);
} else {
    $dompdf->load_html_file($file);
}
if (isset($base_path)) {
    $dompdf->set_base_path($base_path);
}
$dompdf->set_paper($paper, $orientation);
$dompdf->render();
if ($_dompdf_show_warnings) {
    foreach ($_dompdf_warnings as $msg) {
        echo $msg . "\n";
    }
    flush();
}
if ($save_file) {
    //   if ( !is_writable($outfile) )
    //     throw new DOMPDF_Exception("'$outfile' is not writable.");
Beispiel #4
0
 /**
  *
  * @param string $file 
  */
 public function renderFile($file)
 {
     $this->_domPdf->load_html_file($file);
 }