Generating a PDF file through PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
weasel512
Forum Newbie
Posts: 5
Joined: Wed Sep 02, 2009 7:58 am

Generating a PDF file through PHP

Post by weasel512 »

G'day,

I have a problem, which i really dont know much about. I'm just testing the waters here, and looking at how i can export output from php to a PDF file.

I found one tutorial, but i am getting a confusing error message.

Code: Select all

// create handle for new PDF document
    $pdf = pdf_new();
    
    // open a file
    pdf_open_file($pdf, "philosophy.pdf");
    
    // start a new page (A4)
    pdf_begin_page($pdf, 595, 842);
    
    // get and use a font object
    $arial = pdf_findfont($pdf, "Courier", "host", 1);
    pdf_setfont($pdf, $arial, 10);
    
    // print text
    pdf_show_xy($pdf, "There are more things in heaven and earth, Horatio,",50, 750); 
    pdf_show_xy($pdf, "than are dreamt of in your philosophy", 50,730);
    
    // end page
    pdf_end_page($pdf);
    
    // close and save file
    pdf_close($pdf);
The error message that i am getting is:
Fatal error: Uncaught exception 'PDFlibException' with message 'No file specified with outline data for font 'Courier'' in C:\wamp\www\Creating PDFs\pdf.php:20 Stack trace: #0 C:\wamp\www\Creating PDFs\pdf.php(20): pdf_findfont(Resource id #2, 'Courier', 'host', 1) #1 {main} thrown in C:\wamp\www\Creating PDFs\pdf.php on line 20
If someone could please help me to understand, it would be much appreciated!


Cheers
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: Generating a PDF file through PHP

Post by Darhazer »

There was topic about PDF generation, it does not cover those functions, as far as I remember, but it have solutions you may find interesting.
weasel512
Forum Newbie
Posts: 5
Joined: Wed Sep 02, 2009 7:58 am

Re: Generating a PDF file through PHP

Post by weasel512 »

I'm using the standard PDFLib thats supported by php4 and above..
To be honest, i'd prefer to use that, but the link you provided has some v. good points.

thx man.


If anyone knows how to effectively use the pdfLib, i'd LOVE to hear from you !



Cheers
Post Reply