Good PDF Tutorial?

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
JasonTC
Forum Commoner
Posts: 92
Joined: Wed Nov 02, 2005 11:05 am
Location: Grand Rapids, MI

Good PDF Tutorial?

Post by JasonTC »

I've found a couple, but apparently I'm missing some key concept or something. I tried this incredibly simple script, for the most part copied and pasted from the php.net site:

Code: Select all

<?php
$pdf = pdf_new();
pdf_open_file($pdf, "test.pdf");
pdf_set_info($pdf, "Author", "Uwe Steinmann");
pdf_set_info($pdf, "Title", "Test for PHP wrapper of PDFlib 2.0");
pdf_set_info($pdf, "Creator", "See Author");
pdf_set_info($pdf, "Subject", "Testing");
pdf_begin_page($pdf, 595, 842);
pdf_add_outline($pdf, "Page 1");
$font = pdf_findfont($pdf, "Times-Roman", "host", 0);
pdf_setfont($pdf, $font, 10);
pdf_set_value($pdf, "textrendering", 1);
pdf_show_xy($pdf, "Times Roman outlined", 50, 750);
pdf_moveto($pdf, 50, 740);
pdf_lineto($pdf, 330, 740);
pdf_stroke($pdf);
pdf_end_page($pdf);
pdf_close($pdf);
//pdf_delete($pdf);
?>
It creates no file called "test.pdf". Creates no file at all. What could I have done wrong? I tried it with the pdf_delete both commented and uncommented; I thought that might make a difference, but it didn't. If someone could point me in the direction of a "PDF Tutorial for First Graders", that would be great. I haven't found anything that really seems to start from the very basic building blocks of a PDF file yet.

Thanks,
Jason
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

First of all, do you have the PDFlib library installed?
JasonTC
Forum Commoner
Posts: 92
Joined: Wed Nov 02, 2005 11:05 am
Location: Grand Rapids, MI

Post by JasonTC »

Apparently. Here's my deal: I just got hired at a company whose former programmer left and cannot be contacted in any way. I'm left to decipher the spaghetti code he left behind. One script he wrote is supposed to generated PDF files, and it does...sometimes. So since it works sometimes, I'm guessing the PDFlib is installed.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

First thing to do:

Code: Select all

ini_set('display_errors', TRUE);
ini_set('error_reporting', E_ALL);
If the code is running on a production server you better log it to a file instead of displaying though ;)
JasonTC
Forum Commoner
Posts: 92
Joined: Wed Nov 02, 2005 11:05 am
Location: Grand Rapids, MI

Post by JasonTC »

Thanks, but this yields no errors.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

I've tested on Apache/2.0.54 (Win32) mod_ssl/2.0.54 OpenSSL/0.9.8 PHP/5.0.5 Server at localhost Port 80

If i use a relative path in pdf_open, eg: "test.pdf" there is no file created...
If i use an absoltue path it does work, eg: pdf_open_file($pdf, "f:/websites/localhost/test.pdf");
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

I just ran a search on my filesystem for test.pdf...
Apparently there was a test.pdf generated in c:/program files/apache group/apache2. I've got a feeling there is a little "bug/feature" in the win32 version of that extension :)
Post Reply