• Holiday Schedule

    Your code gophers will be away for the next couple of weeks so support will be sporadic. We should be fully back online by the end of September.

  • A new version of Full Calendar is now available.

    See the details here

Solved PDF, total page count overlaid

elmarra

Member
Hi everyone.
I inserted the script into my custom template (bootstrap copy) to display the number of pages with the total pages.
But I have a strange effect
On the first and subsequent pages, page 1 of 5 is shown with all page numbers superimposed.
Page 2 of 5
and so on.
The numbers on the left then the current page is displayed correctly except the number on the right.
Until on the last page it is displayed correctly
See image
What have I done:
I inserted the script in the default.php file below the line:
defined('_JEXEC') or die('Restricted access');
Code:
?>
<div id="footdompdf">
    <script type="text/php">

if ( isset($pdf) ) {

  $size = 6;
  $color = array(0,0,0);
  if (class_exists('Font_Metrics')) {
    $font = Font_Metrics::get_font("helvetica");
    $text_height = Font_Metrics::get_font_height($font, $size);
    $width = Font_Metrics::get_text_width("Page 1 of 2", $font, $size);
  } elseif (class_exists('Dompdf\\FontMetrics')) {
    $font = $fontMetrics->getFont("helvetica");
    $text_height = $fontMetrics->getFontHeight($font, $size);
    $width = $fontMetrics->getTextWidth("Page 1 of 2", $font, $size);
  }

  $foot = $pdf->open_object();
 
  $w = $pdf->get_width();
  $h = $pdf->get_height();

  // Draw a line along the bottom
  $y = $h - $text_height - 24;
  $pdf->line(16, $y, $w - 16, $y, $color, 0.5);

  $pdf->close_object();
  $pdf->add_object($foot, "all");

  $text = "Pagina {PAGE_NUM} di {PAGE_COUNT}"; 

  // Center the text
  $pdf->page_text($w / 2 - $width / 2, $y, $text, $font, $size, $color);
 
}
</script>

</div>

In the css_custom file I adjusted this:
Code:
body {margin-top:1.5em;margin-bottom:1.5em}


#footdompdf {

    display:block;

    position: fixed;

    bottom: 0px;

    width:100%;

    height: 1.1em;
but I can't understand the problem. I also tried changing various dompdf versions.
I obviously activated php in the pdf by adding this in the pdf.php file

$options->set("isPhpEnabled", true);
from an online search I found this which is the same problem.
But I didn't understand how to correct the same in the template.
stackoverflow fix

Has anyone had the same problem? or do you know how to fix this?
In fabrik 3 it worked for me.
Thank you
 

Attachments

  • pdf number.jpg
    pdf number.jpg
    16.6 KB · Views: 50
Hello everyone, I was finally able to solve the problem and get the page count correct.
Instead of inserting the footer <div> into default.php immediately below:
Code:
defined('_JEXEC') or die('Restricted access');
under:
Code:
<?php
echo $this->table->outro;
if ($pageClass !== '') :
    echo '</div>';
endif;
?>

by entering:

Code:
<div id="footdompdf">
  <script type="text/php">
if ( isset($pdf) ) {
  $size = 8;
  $color = array(0,0,0);
  if (class_exists('Font_Metrics')) {
    $font = Font_Metrics::get_font("helvetica");
    $text_height = Font_Metrics::get_font_height($font, $size);
    $width = Font_Metrics::get_text_width("Page 1 of 2", $font, $size);
  } elseif (class_exists('Dompdf\\FontMetrics')) {
    $font = $fontMetrics->getFont("helvetica");
    $text_height = $fontMetrics->getFontHeight($font, $size);
    $width = $fontMetrics->getTextWidth("Page 1 of 2", $font, $size);
  }
  $pdf->page_script(function ($pageNumber, $pageCount, $pdf, $fontMetrics) use ($font, $text_height, $width, $size, $color) {
    $w = $pdf->get_width();
    $h = $pdf->get_height();
    // Draw a line along the bottom
    $y = $h - $text_height - 24;
    $pdf->line(16, $y, $w - 16, $y, $color, 0.5);
    $text = "Pagina $pageNumber di $pageCount";
    // Center the text
    $pdf->text($w / 2 - $width / 2, $y, $text, $font, $size, $color);
  });
}
</script>
</div>

and in the custom.css file:

Code:
#footdompdf {

    display:block;

 

    bottom: 0px;

    width:100%;

    height: 1.1em;


}

#footdompdf .pagenum { position:absolute;

    right: 20px;}

#footdompdf .pagenum:after {

  content: counter(page) ; //This is including the page number at bottom right

}

And I finally got the page count displayed correctly without overlays
 

Attachments

  • pdf correct.jpg
    pdf correct.jpg
    10.4 KB · Views: 26
Back
Top