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.

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

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.

This article has been dead for over six months. Start a new discussion instead.