Dynamically create a PDF with a background image
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 se开发者_如何学编程em 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?
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.
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.
Another good alternative is TCPDF, it also supports (basic) HTML as output. Just look at the TCPDF Examples for a quick overview of what it can do (Example 51 might be helpful for you).
Also, dompdf.
You were thinking too hard about what you wanted to do ;) ... always start with something you're familiar with (PHP, HTML) and see if there's something that will create the desired result (PDF). For a full list of converters you could try see the community wiki List of HTML to PDF converters (it covers more than just PHP-based libraries).
You just need to re-order your code. Then your next content will automatically placed on the top of the image. example:
$fpdf = new FPDF();
$fpdf->AddPage();
// put the image in first order
$fpdf->Image('background-image.png', 0, 0, $fpdf->w, $fpdf->h);
$fpdf->cell(...);
...
...
$fpdf->Output();
精彩评论