TCPDF cuts text when the page end / footer is reached? - php

I am using TCPDF to create PDFs with PHP. Everything works very nice, except when text would be placed where the footer resides. In my example, the text is shown only half, the rest is behind the footer. Is there an option which defines to put it on the next page?
Besides that, my PDFs differ from print to print, some have 1 page, some 2 or more. Is it possible to say that a specific text should only be placed on the page when it fits completely? if not, it should go to the next page.
I already have this in my code, but it doesnt help, the text is still cut.
$pdf->SetAutoPageBreak(true, 25);
I am creating the PDF by creating a huge HTML string and print that to the PDF using writeHTML. This is how it looks, the bold text on top should go to the next page, its hidden behind the footer.
Thanks!

Related

FPDF - How to make text to display in middle of a page?

I'm using the FPDF library to generate a PDF file.
Each page in the file is 100mm x 100mm with a 10mm margin on all sides.
The text that displays on each page varies (but should always ever be a maximum of 200 words).
I really want the text to display so it's centered perfectly in the middle of the page.
At the moment, I can get the text to be centre-aligned but am struggling to position it so it sits in the middle of the page every time. This is my code so far:
$pdf->AddPage();
$pdf->SetMargins($card_margin,$card_margin,$card_margin);
$pdf->SetAutoPageBreak(true,$card_margin);
$pdf->SetFont('Avenir','','10');
$pdf->SetAutoPageBreak(false);
$pdf->MultiCell(80,5,$text_to_print,0,'C');
$pdf->SetFont('Alex Brush','','13');
$pdf->MultiCell(80,10,$signee_text_to_print,0,'C');
And this is a screenshot of a PDF page that is produced from the above code:
Any ideas or suggestions would be greatly appreciated!
Use SetY before your call to MultiCell to "push down" where the text starts on the page. Since you indicate that it will never be more than 200 characters you should be able to estimate the height and used a fixed value for X which will get you very close to the center vertically every time.
$pdf->SetAutoPageBreak(false);
$pdf->SetY(100); // for example ... value will need to be changed of course
$pdf->MultiCell(80,5,$text_to_print,0,'C');

Completly remove margin with tcpdf when printing the document

I'm using tcpdf to create a report. I have an image in the header and in the footer. When I generate the pdf (view on the screen), I successfully removed the margins. But, when I print it, is there a way to remove the margin set for the printing?
My customer would like to have a document like if they print on a paper that already have the header/footer.
Is this possible? (first picture is what I see on the screen after generate the pdf, second picture is what I get when I want to print it)
This can't be done via PHP nor TCPDF. You either have to change the printing configurations of the program used to print or the ones of the printer. And the printer has to support printing without margins.

mPDF - Determine height of a element after rendering

I am using mPDF to generate PDF files from form submissions.
The script is going through all questions and creating a HTML fieldset for each containing the question and the answers.
Since the survey is quite long, the generated PDF spans over several pages which works fine. Now, the client wants "nice & pretty" PDF files, where a fieldset does not contain a page break.
From this question, I know I can determine the remaining space of a page during the generation process.
Now the question is, how can I determine the height of the fieldset coming up next in order to decide whether or not I have to add a page break first?
Is there a function, which just renders a specific part of HTML as a PDF and returns the final height?

dompdf making the header and the footer "solid"

Hi i'm saving some html stuff with .pdf extension using dompdf.
The problem is that i made an header and a footer(using the dompdf script) and it looks fine as long as content does not fill the whole page.
The thing is that the header and the footer generated act like an absolute positioned div and the page content goes under them instead of jumping to the next page once the footer is reached.
Now, i know they are added after the html and it's normal that the text goes under but is there anyway(maybe with some kind of html/css solution) to make a solid div that, once "reached" by the div above makes it jump to the next free space available on the page?
Any work around?
Thanks in advance
I solved the problem giving the body tag a margin top equal to the header height and a margin bottom equal to the footer height this automatically applies to every page.

Importing legacy html table design into div layout

We are in the process of importing some old pages from our legacy website which was designed in tables into our new DIV based layout. Our site is built on a PHP include system, so we have our pages split into three components; header, body, and footer. These old pages need to be pulled in for our launch of revision 1.0, and then as we get all of the wrinkles ironed out, we will redesign.
Our header component is working out just fine, and the body content displays as it should, but unfortunately the existing footer element plugs into the bottom of the table. Our footer for the new design extends for 100% of the width, but the existing table only allows for 960px width. Thus our footer is getting cut off.
We are trying to find a dynamic solution, either a using JavaScript, or the jQuery Attr() call to dynamically effect the table dimensions to allow the footer to extend to the edge of the page, yet everything I have tried does not modify the table dimensions or allow overfow to show at all.
Here are a couple of screenshots for you to see what I am talking about.
Div layout:
Table Layout:
If you like to take a peek at the code, you can look at my Demo Page, but just know that this is a demo version which is not using PHP to pull in the components. Its a simple HTML/CSS based layout I have been using to search for alternatives. (I'm not a PHP guy)
We are trying to avoid having to go through hundreds of documents and cutting and pasting the footer in below the table, or having to modify any other code by hand. If we could just include a CSS or JavaScript doc in the header that would render a workaround is the ideal solution.
You can also make a div with the footer Background - separate from the contents and underneath. Put a div with the same css styles as 'footer' after your element. Then you can take the background image (footer_bg.jpg repeat-x) off of footer.
See campdavidozarks.org for a website I made with the same idea.
Center the table, and use the same footer-background on the parent, 100% width element, too with alignment to the bottom and no-repeat on y. Done. Pure CSS solution.

Categories