DOMPDF - Get the last pdf position

Is it possible to get the y-position of the last HTML element when rendering an HTML document to PDF using Dompdf?

I need to insert an item after PDF rendering at the end of my document (digital signature fields) ...

EDIT: As described in the DOMPDF Github https://github.com/dompdf/dompdf/issues/1424 , you need to create a callback for the "end_frame" event:

$dompdf = new Dompdf();
$dompdf->setCallbacks(
  array(
    'myCallbacks' => array(
      'event' => 'end_frame', 'f' => function ($infos) {
        $frame = $infos["frame"];
        // elements positions
        $GLOBALS["array_coord"][] = $frame->get_padding_box();
        // last page number
        $counter_frame = $frame->lookup_counter_frame('page');
        $page_number = $counter_frame->counter_value('page');
      }
    )
  )
);

      

and then after rendering:

$dompdf->render();
// get the last y position in the PDF
$ligne_sign = sizeof($GLOBALS["array_coord"]) - 2;
$y = $GLOBALS["array_coord"][$ligne_sign]["y"];

      

+3


source to share





All Articles