I reported this with version 6.2.6 and the issue is still present in the most recent version of TCPDF (6.2.8). Is there anything you are wondering about or do you need any further info to proceed?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
It would be appreciated if you at least gave some indication on the status of this issue. It has been four months now and I have previously tried emailing you offering to pay for development time but did not receive a response. A 'wontfix' is much better than you just keeping quiet. What is the problem here? I would like to help (both with my time and money) getting this solved, but you are unresponsive? Are you in the process of abandoning the TCPDF project altogether?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am still offering to pay you for your time to fix this. If you could only tell me what you need to fix it. If you don't want to fix it for any reason whatsoever please close this issue, at least please just stop ignoring it.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Just checked your code and I guess your problem causes from this:
public function endPage($tocpage=false) {
// check if page is already closed
if (($this->page == 0) OR ($this->numpages > $this->page) OR (!$this->pageopen[$this->page])) {
return;
}
/* ... */
}
Which means, that the Footer -method is not called 'cause you're on page zero. You can see that by yourself by just adding another page:
// create new PDF document
$pdf = new customTCPDF(
PDF_PAGE_ORIENTATION,
PDF_UNIT,
PDF_PAGE_FORMAT,
true, // unicode
'UTF-8',
false, // cache
true // true = pdf 1.4
);
$pdf->addPage();
$pdf->addPage();
// returns "int 99".
var_dump($pdf->getFooterMargin());
Conclusion: your code works and tcpdf works, but not just in a way you thought :)
PS. your constructor with "call_user_func_array" really shocked my object-oriented mind, but for wierd PHP-reasons it actually works... so what ever rocks your boat :)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
In tcpdf.php (line 3119 or thereabout), some debug with print_r:
/**
* Terminate the current page
* @param $tocpage (boolean) if true set the tocpage state to false (end the page used to display Table Of Content).
* @public
* @since 4.2.010 (2008-11-14)
* @see AddPage(), startPage(), addTOCPage(), endTOCPage()
*/
public function endPage($tocpage=false) {
// check if page is already closed
print "\ncheck if page is already closed\n";
print_r([
'($this->page == 0)' => ($this->page == 0),
'($this->numpages > $this->page)' => ($this->numpages > $this->page),
'(!$this->pageopen[$this->page])' => (!$this->pageopen[$this->page])
]);
if (($this->page == 0) OR ($this->numpages > $this->page) OR (!$this->pageopen[$this->page])) {
return;
}
// print page footer
$this->setFooter();
// close page
$this->_endpage();
// mark page as closed
$this->pageopen[$this->page] = false;
if ($tocpage) {
$this->tocpage = false;
}
}
Updated index.php from my test case:
classcustomTCPDFextendsTCPDF{publicfunction__construct() {// "Transfers" arguments to parent classcall_user_func_array('parent::__construct',func_get_args());// Make sure that the footer prints$this->SetPrintFooter(true);$this->setFooterData(array(0,0,0),array(0,0,0));}publicfunctionFooter() {$this->setFooterMargin(99);$this->writeHTMLCell(0,// width11,// height10,// pos x282,// pos y"Page ".$this->getAliasNumPage()." of ".$this->getAliasNbPages(),"TRBL",// borders$ln=0,// line on next rowfalse,// backgroundtrue,// reset h'C',// alignmentfalse// autopadding);}publicfunctionget_page() {return$this->page;}publicfunctionget_page_open() {return$this->pageopen;}}// create new PDF document$pdf=newcustomTCPDF(PDF_PAGE_ORIENTATION,PDF_UNIT,PDF_PAGE_FORMAT,true,// unicode'UTF-8',false,// cachetrue// true = pdf 1.4);print"<pre>";print"Before first addPage()\n";print_r(['footer margin'=>$pdf->getFooterMargin(),'page'=>$pdf->get_page(),'page open'=>$pdf->get_page_open()]);$pdf->addPage();print"\nAfter first addPage()\n";print_r(['footer margin'=>$pdf->getFooterMargin(),'page'=>$pdf->get_page(),'page open'=>$pdf->get_page_open()]);$pdf->addPage();print"\nAfter second addPage()\n";print_r(['footer margin'=>$pdf->getFooterMargin(),'page'=>$pdf->get_page(),'page open'=>$pdf->get_page_open()]);$pdf->addPage();print"\nAfter third addPage()\n";print_r(['footer margin'=>$pdf->getFooterMargin(),'page'=>$pdf->get_page(),'page open'=>$pdf->get_page_open()]);
What you will notice is that setFooterMargin() does not work properly untill the second page, this means that setFooterMargin() does not work the first and second pages. Starting by the second page it does work. Do you have any suggestion how I can get it working on page 1? While I do use setFooterMargin(99) the number is actually dynamically calculated in my code but I opted not to include the calculation to simplify the test case as much as possible.
I need setFooterMargin() working on the first call to Footer(). I suppose I could do a workaround by using deletePage() but that seems like a hacky bandaid:
// create new PDF document
$pdf = new customTCPDF(
PDF_PAGE_ORIENTATION,
PDF_UNIT,
PDF_PAGE_FORMAT,
true, // unicode
'UTF-8',
false, // cache
true // true = pdf 1.4
);
$pdf->addPage();
$pdf->addPage();
/*
... do stuff ...
*/
$pdf->deletePage($page=0);
Last edit: NiklasBr 2015-10-06
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Okay, now I guess I see your point. The setFooterMargin -method is called as wished, but that doesn't occur before the page is ended (ie. adding a second page, closing a document). But the real question is that before the Footer -method is called X and Y -postions are set to footer position. This means that only place where the footermargin is used is before the Footer -method.
This means that footerMargin cannot be changed in Footer (well it can, but it really affects only the next time the footer is called) so the changing of footer must be triggered somewhere else.
Here's one way to do it:
// Include the main TCPDF library (search for installation path).require_once('tcpdf/tcpdf.php');classcustomTCPDFextendsTCPDF{/** * * @var float store for the dynamic margin. used in this test case */protected$dynamic_footer_margin=50;publicfunction__construct() {// "Transfers" arguments to parent classcall_user_func_array('parent::__construct',func_get_args());// Make sure that the footer prints$this->SetPrintFooter(true);$this->setFooterData(array(0,0,0),array(0,0,0));}publicfunctionFooter() {/* changed so that footer margin is also displayed *//* postion is changed to getX and GetY, so we actually use the margin we setted */$this->writeHTMLCell(0,// width11,// height$this->GetX(),// pos x$this->GetY(),// pos y"Page ".$this->getAliasNumPage()." of ".$this->getAliasNbPages().' fm: '.$this->getFooterMargin(),"TRBL",// borders$ln=0,// line on next rowfalse,// backgroundtrue,// reset h'C',// alignmentfalse// autopadding);}/** * Simple method just show the dynamic (though very simple :) ) changing of footer margin * It simply adds 50 to margin by each call. */publicfunctionsetDynamicFooter() {$this->setFooterMargin($this->dynamic_footer_margin);$this->dynamic_footer_margin+=50;}/** * Copied from tcpdf -"core" * Terminate the current page * @param $tocpage (boolean) if true set the tocpage state to false (end the page used to display Table Of Content). * @public * @since 4.2.010 (2008-11-14) * @see AddPage(), startPage(), addTOCPage(), endTOCPage() */publicfunctionendPage($tocpage=false){// check if page is already closedif(($this->page==0)OR($this->numpages>$this->page)OR(!$this->pageopen[$this->page])){return;}/* NOTE this is only change to real endPage-method. Here we set the footer dynamically NOTE *//* CHANGE STARTS */$this->setDynamicFooter();/* CHANGE ENDS */// print page footer$this->setFooter();// close page$this->_endpage();// mark page as closed$this->pageopen[$this->page]=false;if($tocpage){$this->tocpage=false;}}}// create new PDF document$pdf=newcustomTCPDF(PDF_PAGE_ORIENTATION,PDF_UNIT,PDF_PAGE_FORMAT,true,// unicode'UTF-8',false,// cachetrue// true = pdf 1.4);$pdf->addPage();$pdf->addPage();$pdf->addPage();$pdf->Output('footer_margin_example.pdf','I');
In this example we change the margin in endPage so that margin is changed before setFooter is called (the setFooter calls the Footer -method).
Hope this answers to some of your questions.
Mikko
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Now that I gave it a try some "real" content it looked bad 'cause the content didn't actually follow the rules of footermargin I made another effort:
<?php// Include the main TCPDF library (search for installation path).require_once('tcpdf/tcpdf.php');classcustomTCPDFextendsTCPDF{/** * * @var float store for the dynamic margin. used in this test case */protected$dynamic_footer_margin=50;publicfunction__construct() {// "Transfers" arguments to parent classcall_user_func_array('parent::__construct',func_get_args());// Make sure that the footer prints$this->SetPrintFooter(true);$this->setFooterData(array(0,0,0),array(0,0,0));}publicfunctionFooter() {/* changed so that footer margin is also displayed *//* postion is changed to getX and GetY, so we actually use the margin we setted */$this->writeHTMLCell(0,// width11,// height$this->GetX(),// pos x//$this->GetY(), // pos y$this->h-$this->footer_margin,// pos y"Page ".$this->getAliasNumPage()." of ".$this->getAliasNbPages().' fm: '.$this->getFooterMargin(),"TRBL",// borders$ln=0,// line on next rowfalse,// backgroundtrue,// reset h'C',// alignmentfalse// autopadding);}/** * Simple method just show the dynamic (though very simple :) ) changing of footer margin * It simply adds 50 to margin by each call. */publicfunctionsetDynamicFooter() {$this->setFooterMargin($this->dynamic_footer_margin);$this->dynamic_footer_margin+=20;}publicfunctionAddPage($orientation='',$format='',$keepmargins=false,$tocpage=false){if($this->inxobj){// we are inside an XObject templatereturn;}if(!isset($this->original_lMargin)OR$keepmargins){$this->original_lMargin=$this->lMargin;}if(!isset($this->original_rMargin)OR$keepmargins){$this->original_rMargin=$this->rMargin;}// terminate previous page$this->endPage();// start new page$this->setDynamicFooter();$this->SetAutoPageBreak(true,$this->getFooterMargin());$this->startPage($orientation,$format,$tocpage);}}functiongetLorem($paragraphs=1){$lorem='Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris nec sapien eros. Praesent nisi ex, tempor sit amet tempor sit amet, mattis a libero. Pellentesque convallis lorem risus, volutpat volutpat tellus posuere quis. Vivamus ut vulputate ex. Phasellus feugiat porttitor justo vel pretium. Curabitur interdum quam velit, ut sodales est cursus nec. Praesent auctor ligula ac nunc suscipit commodo gravida sed ipsum. Nunc eget nulla ante. Maecenas luctus ultricies lacus eu tincidunt. Curabitur nulla dolor, vehicula sed ex at, dignissim dictum erat. Vestibulum facilisis ipsum sit amet lacus cursus tempus. Aliquam mauris libero, efficitur sit amet rhoncus quis, finibus non magna. Praesent quis velit porta, pharetra nulla at, tincidunt ante.';$ret='';for($i=0;$i<$paragraphs;$i++){$ret.=$lorem."\n\n";}return$ret;}// create new PDF document$pdf=newcustomTCPDF(PDF_PAGE_ORIENTATION,PDF_UNIT,PDF_PAGE_FORMAT,true,// unicode'UTF-8',false,// cachetrue// true = pdf 1.4);$pdf->addPage();/* dynamic footer-margin example with content */$pdf->writeHTMLCell(0,// width11,// height$pdf->GetX(),// pos x$pdf->GetY(),// pos ygetLorem(25),"TRBL",// borders$ln=0,// line on next rowfalse,// backgroundtrue,// reset h'C',// alignmentfalse// autopadding);$pdf->Output('footer_margin_example.pdf','I');
Here we have a great big content (of repeated lorem ipsum) so that the content spans over multiple pages. Now the footer-margin is applied in addPage and the SetAutoPageBreak is called (so the content actually works with the dynamic margin).
Hopefully this will satisfy your needs :)
Mikko
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Mikko, this is a great example regarding tcpdf and it will auto break page based on dynamic content. But how can do like
for normal pages, footer margin will be 20, and same will be used for autopagebreak
but for last page of pdf need footer margin as 60 and same be used as autopagebreak for the last page only.
what I meant to ask is show dynamic footer, only to last page irrespective of number of pages in pdf and the pdf got common header for all pages. you can see the sample as attached. Is there solution for this kind of situation.
I reported this with version 6.2.6 and the issue is still present in the most recent version of TCPDF (6.2.8). Is there anything you are wondering about or do you need any further info to proceed?
I tried 6.2.9, but it does not seem to contain any fixes for this bug. I will gladly provide any more info if you request it.
I tried version 6.2.11 just now, but no changes. Please tell me what you need!
It would be appreciated if you at least gave some indication on the status of this issue. It has been four months now and I have previously tried emailing you offering to pay for development time but did not receive a response. A 'wontfix' is much better than you just keeping quiet. What is the problem here? I would like to help (both with my time and money) getting this solved, but you are unresponsive? Are you in the process of abandoning the TCPDF project altogether?
I am still offering to pay you for your time to fix this. If you could only tell me what you need to fix it. If you don't want to fix it for any reason whatsoever please close this issue, at least please just stop ignoring it.
Hey Niklas,
Just checked your code and I guess your problem causes from this:
Which means, that the Footer -method is not called 'cause you're on page zero. You can see that by yourself by just adding another page:
Conclusion: your code works and tcpdf works, but not just in a way you thought :)
PS. your constructor with "call_user_func_array" really shocked my object-oriented mind, but for wierd PHP-reasons it actually works... so what ever rocks your boat :)
Mikko, thanks for looking into this!
In tcpdf.php (line 3119 or thereabout), some debug with print_r:
Updated index.php from my test case:
This gives the following output:
What you will notice is that setFooterMargin() does not work properly untill the second page, this means that setFooterMargin() does not work the first and second pages. Starting by the second page it does work. Do you have any suggestion how I can get it working on page 1? While I do use setFooterMargin(99) the number is actually dynamically calculated in my code but I opted not to include the calculation to simplify the test case as much as possible.
I need setFooterMargin() working on the first call to Footer(). I suppose I could do a workaround by using deletePage() but that seems like a hacky bandaid:
Last edit: NiklasBr 2015-10-06
Hi Niklas,
Okay, now I guess I see your point. The setFooterMargin -method is called as wished, but that doesn't occur before the page is ended (ie. adding a second page, closing a document). But the real question is that before the Footer -method is called X and Y -postions are set to footer position. This means that only place where the footermargin is used is before the Footer -method.
This means that footerMargin cannot be changed in Footer (well it can, but it really affects only the next time the footer is called) so the changing of footer must be triggered somewhere else.
Here's one way to do it:
In this example we change the margin in endPage so that margin is changed before setFooter is called (the setFooter calls the Footer -method).
Hope this answers to some of your questions.
Whoops,
Now that I gave it a try some "real" content it looked bad 'cause the content didn't actually follow the rules of footermargin I made another effort:
Here we have a great big content (of repeated lorem ipsum) so that the content spans over multiple pages. Now the footer-margin is applied in addPage and the SetAutoPageBreak is called (so the content actually works with the dynamic margin).
Hopefully this will satisfy your needs :)
Hi Mikko, this is a great example regarding tcpdf and it will auto break page based on dynamic content. But how can do like
for normal pages, footer margin will be 20, and same will be used for autopagebreak
but for last page of pdf need footer margin as 60 and same be used as autopagebreak for the last page only.
what I meant to ask is show dynamic footer, only to last page irrespective of number of pages in pdf and the pdf got common header for all pages. you can see the sample as attached. Is there solution for this kind of situation.