Hello Coders, I am trying to generate the pdf file using php, I successfully generated the php file and then I tried to insert an image in the pdf file using php and got this error, I have the image and file in the same directory and don't know why the code is failing please help me.

Error:
Fatal error: Uncaught exception 'PDFlibException' with message 'Couldn't open JPEG file 'test.jpg' for reading (file not found)' in C:\xampplite\htdocs\score\scorepass\pdfgeneration.php:13 Stack trace: #0 C:\xampplite\htdocs\score\scorepass\pdfgeneration.php(13): pdf_open_image_file(Resource id #5, 'jpeg', 'test.jpg', '', 0) #1 {main} thrown in C:\xampplite\htdocs\score\scorepass\pdfgeneration.php on line 13

<?php
$pdf = pdf_new();
pdf_open_file($pdf,"c:\scorefm.pdf");
pdf_set_info($pdf, "Author", "Author");
pdf_set_info($pdf, "Title", "Title");
pdf_set_info($pdf, "Creator", "Author");
pdf_set_info($pdf, "Subject", "Coupoun");
pdf_begin_page($pdf, 504, 264);	
$image = pdf_open_image_file($pdf, "jpeg", "test.jpg", "", 0);
pdf_place_image($pdf, $image, 504, 504, 1); 
$font = pdf_load_font($pdf, "Courier","iso8859-1", "");
pdf_setfont($pdf, $font, 10);
pdf_end_page($pdf);
pdf_close($pdf);
?>

Please Please help me.

Recommended Answers

All 7 Replies

Your problem is just as the exception describes, the file doesn't exist. Try giving an absolute path to the image.

Your problem is just as the exception describes, the file doesn't exist. Try giving an absolute path to the image.

It means that I should give a path like this http://www.site.com/img.jpg
??

No, it means you should give it a path like this C:\somedirectory\img.jpg

Thanks alot for your help, But Then how can I use it over the net. Because each user will not have that image in directory,

Thanks alot for your help, But Then how can I use it over the net. Because each user will not have that image in directory,

This is just for testing purposes, you can change it back later. If it doesn't find the file with an absolute path then there's something wrong. Also, you're already using an absolute path for the PDF file.

Make sure that ur web server support this library

Call to undefined function pdf_new()

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.