Headers - Text over image!

306 views
Skip to first unread message

John Kesterton

unread,
Jul 11, 2011, 11:16:16 AM7/11/11
to dompdf
Good Afternoon,

I am trying to render a header image in dompdf which is working fine.
I would now like to add some text over the image however it always
renders underneath!?!

My code is as follows.....Any suggestions would be greatly apreciated.

<script type="text/php">
if( isset($pdf) ) {
//header and footer
$obj = $pdf->open_object();

//header text
$font = Font_Metrics::get_font("Helvetica");
$fontsize = 10;
$fontcolor = array(0.4,0.4,0.4);

$pdf->page_text($pdf->get_width()-100, $pdf->get_height()-40,
"Page {PAGE_NUM} of {PAGE_COUNT}", $font, $fontsize, $fontcolor);

//header image
$image = './images/reportheader.png';
$points = 3142 * 72 / 96;
$points2 = 229 * 72 / 96;
$pdf->page_text(60, 46, "Title Text", $font, $fontsize, $fontcolor);
$pdf->image($image, 'png', 44, 36,754,54);
$pdf->close_object();
$pdf->add_object($obj, 'all');
}
</script>

BrianS

unread,
Jul 11, 2011, 2:10:43 PM7/11/11
to dom...@googlegroups.com
On Monday, July 11, 2011 11:16:16 AM UTC-4, John Kesterton wrote:
I am trying to render a header image in dompdf which is working fine.
I would now like to add some text over the image however it always
renders underneath!?!

My code is as follows.....Any suggestions would be greatly apreciated.

The core of your problem is that creating an object, adding text/images, and then adding that object to a PDF works separately from the page_text() method. You should rewrite your code as follows to make that clear:

<script type="text/php">
if( isset($pdf) ) {
  // global page text

  $font = Font_Metrics::get_font("Helvetica");
  $fontsize = 10;
  $fontcolor = array(0.4,0.4,0.4);
  $pdf->page_text($pdf->get_width()-100, $pdf->get_height()-40, "Page {PAGE_NUM} of {PAGE_COUNT}", $font, $fontsize, $fontcolor);
  $pdf->page_text(60, 46, "Title Text", $font, $fontsize, $fontcolor);

  //header image
  $obj = $pdf->open_object();
  $image = './images/reportheader.png';
  $points = 3142 * 72 / 96;
  $points2 = 229 * 72 / 96;
  $pdf->image($image, 'png', 44, 36,754,54);
  $pdf->close_object();
  $pdf->add_object($obj, 'all');
}
</script>

I'd have to go back and review the source to confirm, but the order which page_text() content and header/footer objects are added will affect which appears on top of the other. page_text() may very well be rendered first and so be layered underneath the header/footer objects.

Unfortunately, the placeholder text can not be used in $pdf->text() which is what you would use to add text to a header/footer object.

In the 0.6.0 release, if you don't need the total number of pages you can rewrite your header/footer entirely in HTML. (There is a way to output the current page number.)
Reply all
Reply to author
Forward
0 new messages