Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8024121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:46:09+00:00 2026-06-04T22:46:09+00:00

TL;DR: I have problems with PHP generating PDF’s longer than 1 page total. Hello

  • 0

TL;DR: I have problems with PHP generating PDF’s longer than 1 page total.


Hello again. My goal is to create a script that will basically get all the important data and create a A4 format PDF invoice/document for printing/mailing/archiving. Generating PDF document is fine as long as the document does not overflow.

I want the invoice pages to be outlined with a border, it should contain:

  • the needed stuff required for the invoice to be valid
  • billed products/other information
  • place for supplier/customer signature and stamp or other data

All the pages HAVE to contain header and footer (company logo) and footer (page # of # – Invoice/Document ID – Date and Time – office ID – Printer ID, assigned personnel, whatever someone can ask), as well as border around the document body (under header, above footer).

Everything is fine as long as the document size is not bigger than

$pageSize-$pageMargins-$header-$footer-$invoiceDataBlock-$signaturesBlock

which is basically just like 10 cm for the actual invoiced items. If the document is bigger, I actually create attachment for the invoice manually using spreadsheet editor.

The question is: What can I do to create a multipage PDF document that has no problems like invoiced items overlaying the header/footer? I need to know when to continue on the next page. How do I know this? What is the best way to accomplish this task?

Thank you in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T22:46:11+00:00Added an answer on June 4, 2026 at 10:46 pm

    Use TCPDF. It has a very handy SetY() / GetY() pair of functions, that allows you to know, where on the page you are. You can use this to know when to do a page break.

    Hint: Do not use the Header/Footer capabilities – they are clunky. Draw your own headers/footers.

    Edit

    As from discussion below, here are some details: To avoid overlaying you have 2 possibilities

    1. Use getStringHeight() and calculate
    2. Use Transactions

    The first version draws its rationale from the fact, that of all objects you typically use in generating a PDF a text-flow is the only one, of which you cannot tell beforehand the height it will use. getStringHeight() provides you with a good enough estimate, so you know before adding the element, if it will fit on the page (leaving enough room on the bottom for the footer). So basically you extend your drawing loop to calculate the height of each element and test, if you need to start a new page first. This allows also for some sort of keeptogether, e.g. if the remaining space after a section title is too low, start a new page before, to keep section title and section body together.

    The second version is even easier: In TCPDF you can use transactions simialr to a Database: Start a transaction, draw, if the result is not to your liking roll back, else commit. We found this to be quite a performance hog, ultimately deciding against it for long textual reports, but a 2-page invoice is a very different beast.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have page, i can contact directly without any problems. http://www.mysite.com/app_dev.php/comments/22 the page shows
I realized that I can have problems with single quotes in php arrays: <?php
I have two problems with the same php/ajax solution. The first is a weird
I have the following code generating content on my site: <div class=content id=links> <?php
I have a site like: http://*mysite.com/search/ in it index.php is generating History.pushState() for history.js
I made a PHP script yesterday which send an email with a PDF as
A PHP script is generating the following table panel based on the data from
I am using the FPDF library for generating PDF files by PHP. This library
I have PHP generating JSON data but I am having a problem making a
I have a problem in php code inserting values into database (I use PHPMyAdmin).

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.