[eluser]miss_amylee[/eluser]
hi..im using dompdf to create my pdf file..but im getting weird prob here..when i run it, browser displayed 'connection interrupted'.. pls help me guys..tQ
here is my controller:
Code:
<?php
class htmltopdf extends Controller{
function htmltopdf(){
parent::Controller();
}
function index(){
$this->load->library( 'parser' );
$this->load->plugin( 'to_pdf_pi' );
//render your html first, I'm using parser on this example
//you can always use any method you like
$html = $this->parser->parse('sample.html', $data, true);
pdf_create( $html, 'sample.pdf', TRUE ); //this will stream only
}
}
?>
my plugin
Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
ini_set("memory_limit","32M");
function pdf_create($html, $filename, $stream=TRUE)
{
require_once(BASEPATH."plugins/dompdf/dompdf_config.inc.php");
$dompdf = new DOMPDF();
$dompdf->set_paper("a4", "portrait");
$dompdf->load_html($html);
$dompdf->render();
if ($stream) { //open only
$dompdf->stream($filename.".pdf");
}else{ // save to file only, your going to load the file helper for this one
write_file("pdf/$filename.pdf", $dompdf->output());
}
}
view
Code:
<html>
<head>
<title>PDF Sample</title>
[removed]
if ( isset($pdf) ) {
//This goes to the header
$font = Font_Metrics::get_font("Helvetica", "bold");
$pdf->page_text(72, 18, "Page {PAGE_NUM} of {PAGE_COUNT}", $font, 8, array(0,0,0));
//get started with the footer
// Open the object: all drawing commands will
// go to the object instead of the current page
$footer = $pdf->open_object();
$text_height = 7;
$w = $pdf->get_width();
$h = $pdf->get_height();
$y = $h - 2 * $text_height - 24;
$size = 7;
$color = array(255,255,255);
$font = Font_Metrics::get_font("Helvetica", "italic");
$text = "http://www.ikawka.com/ - ".date("F m, Y - h:i:s a");
$width = Font_Metrics::get_text_width($text, $font, $size);
// Add a logo
$img_w = 540; // 2 inches, in points
$img_h = 20; // 1 inch, in points -- change these as required
$pdf->image("images/logo.png", "png", ($w - $img_w) / 2.0, $y - $img_h, $img_w, $img_h );
$pdf->text(38, $y-16, $text, $font, $size, $color);
// Close the object (stop capture)
$pdf->close_object();
// Add the object to every page. You can
// also specify "odd" or "even"
$pdf->add_object($footer, "all");
}
[removed]
</head>
<body>
<h1>Hello Gallaxy!!!</h1>
</body>
</html>