Can't create PDF from my own list template with custom calculations.

Status
Not open for further replies.
Hi,

I have made my own list template for multicolumn list. On my list i have standard fabrik calculations for some columns and my "manually written calculations". They are together on 1 list template.

My own calculations are written in default file for list template.
I can't create PDF for this list using my template with calculations.

I get an error:
Fatal error: Call to undefined method DOMText::getAttribute() in /var/www/cc.joomla/libraries/dompdf/include/cellmap.cls.php on line 437

Cellmap.cls.php is:
PHP:
$node = $frame->get_node();
 
  // Determine where this cell is going
  $colspan = $node->getAttribute("colspan");
  $rowspan = $node->getAttribute("rowspan");

  if ( !$colspan ) {
  $colspan = 1;
  $node->setAttribute("colspan",1);
  }

  if ( !$rowspan ) {
  $rowspan = 1;
  $node->setAttribute("rowspan",1);
  }
  $key = $frame->get_id();

  $bp = $style->get_border_properties();

line 437 is:
$colspan = $node->getAttribute("colspan");


i use code like <td colspan="5"> for my custom calculations in file default.php

Exactly i would need in PDF "only summing part" on my list, = without table with records.

But now, on the beginning-to-get-PDF nothing is not send to PDF, PDF is not created at all.


Some piece of code for: /var/www/cc.joomla/components/com_fabrik/views/list/tmpl/default-2015-09-11-table-kp5/default.php
PHP:
<?php
/**
* Fabrik List Template: Default
*
* @package     Joomla
* @subpackage  Fabrik
* @copyright   Copyright (C) 2005 Fabrik. All rights reserved.
* @license     http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
*/
//===================================.......
<?php
            foreach ($group as $this->_row) :
                echo $this->loadTemplate('row');
             endforeach;
             ?>
        <?php if ($this->hasCalculations) : ?>
<tr class="fabrik_calculations">
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
<td>8</td>
<td>9</td>
<td>10</td>
<td>11</td>
<td>12</td>
<td>13</td>
<td>14</td>
<td>15</td>
<td>16</td>
<td>17</td>
<td>18</td>
<td>19</td>
<td>20</td>
</tr>
                                     
                                        <td><table class="rysio1">
                     <?php   $h=0;
                          foreach ($this->calculations as $cal) {

if($h <= 1)  {
                               echo '<tr>';
                                        echo "<td>";
                                        echo array_key_exists($groupedby, $cal->grouped) ? $cal->grouped[$groupedby] : $cal->calc;
                                        echo "</td>";
                                        echo  "</tr>";
}
$h++;
}
                              ?>
                                        </table></td>
                                     
<td colspan="5"><table class="rysio1">
                     <?php  $j=0;

echo '<tr class="fabrik_calculations">';
                                        echo "<td>";
$db =& JFactory::getDBO();
$order1 =FabrikHelperElement::filterValue(11152); //with 81
echo "<br/>";
if (isset($order1)) {
$query = "SELECT  `ip2_zamowienie_symbol1` FROM  `ccjom_cc_kk_ip2_zamowienie`  WHERE  `id`= ".$order1."  ";
$db->setQuery($query);
$result = $db->loadResult();
$zam1 = $result;
}
if ($order1==0) {
$zam1 = "Razem wszystkie zam?wienia";
}





echo " ---- <strong><font color='blue'> Zam?wienie nr: $zam1 </font></strong> ---- <br/><br/>";
                                        echo "</td>";

                        foreach ($this->calculations as $cal) {
if($j>=4 and $j<= 4)  {
                                 echo '<tr class="fabrik_calculations">';
                                        echo "<td>";
                                        echo array_key_exists($groupedby, $cal->grouped) ? $cal->grouped[$groupedby] : $cal->calc, $j;
                                        echo "</td>";
                                        echo  "</tr>";
}
$j++;
}                            ?>

<?php  $n=0;
                        foreach ($this->calculations as $cal) {
if($n >= 19 and $n<20)  {
                                 echo '<tr class="fabrik_calculations">';
                                        echo "<td>";


echo "Test2 --- <strong>Suma pakietow AA, AB, AC, AD:</strong>  <br/><br/>";
$db =& JFactory::getDBO();


for ($i=1; $i<=5; $i++){

if ($order1==0){
$query = "SELECT  `is_pak_xxxx`, `field_pakiety_analogowe` FROM  `ccjom_cc_kk_karta_rejestr` WHERE ( `rodzaj_karty_np_wzorzec`= '2' and `field_pakiety_analogowe`=".$i.") ORDER BY `id`";
}
else {
$query = "SELECT  `is_pak_xxxx`, `field_pakiety_analogowe`  FROM `ccjom_cc_kk_karta_rejestr` WHERE ( `zamow_symbol`=".$order1."  and `field_pakiety_analogowe`=".$i.") ORDER BY `id`";
}

$db->setQuery($query);
$result = $db->loadResult();

$resaa = mysql_query($query);
$rrraa=array();
$n=0;
while($row = mysql_fetch_array($resaa))
   {
       $rrraa[$n]=  $row['is_pak_xxxx'];
$n++;               }


if ($order1==0){
$query = "SELECT  `is_pak_xxab`, `field_pakiety_analogowe` FROM  `ccjom_cc_kk_karta_rejestr` WHERE ( `rodzaj_karty_np_wzorzec`= '2' and `field_pakiety_analogowe`=".$i.") ORDER BY `id`";
}

else {
$query = "SELECT  `is_pak_xxab`, `field_pakiety_analogowe`  FROM `ccjom_cc_kk_karta_rejestr` WHERE ( `zamow_symbol`=".$order1." and `field_pakiety_analogowe`=".$i.")  ORDER BY `id`";
}

$db->setQuery($query);
$result = $db->loadResult();
$resab = mysql_query($query);

while($row = mysql_fetch_array($resab))
   {
       $rrraa[$n]=  $row['is_pak_xxab'];
$n++;
               }

if ($order1==0){
$query = "SELECT  `is_pak_xxac`, `field_pakiety_analogowe` FROM  `ccjom_cc_kk_karta_rejestr` WHERE ( `rodzaj_karty_np_wzorzec`= '2' and `field_pakiety_analogowe`=".$i.") ORDER BY `id`";
}

else {
$query = "SELECT  `is_pak_xxac`, `field_pakiety_analogowe`  FROM `ccjom_cc_kk_karta_rejestr` WHERE (`zamow_symbol`=".$order1." and `field_pakiety_analogowe`=".$i.")  ORDER BY `id`";
}


$db->setQuery($query);
$result = $db->loadResult();
$resac = mysql_query($query);

while($row = mysql_fetch_array($resac))
   {
       $rrraa[$n]=  $row['is_pak_xxac'];
$n++;               }

if ($order1==0){
$query = "SELECT  `is_pak_xxad`, `field_pakiety_analogowe` FROM  `ccjom_cc_kk_karta_rejestr` WHERE ( `rodzaj_karty_np_wzorzec`= '2' and `field_pakiety_analogowe`=".$i.") ORDER BY `id`";
}

else {
$query = "SELECT  `is_pak_xxad`, `field_pakiety_analogowe`  FROM `ccjom_cc_kk_karta_rejestr` WHERE ( `zamow_symbol`=".$order1." and `field_pakiety_analogowe`=".$i.")  ORDER BY `id`";
}

$db->setQuery($query);
$result = $db->loadResult();
$resad = mysql_query($query);

while($row = mysql_fetch_array($resad))
   {
       $rrraa[$n]=  $row['is_pak_xxad'];
$n++;               }

$newrrraa = array_count_values($rrraa);
                                foreach ($newrrraa as $key => $value) {
$query = "SELECT  `is_pak_wejsc_analog_aa` FROM  `ccjom_cc_kk_is_aa` WHERE `id`=$key ";
$db->setQuery($query);
$result2 = $db->loadResult();

$query3 = "SELECT  `is_pak_wejsc_analog_n_i_w` FROM  `ccjom_cc_kk_is_pak_wa` WHERE `id`=$i ";
$db->setQuery($query3);
$result3 = $db->loadResult();
echo "<strong> $result3 -- $result2 ---- <font color='red'>$value</font></strong> <br />"; }

}

echo "<br/>";


echo "</td>";
                                        echo  "</tr>";
}
$n++;
}                            ?>




  <?php  $j=0;
                        foreach ($this->calculations as $cal) {
if($j>=6 and $j<= 7)  {
                                 echo '<tr class="fabrik_calculations">';
                                        echo "<td>";
                                        echo array_key_exists($groupedby, $cal->grouped) ? $cal->grouped[$groupedby] : $cal->calc, $j;
                                        echo "</td>";
                                        echo  "</tr>";
}
$j++;
}                            ?>

</table></td>
                                        <td>7</td>
                                
                                       <td colspan="3"><table class="rysio1">
                     <?php  $k=0;
                        foreach ($this->calculations as $cal) {
if($k >= 8 and $k<=10)  {
                                 echo '<tr class="fabrik_calculations">';
                                        echo "<td>";
                                        echo array_key_exists($groupedby, $cal->grouped) ? $cal->grouped[$groupedby] : $cal->calc, $k;
                                        echo "</td>";

   echo  "</tr>";
}
$k++;
}
                            ?>
//=================........
<?php  $i=0;
                        foreach ($this->calculations as $cal) {

if($i >= 11 and $i<=18)  {
                                 echo '<tr class="fabrik_calculations">';
                                        echo "<td>";
                                        echo array_key_exists($groupedby, $cal->grouped) ? $cal->grouped[$groupedby] : $cal->calc;
                                        echo "</td>";
                                        echo  "</tr>";}
$i++;}













echo "</table>";


                                        echo "</td>";
                                        echo  "</tr>";



                            ?>

                                        </table>
                                        </td>
                                        </tr>
                        <?php    endif;?>

                        </tbody>
                        <?php
                        $gCounter++;
                endforeach;

        $this->showGroup = false;

        // If using AJAX then we need to add in enough groupdata containers for additonal rows that may be shown
     
//===================.........

my list is here:
http://candc.katowice.pl/index.php/menu-karta-produkcji/adm-rejestr-pak-prod3

Neccessary is login, should be actual login for Fabrik Staff in my profile.
 

Attachments

  • Zaznaczenie_084.png
    Zaznaczenie_084.png
    65.2 KB · Views: 622
Last edited:
This is a DOMPdf error, no Fabrik one.
Which exact Fabrik version are you running (must be a GitHub version including the DOMPdf lib)?

Do you have a list PDF template?
DOMPdf has it's restrictions, you must adapt the template used for the PDF output.
 
I can't replicate your error, it's creating the PDF.
But with DOMPdf you can run into runtime limits depending on list size etc.
 
Hmmm!
I have made big error - lost <tr> in my code.

Now, pdf is created but without my own calculations.
I need in PDF all calculations (fabrik and my own calculation).
I would need also PDF that include only summing (calculations) under table with records.
 

Attachments

  • __ REJESTR pakietów produkcyjnych - nowa wersja sum-1.pdf
    1.6 MB · Views: 560
Create an extra PDF template.
DOMPdf is converting what it gets from your template in HTML.
Maybe you must adapt your CSS, e.g.DOMPdf can't handle float.
 
I have created my own list template with my custom calculations by changing file default.php - sample of code is in first post.
Code for those own-calculations is in php not html.
I can duplicate my directory with list template and create one independent list template for PDF purpose.

But have no idea how to modify my own-calculations written in php to get them in PDF.

Is any tip how to do this or any steeps?
 
My own calculations are marked on screen shoot : Test2 - Test8.
Those without Testx - header-line are fabrik calculations.

Code for Test3: (in file default.php)
PHP:
<?php  $n=0;
                        foreach ($this->calculations as $cal) {
if($n >= 19 and $n<20)  {
                                 echo '<tr class="fabrik_calculations">';
                                        echo "<td>"; 
echo "Test3 --- <strong>Suma pakietow dwustanowych IA,IC,IE:  </strong>";
if ($order1==0){
$query = "SELECT  `is_pak_dwus_ia`, `pd_ia`, `konfig_napiecie` FROM  `ccjom_cc_kk_karta_rejestr` WHERE  `rodzaj_karty_np_wzorzec`= '2'  ORDER BY `id`";
$query1 = "SELECT  `pd_ia` FROM  `ccjom_cc_kk_karta_rejestr` WHERE  `rodzaj_karty_np_wzorzec`= '2'  ORDER BY `id`";
}
else {
$query = "SELECT  `is_pak_dwus_ia`, `pd_ia`, `konfig_napiecie` FROM  `ccjom_cc_kk_karta_rejestr` WHERE  `zamow_symbol`=".$order1."  ORDER BY `id`";
$query1 = "SELECT  `pd_ia` FROM  `ccjom_cc_kk_karta_rejestr` WHERE  `zamow_symbol`=".$order1."  ORDER BY `id`";
}
$db->setQuery($query);
$result = $db->loadResult();

$resaa = mysql_query($query);
$rrraa=array();
$rrrquan=array();
$wynik110=array();
$wynik220=array();

$n=0;
$i=1;
$h=0;
$g=0;

while($row = mysql_fetch_array($resaa))   {
       $rrraa[$n]=  $row['is_pak_dwus_ia'];
       $t=$rrrnap[$n] = $row['konfig_napiecie'];
       $m=$rrrquan[$n] = $row['pd_ia'];
       $g = (int)$row['pd_ia'];

if (!($g==0)) {
for ($h=$i; $h<$i+$g; $h++) {
if ($t==1)
$wynik220[$h] =  $row['is_pak_dwus_ia'];
if ($t==2)
$wynik110[$h] =  $row['is_pak_dwus_ia'];
}
}
$i=$i+$g;
$n++;}

$newrrraa = array_count_values($rrraa);
$newrrrquan = array_count_values($rrrquan);
$newwynik110 = array_count_values($wynik110);
$newwynik220 = array_count_values($wynik220);

echo "<br/><br/>";
                 
                                foreach ($newwynik220 as $key => $value) {
$query = "SELECT  `is_pak_dwus_ia` FROM  `ccjom_cc_kk_is_pak_dwus_ia` WHERE `id`=$key ";
$db->setQuery($query);
$result1 = $db->loadResult();
echo "<strong>Pakiety 220V: $result1</strong> ------ <strong><font color='red'>$value</font></strong> <br />"; }
                               foreach ($newwynik110 as $key => $value) {
$query = "SELECT  `is_pak_dwus_ia` FROM  `ccjom_cc_kk_is_pak_dwus_ia` WHERE `id`=$key ";
$db->setQuery($query);
$result1 = $db->loadResult();
echo "<strong>Pakiety 110V: $result1 ------ <font color='red'>$value</font></strong> <br />"; }
echo "<br/>";
 

Attachments

  • Zaznaczenie_085.png
    Zaznaczenie_085.png
    155.7 KB · Views: 591
Last edited:
Not sure what are yours, I can't see anything marked.

But I assume you don't have a "clean" HTML structure, DOMPdf is very sensitive and doesn't support any possible thinkable structure (e.g. I don't know if your can use nested tables...)
 
Sorry, it is really not clear what is calculation: Test2, Test3, ...
Can you look at new screen shoot?
 

Attachments

  • Zaznaczenie_085a.png
    Zaznaczenie_085a.png
    184.8 KB · Views: 557
My suggestion would be to take your PDF template's output, by using the tmpl=component link, and run it through validator.w3.org, to make sure it is valid HTML. If it has any warnings or errors, fix those, and try it as PDF again.

-- hugh
 
Looking at your site http://candc.katowice.pl/index.php/menu-karta-produkcji/adm-rejestr-pak-prod3?tmpl=component
with web developer (FF addon) it's blaming the <font... tag
which is not longer a valid HTML tag.
No idea if this is breaking DOMPdf but you should replace it (use e.g. <span style="color:red">...)

But there's a lot of other stuff missing in the PDF, not only your own calculation.
You should really create a very simple plain HTML stucture.
 
I also try something with this PDF and i change code where is my own calculation to:
PHP:
<?php  $n=0;

                        foreach ($this->calculations as $cal) {

if($n >= 18 and $n<19)  {
                                 echo '<tr class="fabrik_calculations">';
                                        echo "<td>";


echo "Test2 --- <strong>Suma pakietow AA, AB, AC, AD:</strong>  <br/><br/>";
$db =& JFactory::getDBO();

Earlier was:
if($n >= 19 and $n<20) {

Now, my own calculations appear on PDF, but columns are very wide and ugly,
doesn't work in my code:
<td colspan="5">
and others:
<td colspan="3">
 
I will try this hugh!
Now i get PDF with all calculations, but this PDF is ugly.

Is any way to modify list-template-for-PDF to get only summing/calculations = without table with records ?
 

Attachments

  • __ REJESTR pakietów produkcyjnych - nowa wersja sum-14.pdf
    1.6 MB · Views: 572
In the PDF template don't do
Code:
            foreach ($group as $this->_row) :
                echo $this->loadTemplate('row');
             endforeach;
(Assuming you are using a copy of the default template)
PDF ugly: That's what I've said. You must adapt your HTML and CSS for DOMPdf.
 
Thanks troester - i remove the code you have mentioned (and table doesn't appear on PDF), i also removed some other lines of code in default.php and also "headings" with column headers are not appear.
Now my PDF is what i need.
 

Attachments

  • -- REJESTR pakietów produkcyjnych (2).pdf
    1.5 MB · Views: 579
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top