Rajul
Rajul

Reputation: 103

DOMPDF is not producing correct output

DOMPDF is producing only html path in pdf file instead of content at html path.

include_once('dompdf/dompdf_config.inc.php'); 
$html= $this->load->view('view_pdf');
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->set_paper("a4", "landscape" ); 

$dompdf->render();
$dompdf->stream("my_pdf.pdf", array("Attachment" => 0));   

If anybody have any idea please give here.

Upvotes: 0

Views: 1520

Answers (2)

BrianS
BrianS

Reputation: 13914

From the codeigniter docs:

Returning views as data

There is a third optional parameter lets you change the behavior of the function so that it returns data as a string rather than sending it to your browser. This can be useful if you want to process the data in some way. If you set the parameter to true (boolean) it will return data. The default behavior is false, which sends it to your browser. Remember to assign it to a variable if you want the data returned:

$string = $this->load->view('myfile', '', true);

So your code should be:

include_once('dompdf/dompdf_config.inc.php');
$html= $this->load->view('view_pdf','',true);
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->set_paper("a4", "landscape" );

$dompdf->render();
$dompdf->stream("my_pdf.pdf", array("Attachment" => 0));

Upvotes: 2

Mudshark
Mudshark

Reputation: 3253

You need the content of view_pdf to load as a string into $html:

$html = $this->load->view('view_pdf', '', true);

Upvotes: 2

Related Questions