Miko Posted January 5, 2010 Share Posted January 5, 2010 Hello, I must make a PDF with PHP. The following things should come on this PDF file: - title - description of about 4 lines - images - image name - 2 options of this image (something like check) So basically one of my users comes on my webpage (intranet) gets a result with some search requests. Then he should create a pdf file that will contain the title, description + images and the options. Creating a pdf isn't so complicated, the main issue is that the amount of images that the user requests is variable. Fortunally each image has a size of 240px width and 120px height, what I want to do is place those images next and below each other on the pdf. So basically something like this: A Title Some description Image 01 | Image 02 | Image 03 | Image 04 ImgNm 01 | ImgNm 02 | ImgNm 03 |ImgNm 04 Image 05 | Image 06 | Image 07 | Image 08 ImgNm 05 | ImgNm 06 | ImgNm 07 |ImgNm 08 And so on ... Somebody know how to do this or may know a script that can do this? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/187238-generate-pdf/ Share on other sites More sharing options...
Mchl Posted January 5, 2010 Share Posted January 5, 2010 As long as you know how to use for and while loops there's nothing complicated in that. As a primer you might want to write a code that will write image names just like you did above. Then just replace part responsible for text with code that will insert image Quote Link to comment https://forums.phpfreaks.com/topic/187238-generate-pdf/#findComment-988768 Share on other sites More sharing options...
Miko Posted January 5, 2010 Author Share Posted January 5, 2010 So bassicaly I can write loop in loop so that I can position my images and image names? Quote Link to comment https://forums.phpfreaks.com/topic/187238-generate-pdf/#findComment-988774 Share on other sites More sharing options...
Mchl Posted January 5, 2010 Share Posted January 5, 2010 That's how it's usually done Quote Link to comment https://forums.phpfreaks.com/topic/187238-generate-pdf/#findComment-988778 Share on other sites More sharing options...
Miko Posted January 5, 2010 Author Share Posted January 5, 2010 okay thanks! I know what to do now Quote Link to comment https://forums.phpfreaks.com/topic/187238-generate-pdf/#findComment-988784 Share on other sites More sharing options...
Miko Posted January 5, 2010 Author Share Posted January 5, 2010 Okay, I've been working on this one now and I'm having allready an error Fatal error: Uncaught exception 'PDFlibException' with message 'String parameter 'type' has bad value 'jpg'' in C:\xampp\htdocs\control_signatures\pdf.php:30 Stack trace: #0 C:\xampp\htdocs\control_signatures\pdf.php(30): pdf_open_image_file(Resource id #4, 'jpg', '001-STRUVAY.jpg', 'page', 0) #1 {main} thrown in C:\xampp\htdocs\control_signatures\pdf.php on line 30 Here's the code <?php $dir = "./0532/20091022/T301/"; $open = opendir("./0532/20091022/T301/"); $result = glob("./0532/20091022/T301/*.jpg"); // Create the PDF object $mypdf = PDF_new(); // Open / create PDF PDF_open_file($mypdf, ""); // Begin of page PDF_begin_page($mypdf, 595, 842); $myfont = PDF_findfont($mypdf, "Times-Roman", "host", 0); PDF_setfont($mypdf, $myfont, 10); // Show text for($i=0; $i < count($result); $i++){ $source = $result[$i]; $name = basename($source, ".jpg"); $getSize = getimagesize($dir.$name. ".jpg"); $width = $getSize[0]; $height = $getSize[1]; $myimage = PDF_open_image_file($mypdf, "jpg", "001-STRUVAY.jpg", "page", $i); PDF_place_image($mypdf, $myimage); PDF_close_image($mypdf, $myimage); } PDF_show_xy($mypdf, "SAMPLE PDF", 50, 750); PDF_show_xy($mypdf, "Made by Avril", 50, 730); // End of page PDF_end_page($mypdf); // Close / delete PDF PDF_close($mypdf); $mybuf = PDF_get_buffer($mypdf); $mylen = strlen($mybuf); header("Content-type: application/pdf"); header("Content-Length: $mylen"); header("Content-Disposition: inline; filename=signatures$dir.pdf"); print $mybuf; PDF_delete($mypdf); ?> Don't know what I'm doing wrong here Quote Link to comment https://forums.phpfreaks.com/topic/187238-generate-pdf/#findComment-988845 Share on other sites More sharing options...
Mchl Posted January 5, 2010 Share Posted January 5, 2010 The message is pretty clear. Second parameter for pdf_open_image_file() can not have value 'jpg'. Don't ask me what it's supposed to be. I've never worked with this lib. Quote Link to comment https://forums.phpfreaks.com/topic/187238-generate-pdf/#findComment-988904 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.