TCPDF how to prevent last empty page in some cases - php

when i create via PHP a pdf using TCPDF, some times i get a last empty page body (so header and footer printed, but body empty).
It appened when i print different rows of text and the latest row is very close to bottom margin of my pdf...
When i output data into a file.pdf, for example, i get 3 pages...but text is not occupying 3 pages... it occupe only 2 pages (very close to bottom margin)... but TCPDF i don't know why, add 1 more useless page.
My idea is:
create my rows
after last row, add an empty span <span id="hidden_end"></span>
search inside the pdf: if I find "hidden_end" inside the last page, all is ok. I I find "hidden_end" NOT at the last page, the delete last page from PDF
But i don't know how to implement point 3.
Any ideas?

Related

Add blank page if current page is ODD in PHP mPDF

I have table in HTML, which will take sometimes one page, sometimes more. After add this to pdf I need check how many pages I have so far and add blank page if I have an odd number of pages.
After that I will add another content.
How can I do that?
$mpdf->page holds the current page number, so you can use it to check what page you are on and add a pagebreak if needed:
if($mpdf->page % 2 == 1) {
$mpdf->addPage();
}

Repeat table rows till new div arrives DOMPDF

I am trying to create invoice and exporting in pdf using DOMPDF. Where I am stuck is, the table I am using to display product details, is just remaining till rows only, where I want it to add blank rows till new footer div comes up
Current Invoice :
What I want :
I am using Code Igniter and DOMPDF
I have already tried foreach ($rows as $row):{}
This isn't really something you can do with Dompdf. What you would have to do is determine how many rows fit on a page then just add more rows using PHP before you give the document to Dompdf. The only way this would really be feasible would be if the height of the rows was known in advance.

FPDF show footer page number for specific pages with different format

In FPDF, if there are 4 pages to print then FPDF will calculate page as 0,1,2,3
For generating page number, It will skip the 0th page (if($this->page>0){ } in AddPage() function) and calculate line number from next page onwards(1,2,3) and in close() function it just add another page number (4)
So total there will be 4 pages and in output it will show line number correctly.
Current scenario: I need to determine the page number format dynamically. So in function AddPage($orientation='') I added another parameter called $show_number. So if show number is 1 then need to show the page number for that page in a specific way, else show in another way.
Problem: Because the FPDF skips the first page and adds the last page number in close() function I could not show the page number correctly.
For example, if I wanted to show the number in a different way on the third page, I'm getting the result in 2nd page instead.

Dompdf: Get index of page-breaking table tr for arithmetic carry

I am using Dompdf to create invoices for an online shop.
If the list of articles exceed the available space on a page, it generates a page break and continues on the next page with a new thead as it is supposed to be.
What I need to do next is show an arithmetic carry (the sum of all previous articles) of the previous page(s) somewhere on top of the pages after a page break.
I am searching for a solution to find out the index of the tr after which a page break is produced.
I was thinking of attaching an invisible element with the current sum of all previous articles to each tr and then display only the correct elements according to the beaking tr elements' indices, but I don't know if this is the best way to do this.
Also I thought about css count which is working with Dompdf, but I wasn't able to find out whether I can make an element visible by the current number of a counter.
Just if it helps: I am generating the invoice document dynamically via Twig with an {{for ... in ... }} loop.
I appreciate any help! :)

Form on PHP page with multiple submits changes CSS of page

I've created a PHP web form which when all the data is present has 2 submit buttons (Continue and Print). Continue calculates details based on the entered information and displays it on the page. Print performs the same calculations, but then creates a PDF in a new window.
When I click Print the original page still loads (which is fine) but the styling is altered.
To see what I mean head to this page and for speed enter "1" in all text boxes except Position (which must be text). After you've clicked Continue, click Print to generate a PDF, then look back at the original web page to see altered styling.
Any ideas would be useful.
Thanks,
Adrian
Assuming you mean the tables overrunning the footer, get rid of the height: 100%; on #prodselector_text, solves the issue for me.

Categories