Reputation: 1
i have a website in that user needs to take report as pdf[in code] , i tried the following code , nut it displayes some special characters , Please help me to fix this issue.
<?php
require('fpdf.php');
//create a FPDF object
$pdf=new FPDF();
//set document properties
$pdf->SetAuthor('Lana Kovacevic');
$pdf->SetTitle('FPDF tutorial');
//set font for the entire document
$pdf->SetFont('Helvetica','B',20);
$pdf->SetTextColor(50,60,100);
//set up a page
$pdf->AddPage('P');
$pdf->SetDisplayMode(real,'default');
//insert an image and make it a link
$pdf->Image('logo.png',10,20,33,0,' ','http://www.fpdf.org/');
//display the title with a border around it
$pdf->SetXY(50,20);
$pdf->SetDrawColor(50,60,100);
$pdf->Cell(100,10,'FPDF Tutorial',1,0,'C',0);
//Set x and y position for the main text, reduce font size and write content
$pdf->SetXY (10,50);
$pdf->SetFontSize(10);
$pdf->Write(5,'Congratulations! You have generated a PDF.');
//Output the document
$pdf->Output('example1.pdf','I');
?>
i got the output as below g endstream endobj 1 0 obj <> endobj 5 0 obj <> endobj 2 0 obj << /ProcSet [/PDF /Text /ImageB /ImageC /ImageI] /Font << /F1 5 0 R >> /XObject << >> >> endobj 6 0 obj << /Producer (FPDF 1.6) /Title (FPDF tutorial) /Author (Lana Kovacevic) /CreationDate (D:20100215182640) >> endobj 7 0 obj << /Type /Catalog /Pages 1 0 R /OpenAction [3 0 R /FitH null] /PageLayout /OneColumn >> endobj xref 0 8 0000000000 65535 f 0000000407 00000 n 0000000595 00000 n 0000000204 00000 n 0000000282 00000 n 0000000494 00000 n 0000000699 00000 n 0000000822 00000 n trailer << /Size 8 /Root 7 0 R /Info 6 0 R >> startxref 925 %%EOF
Upvotes: 0
Views: 3793
Reputation: 123563
Output(..., 'I')
should handle HTTP headers for you -- unless you're using PHP-CLI.
FDPF::Output
depends on php_sapi_name
not returning 'cli'
when the destination is 'I'
. It still echoes the buffer, but the proper headers aren't specified.
If you're using FPDF 1.6, see lines 1010-1027, esp. 1014, of fpdf.php
.
Upvotes: 0
Reputation: 3891
Most likely you just need to specify the content-type as PDF so your browser will know how to handle the file.
header('Content-type: application/pdf');
Be sure to call that before you call $pdf->Output('example1.pdf','I');
This issue could also be caused by having the correct browser information being sent but not having an application that understands PDFs installed.
Upvotes: 1
Reputation: 2472
$pdf->Output('example1.pdf','I');
Will save pdf to file. If you want to show pdf directly in browser (or open download dialog, it depends on browser and plugins), you should do:
$pdf->Output();
Upvotes: 0