Solved

fpdf dynamic footer height

Posted on 2014-04-20
6
1,873 Views
Last Modified: 2014-04-24
The tutorial about the footer here http://www.fpdf.org/
shows a method for a static height footer.

How can make the footer height dynamic when the footer contains an image or a multicell with more than 1 line?

Thank you.
0
Comment
Question by:myyis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 35

Expert Comment

by:Dan Craciun
ID: 40012038
Reading the code, making the footer "dynamic" is as easy as adding more elements to it.
It's simply positioned 1.5 cm from the bottom, so any content you add to the footer will be pushed up.

HTH,
Dan
0
 
LVL 1

Author Comment

by:myyis
ID: 40012137
The extra content does not make it pushed up, they disappear at the bottom margin
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 40012267
I do not think there is a "dynamic" answer, so this is just an explanation of the philosophy behind two different languages.  

First, HTML: It is a semantic markup language, but many years ago it was used (or abused) for layout capabilities, too (think tables, etc).  HTML is somewhat flexible in the way it wraps text and adjusts container sizes to account for differences in the dimensions of the viewports.  

Next PDF: It is a document layout language, devoid of semantic meaning, and inflexible in the way it wraps text.  PDF is intended to prescribe in extreme detail the exact positioning of data elements on the printed page.  So the idea of a "dynamic height" in a PDF document is kind of counter-intuitive, in the same way that a dynamic height would not make sense in automobile wheel - the parts have to fit together in a car.  They have to fit together in a PDF document, too.

I think you will get the best results from your work with FPDF (or TCPDF) if you approach the page layout logically from the top left to the bottom right, putting everything exactly into its place in the document.  That means if you have some footers that are one size and some that are another size, you need two different footer algorithms. The resulting PDFs can render the footers exactly the way you want them, but your program logic will have to control which footer layout you add to the document.
0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
LVL 1

Author Comment

by:myyis
ID: 40012281
I see but there should be a simpler way.
Because the header height is automatically adjusted without any extra effort while the footer height is static. I believe the fpdf community had found a solution to this problem.
0
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 40012294
Top-to-bottom organization (which is what FPDF and TCPDF use) readily allows for header height to be "dynamic" because it just means pushing other things down the page.  But where do you "push" the data when you've gotten to the end of the page?  I don't believe these libraries give you the option to "push" the data up the page.  You can manually calculate the position of any data element you want.  I'm not suggesting that a dynamic footer is a bad idea; I'm just trying to show you how to get past this issue in a practical step, without wasting your time.

Here are the choices as I see them:

Allocate the footer area large enough to hold the largest data element that you need in the footer.  That way everything will fit.  Then if you have a smaller data component, you will have some white space in the footer.

Or, write program logic that predetermines the size of the footer and uses that information to decide the size you will allocate to the page of information above the footer.  By doing that you can be sure that the footer will always fit with a minimum of unused white space.

My preference would be to allocate the larger footer area; I think this will give you the fastest path to a solution.
0
 
LVL 1

Author Closing Comment

by:myyis
ID: 40021455
Helped! Thank you.
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question