Solved

fpdf dynamic footer height

Posted on 2014-04-20
6
1,788 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
 

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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 

Author Closing Comment

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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Link failure 16 63
How do I speed up this PDO query 4 13
JSON decode 5 17
Why is my implode function empty 8 13
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

756 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