Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamically create a PDF with a background image

Tags:

php

pdf

I'm trying to dynamically create a PDF (on the server) with some text on top of a pre-defined background image. I'm using PHP and I can't seem to find anyway to do this.

I've looked into http://www.fpdf.org/ and a bunch of other options.

I'm not opposed to using Flash either if it will do the trick.

Does anyone have any ideas on how to get this to work?

like image 802
Daelan Avatar asked Feb 15 '11 16:02

Daelan


People also ask

How do I add a background image in Fpdf?

With FPDF you can do it like this: $fpdf = new FPDF(); $fpdf->AddPage(); $fpdf->Image('background-image. png', 0, 0, $fpdf->w, $fpdf->h); $fpdf->Output();

How do I add a background image in Tcpdf?

$img_file = './certbg/cs. jpg'; (A) In order to display the background image properly, we have to disable auto-page-break, set the background and then restore the page break afterward - all to be done in the custom header.


2 Answers

With FPDF you can do it like this:

$fpdf = new FPDF();
$fpdf->AddPage();
$fpdf->Image('background-image.png', 0, 0, $fpdf->w, $fpdf->h);
$fpdf->Output();

Old question I know, but this might help someone.

like image 86
Sam Avatar answered Sep 18 '22 17:09

Sam


You should take a look at this class, I really love it. It renders HTML to PDF, and if you define a Background-Image with CSS it will be in the created PDF.

like image 30
Tokk Avatar answered Sep 20 '22 17:09

Tokk