Solved

fpdf dynamic footer height

Posted on 2014-04-20
6
1,636 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
  • 3
  • 2
6 Comments
 
LVL 34

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
 

Author Comment

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

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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

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 108

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
 

Author Closing Comment

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

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

759 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now