The image is of fixed size and I want to update that image for every user like updating the username and date etc. Then I want to convert that image to PDF with the A4 printing size. How can this be achieved in PHP/Laravel.
-
See my answer below. It would allow you to create it in html and convert to PDF like you mentioned. – andrew-caulfield Apr 27 '16 at 22:27
5 Answers
I was able to achieve this by first creating a responsive html and then converting that html to PDF.

- 363
- 3
- 13
There are various libraries available for pdf generation for PHP.
e.g. there is MPDF which allows you to create a html and pass it to the library and it converts it into pdf.
You can also check a comparison of various other generators here: Which one is the best PDF-API for PHP?

- 1
- 1

- 3,715
- 2
- 24
- 37
-
Thanks Nabeel but I know about the libraries. The main challenge here is to edit the image and I think there are libraries available for that too. The other thing I am thinking of creating a responsive html and then convert to PDF. – Abdul Jamil Apr 27 '16 at 05:49
-
to add text to image (without removing anything) you can use that image as a background and add the text as html on it – Nabeel Khan Apr 27 '16 at 05:52
-
You can look into the php_GD
library and in particular, the imagettftext
. For image to PDF conversions, try using ImageMagick
You can add text to an image with Intervention using text()
method:
$img = Image::make('public/foo.jpg');
$img->text('The quick brown fox jumps over the lazy dog.', 120, 100);
Then, you could just create simple HTML wrap for an image to convert it to PDF with any appropriate tool or package:
$pdf = PDF::loadView('view.with.image', $data);
return $pdf->download('image.pdf');
Or, you could convert image to PDF using ImageMagick (CLI example):
convert image.jpg image.pdf

- 158,981
- 26
- 290
- 279
I would definitely take a look at using Snappy by barryvdh
One you have the package pulled in through composer. It's as simple as using the wrapper the package provides.
$snappy = \App::make('snappy.pdf');
$snappy->generateFromHtml("Link to your image here", '/tmp/NameofYourPDF.pdf');
This example is here is then saving it to the /tmp
folder on the server.
Have used this in the past and it makes it very straight forward to use.
You need to have wkhtmltopdf/wkhtmltoimage installed. You can download wkhtmltopdf from http://wkhtmltopdf.org/downloads.html

- 2,060
- 2
- 23
- 24