Reputation: 3
I will try to generate pdf file using tcpdf. but there are not generate proper out. There are generate some binary code like this.
My Controller Code
$MYPDF_OBJ = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$MYPDF_OBJ->CoverPage($this->BasePath.'images/LeadImages/Arizona-Property-Investment-3-7087141.jpg');
$addCmdDetails = $MYPDF_OBJ->addCmdDetails();
$MYPDF_OBJ->MAP_OF_ALL_LISTINGS($POST['MAP_OF_ALL_LISTINGS']);
$comparable_array = array();
$comparable_array['comparable']['headers'] = array('Address','Beds','Baths','YrBlt','SqFt','Lot Size','Price','Sold Date');
foreach($array as $MyArray){
$comparable_array['comparable']['data'] = $MyArray;
$MYPDF_OBJ->compatableProperties($comparable_array);
}
$MYPDF_OBJ->propertyDetails($getData);
//$MYPDF_OBJ->Output($this->BasePath.'\images\pdf\file.pdf', 'F');
$MYPDF_OBJ->Output('yourfilename.pdf', 'D');
//echo $pdf->Output(); exit;
Upvotes: 0
Views: 61
Reputation: 21483
what do you mean? PDF files are binary data. that looks like the binary data of a PDF file to me, but interpreted as text. the content-type
http header tells your browser what the output is, and how to interpret it. i bet your server told the browser Content-Type: text/html
, and then just outputted the binary data of a PDF file. so the browser, being told that it was html, tried to render it as such, and because the PDF format and the HTML format are completely incompatible, you got that garbage rendering. to tell the browser this is a PDF file, treat it as such
, send the HTTP header Content-Type: application/pdf
to set a header in PHP, use the header() function, eg
header("Content-Type: application/pdf");
Upvotes: 1