FPDF smooth drop shadow support

After searching for a way to create smooth drop-shadows for Rect elements in FPDF and experimenting with various gradients i could not come up with a satisfying result. So i inspected some PDFs created from Inkscape and Adobe Illustrator and found out that those nice, smooth drop shadows are actually bitmaps rendered & placed behind the particular boxes or elements.

So I am using GD Lib and ImageMagick to do the same:

  • Create a black box, the same width/height ratios as the box to be drawn.
  • Save this as a PNG file, with alpha transparency turned on.
  • Use ImageMagick to blur the image.
  • Put the image on the PDF.
  • Draw the Rect over it.
  • Success!

I know, this is a very crude, slow & cumbersome way to do this, but at least it works reliably. I also write this blog posting to give and ask for some suggestions how this might be done better. Please contact me if you know how.

I created a new PHP-Class, which may be downloaded here.

Usage:

require("rect_shadow.php");

$pdf = new PDF_RectShadow();
$pdf->AddPage();
$pdf->SetLineWidth(0.008);
$pdf->SetFillColor(255,255,255);
$pdf->RectShadow(10,80,120,50,"DF");
$pdf->Output();

This produces a Rect like this:

shadow

An PDF-example can be seen here.

blogroll

social