Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PDF Creation Doesn't seem to work at all 1

Status
Not open for further replies.

SPYDERIX

Technical User
Joined
Jan 11, 2002
Messages
1,899
Location
CA
Hi,

I am trying to create a dynamic pdf using php but can't seem to get it to work. I was looking at: PHP.net and tried an example but it's not ouputting a pdf just the code you would see if you opened a pdf in notepad.

The code I'm using is:

Code:
<?php 
$pdf = pdf_new(); 

pdf_open_file($pdf); 
pdf_begin_page($pdf, 595, 842); 
pdf_set_font($pdf, "Times-Roman", 30, "host"); 
pdf_set_value($pdf, "textrendering", 1); 
pdf_show_xy($pdf, "A PDF document created in memory!", 50, 750); 
pdf_end_page($pdf); 
pdf_close($pdf); 

$data = pdf_get_buffer($pdf); 

header("Content-type: application/pdf"); 
header("Content-disposition: inline; filename=test.pdf"); 
header("Content-length: " . strlen($data)); 

echo $data; 
?>

I am running php on apache under win32 and have uncommented the apporpriate line in the php.ini but when I call the page with that code I get the following output:

Code:
%PDF-1.3 %äãÏÒ 5 0 obj <> stream xœs áÒw3P06PIã2T)@h¨`j `Ä!¹\ I. G…7…”üäÒÜÔ¼…ä¢ÔÄ’Ô…Ì<…ÜÔÜü¢JE͐,.×.!gˆendstream endobj 6 0 obj 84 endobj 4 0 obj <> endobj 8 0 obj <> >> endobj 3 0 obj <> endobj 7 0 obj <> endobj 1 0 obj <> endobj 2 0 obj <> endobj xref 0 9 0000000000 65535 f 0000000537 00000 n 0000000591 00000 n 0000000351 00000 n 0000000188 00000 n 0000000015 00000 n 0000000170 00000 n 0000000443 00000 n 0000000291 00000 n trailer <<1DD0F4665D017D8251424299BB688F26>] >> startxref 638 %%EOF

What do I do to get this to return a pdf file? And one other question is: Is it possible to open a pre-made pdf template and simply insert variables into certain parts and then output a new dynamic pdf with the data in it?

Thanks alot!

NATE


mainframe.gif


Got a question? Search G O O G L E for links to the fastest answers: www.google.com
 
That looks like the beginning of a PDF file to me.

I'm wondering what would happen if you were to change the "Content-disposition:" line from "inline" to "attachment"

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
sleipnir214,

Ok that has finally created the first pdf. But that created a dialog box to open and ask if I wanted to save or open it. I want it to display in the browser though like any other pdf would do.

Any ideas?

Also is it possible to open a premade pdf and insert stuff into it and then output the new version without harming the blank template?

Thanks!

NATE


mainframe.gif


Got a question? Search G O O G L E for links to the fastest answers: www.google.com
 
How your browser opens the file is probably dependent on the headers sent by the server. I use Opera, so my browser doesn't have a choice.

You're probably going to have fetch a small PDF by hand from your server using telnet to figure out what headers you need to set.


Using a PDF as a template is a PDI function. I've never done it -- but I recommend that you start looking in the PHP online manual at those PDF functions that have "pdi" in their names.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top