tags:

views:

46

answers:

2

I have used following code to create a simple PDF file. It executes fine in browsers, but I am not able to get the PDF file. It gives me some output when I am running the code in the CLI; my doubt is where I specify the PDF's filename.

<?php
require('fpdf.php');

$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output();
?>

CLI output: 2 0 obj << /Type /Page /Parent 1 0 R /Contents 3 0 R >> endobj 3 0 obj << /Length 4 0 R >> stream 2.834646 0 0 2.834646 0 841.9 cm 2 J 0.2 w BT /F1 5.64 Tf ET BT 11 -16.692 Td (Hello World!) Tj ET

+2  A: 

You're probably looking for the "Content-type" and "Content-disposition" headers. The documentation for PHP's header function in its own manual give an example for the specific task you're trying to do.

Though I see why you wouldn't have any indication that the "header" function is where to look.

Jim Puls
+2  A: 

This is how you can create the file:

$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output('myFile.pdf', 'F');

Just specify file name to output function.

Sarfraz
yea, now it is creating the specified file , But when I am opening the file . It says following error The filename "myfile.pdf" indicates that this file is of type "PDF document". The contents of the file indicate that the file is of type "plain text document". If you open this file, the file might present a security risk to your system.
pavun_cool
@pavun_cool: Not sure but you should search for this error in fpdf site or google too.
Sarfraz
Actually it is creating the normal text file with pdf extension , so that it does not open correctly . Which method I should to get pdf format file.
pavun_cool