Jump to content

Recommended Posts

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! :)

Link to comment
https://forums.phpfreaks.com/topic/187238-generate-pdf/
Share on other sites

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 ;)

Link to comment
https://forums.phpfreaks.com/topic/187238-generate-pdf/#findComment-988768
Share on other sites

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 :(

Link to comment
https://forums.phpfreaks.com/topic/187238-generate-pdf/#findComment-988845
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.