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:
publicfunctionendPage($tocpage=false){// check if page is already closedif(($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:
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:
/***Terminatethecurrentpage*@param$tocpage(boolean)iftruesetthetocpagestatetofalse(endthepageusedtodisplayTableOfContent).*@public*@since4.2.010(2008-11-14)*@seeAddPage(),startPage(),addTOCPage(),endTOCPage()*/publicfunctionendPage($tocpage=false){// check if page is already closedprint"\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"argumentstoparentclasscall_user_func_array('parent::__construct',func_get_args());//Makesurethatthefooterprints$this->SetPrintFooter(true);$this->setFooterData(array(0,0,0),array(0,0,0));}publicfunctionFooter(){$this->setFooterMargin(99);$this->writeHTMLCell(0,//width11,//height10,//posx282,//posy"Page ".$this->getAliasNumPage()." of ".$this->getAliasNbPages(),"TRBL",//borders$ln=0,//lineonnextrowfalse,//backgroundtrue,//reseth'C',//alignmentfalse//autopadding);}publicfunctionget_page(){return$this->page;}publicfunctionget_page_open(){return$this->pageopen;}}//createnewPDFdocument$pdf=newcustomTCPDF(PDF_PAGE_ORIENTATION,PDF_UNIT,PDF_PAGE_FORMAT,true,//unicode'UTF-8',false,//cachetrue//true=pdf1.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=newcustomTCPDF(PDF_PAGE_ORIENTATION,PDF_UNIT,PDF_PAGE_FORMAT,true,// unicode'UTF-8',false,// cachetrue// true = pdf 1.4);$pdf->addPage();$pdf->addPage();/*...dostuff...*/$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:
//IncludethemainTCPDFlibrary(searchforinstallationpath).require_once('tcpdf/tcpdf.php');classcustomTCPDFextendsTCPDF{/****@varfloatstoreforthedynamicmargin.usedinthistestcase*/protected$dynamic_footer_margin=50;publicfunction__construct(){//"Transfers"argumentstoparentclasscall_user_func_array('parent::__construct',func_get_args());//Makesurethatthefooterprints$this->SetPrintFooter(true);$this->setFooterData(array(0,0,0),array(0,0,0));}publicfunctionFooter(){/*changedsothatfootermarginisalsodisplayed*//*postionischangedtogetXandGetY,soweactuallyusethemarginwesetted*/$this->writeHTMLCell(0,//width11,//height$this->GetX(),//posx$this->GetY(),//posy"Page ".$this->getAliasNumPage()." of ".$this->getAliasNbPages().' fm: '.$this->getFooterMargin(),"TRBL",//borders$ln=0,//lineonnextrowfalse,//backgroundtrue,//reseth'C',//alignmentfalse//autopadding);}/***Simplemethodjustshowthedynamic(thoughverysimple:))changingoffootermargin*Itsimplyadds50tomarginbyeachcall.*/publicfunctionsetDynamicFooter(){$this->setFooterMargin($this->dynamic_footer_margin);$this->dynamic_footer_margin+=50;}/***Copiedfromtcpdf-"core"*Terminatethecurrentpage*@param$tocpage(boolean)iftruesetthetocpagestatetofalse(endthepageusedtodisplayTableOfContent).*@public*@since4.2.010(2008-11-14)*@seeAddPage(),startPage(),addTOCPage(),endTOCPage()*/publicfunctionendPage($tocpage=false){//checkifpageisalreadyclosedif(($this->page==0)OR($this->numpages>$this->page)OR(!$this->pageopen[$this->page])){return;}/*NOTEthisisonlychangetorealendPage-method.HerewesetthefooterdynamicallyNOTE*//*CHANGESTARTS*/$this->setDynamicFooter();/*CHANGEENDS*///printpagefooter$this->setFooter();//closepage$this->_endpage();//markpageasclosed$this->pageopen[$this->page]=false;if($tocpage){$this->tocpage=false;}}}//createnewPDFdocument$pdf=newcustomTCPDF(PDF_PAGE_ORIENTATION,PDF_UNIT,PDF_PAGE_FORMAT,true,//unicode'UTF-8',false,//cachetrue//true=pdf1.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//IncludethemainTCPDFlibrary(searchforinstallationpath).require_once('tcpdf/tcpdf.php');classcustomTCPDFextendsTCPDF{/****@varfloatstoreforthedynamicmargin.usedinthistestcase*/protected$dynamic_footer_margin=50;publicfunction__construct(){//"Transfers"argumentstoparentclasscall_user_func_array('parent::__construct',func_get_args());//Makesurethatthefooterprints$this->SetPrintFooter(true);$this->setFooterData(array(0,0,0),array(0,0,0));}publicfunctionFooter(){/*changedsothatfootermarginisalsodisplayed*//*postionischangedtogetXandGetY,soweactuallyusethemarginwesetted*/$this->writeHTMLCell(0,//width11,//height$this->GetX(),//posx//$this->GetY(),//posy$this->h-$this->footer_margin,//posy"Page ".$this->getAliasNumPage()." of ".$this->getAliasNbPages().' fm: '.$this->getFooterMargin(),"TRBL",//borders$ln=0,//lineonnextrowfalse,//backgroundtrue,//reseth'C',//alignmentfalse//autopadding);}/***Simplemethodjustshowthedynamic(thoughverysimple:))changingoffootermargin*Itsimplyadds50tomarginbyeachcall.*/publicfunctionsetDynamicFooter(){$this->setFooterMargin($this->dynamic_footer_margin);$this->dynamic_footer_margin+=20;}publicfunctionAddPage($orientation='',$format='',$keepmargins=false,$tocpage=false){if($this->inxobj){//weareinsideanXObjecttemplatereturn;}if(!isset($this->original_lMargin)OR$keepmargins){$this->original_lMargin=$this->lMargin;}if(!isset($this->original_rMargin)OR$keepmargins){$this->original_rMargin=$this->rMargin;}//terminatepreviouspage$this->endPage();//startnewpage$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;}//createnewPDFdocument$pdf=newcustomTCPDF(PDF_PAGE_ORIENTATION,PDF_UNIT,PDF_PAGE_FORMAT,true,//unicode'UTF-8',false,//cachetrue//true=pdf1.4);$pdf->addPage();/*dynamicfooter-marginexamplewithcontent*/$pdf->writeHTMLCell(0,//width11,//height$pdf->GetX(),//posx$pdf->GetY(),//posygetLorem(25),"TRBL",//borders$ln=0,//lineonnextrowfalse,//backgroundtrue,//reseth'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.