getting a page footer in a pdf?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jamie
    Senior Member
    • Aug 2025
    • 215

    #16
    i have finally got it working. Should anyone else need to enable it, here is how i did it first in vendor/dompdf/dompdf/src/Options.php set
    PHP Code:
    private $isPhpEnabled true
    Then, create a template helper with the following code

    PHP Code:
    <?php
    namespace Espo\Custom\TemplateHelpers;
    use 
    Espo\Core\Htmlizer\Helper;
    use 
    Espo\Core\Htmlizer\Helper\Data;
    use 
    Espo\Core\Htmlizer\Helper\Result;
    class 
    pdfPageNumbers implements Helper
    {
    public function 
    __construct() {}
    public function 
    render(Data $data): Result
    {
    $html '
    <div class="footer" style="position: fixed; bottom: 10px; width: 100%; text-align: right; font-size: 6px;">
    <script type="text/php">
    if (isset($pdf)) {
    // Set position on page (x = right margin, y = distance from top)
    $x = 560;
    $y = 825;
    $text = "{PAGE_NUM} / {PAGE_COUNT}";
    $font = $fontMetrics->get_font("Open Sans", "normal");
    // Render page numbers on every page
    $pdf->page_text($x, $y, $text, $font, 6, [0,0,0], null, "right");
    }
    </script>
    </div>
    '
    ;
    return 
    Result::createSafeString($html);
    }
    }
    i don't think the $font does anything

    Footer class is set in my stylesheet

    .footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 0.2em 2em;
    font-size: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: #ececec;
    color: #000;
    z-index: -1;
    }

    -----

    Warning. Read the comment below.
    Last edited by yuri; Yesterday, 08:49 AM.

    Comment


    • yuri
      yuri commented
      Editing a comment
      Warning to whomever read. This solution introduces a critical security vulnerability to your system. Anyone with edit access to templates can do whatever they want with the system, including extracting confidential data.
      Last edited by yuri; Yesterday, 08:50 AM.
  • yuri
    EspoCRM product developer
    • Mar 2014
    • 9592

    #17
    I tested conditional logic in the footer. It works for me on multiple pages.

    Code:
    <div style="width: 100%; text-align: center;">
      <span>{pageNumber}&nbsp;</span>
      <span x-if="{{equal type 'Invoice'}}">Invoice</span>
      <span x-if="{{equal type 'Debit Note'}}">Debit Note</span>
    </div>

    ---

    So Dompdf already supports total number of pages?
    If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

    Comment


    • yuri
      yuri commented
      Editing a comment
      This topic was about dynamic footer. I see there's no any issues with dynamic footers. The claims that it's extremely difficult turned out not to be confirmed.

    • jamie
      jamie commented
      Editing a comment
      i dont' see where your showing the total number of pages? Did you have to enable anything to get the x-if working? That would be very useful in the future
  • jamie
    Senior Member
    • Aug 2025
    • 215

    #18
    Originally posted by yuri
    > I couldn't use variables in it either

    What are variables? Placeholders? They work fine for me. Placeholders are printed in the footer on the second page.

    for example {{cCompany.footer}} i tried that and it didn't work i think i've got to stick with template helpers for now, as I finally have page numbers working

    Comment

    • jamie
      Senior Member
      • Aug 2025
      • 215

      #19
      Originally posted by ThomasB
      Here is the discussion about it: https://github.com/dompdf/dompdf/iss...ment-740015376

      Not sure if the workaround still works or how to use it.

      There are not many free PHP PDF libaries around.TCPDF is in maintance mode and has only a few new commits. There is a successor available called tc-lib-pdf.
      But it has only a stable release recently. It's still work in progress and I don't know if its on par with tcpdf yet and what are the advantages or disadvantages of the new version.
      makes you wish darn adobe would make one, though i won't hold my breath for that. if you see the second page i did finnally get it all working with dompdf and detailed how i did it

      Comment

      Working...