MPDF Template please

sunnyjey

Active Member
Would appreciate if someone share PDF template based on MPDF Library for Fabrik with Header, Footer, Table, Body and Page Number.

I have searched Wiki, the PDF template available is for DomPDF which is not rendering output as intended.

Thank you in advance.
 
Yes. I have gone through it. But somehow cannot make it.

Can you give me some example to incorporate mpdf codes into the fabrik detail template ?

This is Fabrik standard detail.php template

Code:
<?php
/**
* Bootstrap Details Template
*
* @package     Joomla
* @subpackage  Fabrik
* @copyright   Copyright (C) 2005-2016  Media A-Team, Inc. - All rights reserved.
* @license     GNU/GPL http://www.gnu.org/copyleft/gpl.html
* @since       3.1
*/

// No direct access
defined('_JEXEC') or die('Restricted access');

$form = $this->form;
$model = $this->getModel();
if ($this->params->get('show_page_heading', 1)) : ?>
    <div class="componentheading<?php echo $this->params->get('pageclass_sfx')?>">
        <?php echo $this->escape($this->params->get('page_heading')); ?>
    </div>
<?php
endif;

if ($this->params->get('show-title', 1)) :?>
<div class="page-header">
    <h1><?php echo $form->label;?></h1>
</div>
<?php
endif;

echo $form->intro;
if ($this->isMambot) :
    echo '<div class="fabrikForm fabrikDetails fabrikIsMambot" id="' . $form->formid . '">';
else :
    echo '<div class="fabrikForm fabrikDetails" id="' . $form->formid . '">';
endif;
echo $this->plugintop;
echo $this->loadTemplate('buttons');
echo $this->loadTemplate('relateddata');
foreach ($this->groups as $group) :
    $this->group = $group;
    ?>

        <div class="<?php echo $group->class; ?>" id="group<?php echo $group->id;?>" style="<?php echo $group->css;?>">

        <?php
        if ($group->showLegend) :?>
            <h3 class="legend">
                <span><?php echo $group->title;?></span>
            </h3>
        <?php endif;

        if (!empty($group->intro)) : ?>
            <div class="groupintro"><?php echo $group->intro ?></div>
        <?php
        endif;

        // Load the group template - this can be :
        //  * default_group.php - standard group non-repeating rendered as an unordered list
        //  * default_repeatgroup.php - repeat group rendered as an unordered list
        //  * default_repeatgroup_table.php - repeat group rendered in a table.

        $this->elements = $group->elements;
        echo $this->loadTemplate($group->tmpl);

        if (!empty($group->outro)) : ?>
            <div class="groupoutro"><?php echo $group->outro ?></div>
        <?php
        endif;
        ?>
    </div>
<?php
endforeach;

echo $this->pluginbottom;
echo $this->loadTemplate('actions');
echo '</div>';
echo $form->outro;
echo $this->pluginend;

What code of lines and where should I add those lines to get Footer / Header / Page No ?

I tried following change to get {PAGENO} , but not working :

Code:
<?php
/**
* Bootstrap Details Template
*
* @package     Joomla
* @subpackage  Fabrik
* @copyright   Copyright (C) 2005-2016  Media A-Team, Inc. - All rights reserved.
* @license     GNU/GPL http://www.gnu.org/copyleft/gpl.html
* @since       3.1
*/

// No direct access
defined('_JEXEC') or die('Restricted access');
?>

<div id="footdompdf">
    <span class="footleft"><?php echo $this->table->label;?></span>
/*  MPDF CODES LINES */
    <span class="pagenum">Page <php echo $pageno ;?></span>
/*  MPDF CODES LINES */
</div>

<?php

$form = $this->form;
$model = $this->getModel();

/*  MPDF CODES LINES */
$mpdf = new \Mpdf\Mpdf();

// Set a simple Footer including the page number
$pageno = $mpdf->setFooter('{PAGENO}');

/*  MPDF CODES LINES */


if ($this->params->get('show_page_heading', 1)) : ?>
    <div class="componentheading<?php echo $this->params->get('pageclass_sfx')?>">
        <?php echo $this->escape($this->params->get('page_heading')); ?>
    </div>
<?php
endif;

if ($this->params->get('show-title', 1)) :?>
<div class="page-header">
    <h1><?php echo $form->label;?></h1>
</div>
<?php
endif;

echo $form->intro;
if ($this->isMambot) :
    echo '<div class="fabrikForm fabrikDetails fabrikIsMambot" id="' . $form->formid . '">';
else :
    echo '<div class="fabrikForm fabrikDetails" id="' . $form->formid . '">';
endif;
echo $this->plugintop;
echo $this->loadTemplate('buttons');
echo $this->loadTemplate('relateddata');
foreach ($this->groups as $group) :
    $this->group = $group;
    ?>

        <div class="<?php echo $group->class; ?>" id="group<?php echo $group->id;?>" style="<?php echo $group->css;?>">

        <?php
        if ($group->showLegend) :?>
            <h3 class="legend">
                <span><?php echo $group->title;?></span>
            </h3>
        <?php endif;

        if (!empty($group->intro)) : ?>
            <div class="groupintro"><?php echo $group->intro ?></div>
        <?php
        endif;

        // Load the group template - this can be :
        //  * default_group.php - standard group non-repeating rendered as an unordered list
        //  * default_repeatgroup.php - repeat group rendered as an unordered list
        //  * default_repeatgroup_table.php - repeat group rendered in a table.

        $this->elements = $group->elements;
        echo $this->loadTemplate($group->tmpl);

        if (!empty($group->outro)) : ?>
            <div class="groupoutro"><?php echo $group->outro ?></div>
        <?php
        endif;
        ?>
    </div>
<?php
endforeach;

echo $this->pluginbottom;
echo $this->loadTemplate('actions');
echo '</div>';
echo $form->outro;
echo $this->pluginend;
 
In your code a lot seems to be missing, not to mention errors such as
Code:
<php echo $pageno ;?>
where $pageno is also defined only later.

Guess you should follow the methods given in the mPDF manual completely.
There's also a section "Real life examples" including a link to a Github repository with tons of example files.
 
I have gone again through the mpdf manual and real examples, but it looks I am something missing. I have tried to output simple syntax with following code in detail.php:

Code:
<?php
/**
* Bootstrap Details Template
*
* @package     Joomla
* @subpackage  Fabrik
* @copyright   Copyright (C) 2005-2016  Media A-Team, Inc. - All rights reserved.
* @license     GNU/GPL http://www.gnu.org/copyleft/gpl.html
* @since       3.1
*/

// No direct access
defined('_JEXEC') or die('Restricted access');
?>

<?php
$mpdf = new \Mpdf\Mpdf();
$mpdf->WriteHTML('<h1>Hello world!</h1>');
$mpdf->Output();
?>

<?php
echo $this->pluginbottom;
echo '</div>';
echo $form->outro;
echo $this->pluginend;

I am not getting 'Hello world!' instead I am getting blank white PDF with '%PDF-1.4 %' at right corner end !!
 
@lousyfool Thank you once again for helping me out. PDF debugging also showing same error.

@troester Yes, I made switched to Mpdf in Fabrik options.

I'm confused whether I need to add extra codes to the custom template like:

<?php
$mpdf = new \Mpdf\Mpdf();
$mpdf->WriteHTML('<h1>blah.... blah.... </h1>');
$mpdf->Output();
?>

The reason I am asking the Mpdf is not outputting {PAGENO} , {DATE j-m-Y} neither respecting Page break CSS (page-break-inside: avoid) . Unfortunately, there is no instruction in WIKI or in Forum like domPDF to get Header / Footer / Page No.

I am not sure, but maybe we have to provide a path to load MDF composer in detail.php template :

// Require composer autoload
require_once __DIR__ . '/vendor/autoload.php';

Ref: https://mpdf.github.io/getting-started/creating-your-first-file.html
 
Last edited:
I'm confused whether I need to add extra codes to the custom template...
Just for the record, I have responded the way I did because I understood (assumed?) that you want PDF output by default, meaning no HTML page with a PDF button or so. Maybe you could confirm if I understood right, or if you want only "optional" PDF output.

Anyway, based on my understanding, I'd say you do need mPDF code in your template files... though Troester may well prove me wrong on this, and then I shall stand corrected! ;)
 
I'd say you do need mPDF code in your template files... though Troester may well prove me wrong on this, and then I shall stand corrected!

Yes. I do feel same, some codes from mPDF are required to generate mPDF Specific syntax like {PAGENO} , {DATE j-m-Y} and Page break CSS (page-break-inside: avoid) class. I have been trying to find those codes. I hope @cheesegrits or @skyrun can help.

I can see @skyrun is extensively using mPDF for his project. Ref:
http://fabrikar.com/forums/index.ph...onthly-yearly-sales-report.34615/#post-175271

As per template provided by @skyrun on above post, I tried to use mPDF codes but they looks outdated.

Hope to get input from Hugh /Barry.
 
Some remarks:
The thread of @skyrun is from 2013, long time before the mPDF lib was added to Fabrik (so he was creating a custom list template using his own mPDF-lib - but NOT a Fabrik-PDF template for Fabrik PDF lib set to mPDF).

Fabrik PDF button creates the HTML+CSS defined by your PDF template (as you see it with PDF debug = Yes) and passes it to the selected PDF engine.

Obviously mPDF doesn't 'understand' the HTML/CSS from the example
http://fabrikar.com/forums/index.ph...mplate-with-page-header-footer-and-pagenumber

It's creating header and footer only on the first page and it seems it doesn't understand any CSS like
#some_id .some_class {...} or
.some_class {content:'xy'; } etc.
(it only displays CSS set with one level and "simple" CSS like .some_class {color:xy;})

So no idea if these are general restrictions from mPDF or if there are some settings which must be enabled or...
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top