I am using TCPDF and using the writeHTML function to create PDF's like this:
$html = 'html content';
$pdf->writeHTML($html, true, false, true, false, '');
I have sections of content and each section is in a div and table, as the page and content automatically continues over to the next page, sometimes i get a very few lines of my content on one page and the remaining on the next page.
Is there a way in TCPDF, to tell it to make sure that the entire content of a div or table should be together? so if it needs to go to the next page, it should take the entire div to the next page?
Thanks
* UPDATE *
As olger suggested, 'page-break-inside' style attribute seems to work and do the job below:
<div style="page-break-inside:avoid;">
HTML grouped content
</div>
If you don't want breakable text then add this style div or table which you used. Add this style in your code style="page-break-inside:avoid;"
Related
I am printing a dynamic HTML page into pdf using php. I'd like to move a certain "" element from the first page to the last page during printing. I'm using the following css:
.last-page {
page: last_page;
page-break-before: always;
}
and in php I'm adding:
<div class='last-page'></div>
before the element that I want to move to the last page.
I'd like to know the number of pages, so I can add the that number of times. Is there a way I can get the value of css counter(pages) to make a loop or any other way to know how many pages will be in the printed page?
Thanks
I have a dinamically generated HTML content and want to generate a page-numbered PDF using mPDF. The problem is that when the content spans more than one page, the footer is only visible in the last page.
Example:
$mpdf->AliasNbPages('{PAGETOTAL}');
$mpdf->WriteHTML($content); // $content is dynamic, it can be a series of paragraphs resulting in a 3 or 4, or more, pages long pdf.
$mpdf->setFooter('{PAGENO}/{PAGETOTAL}'); // this only prints a footer in the last page, displaying for example "3/3", but the previous pages do not have footer
I want the footer in every page, but i don't know in advance how many pages I will have or where the pagebreaks will be.
Am I doing something wrong?
Try putting setFooter before WriteHTML
So, this way:
$mpdf->setFooter('{PAGENO}/{PAGETOTAL}');
$mpdf->WriteHTML($content);
I am working on PDF generation using the MPDF library into a Drupal 8 project.
I am planning to put the table of contents (TOC) inside a <div> on the first page of my PDF.
For that, I created a <tocentry> tags and put the <tocpagebreak /> into my <div> of the first HTML page.
Unfortunately, the TOC is generated in a new page (i.e., page break is happening before and after the TOC).
How can I generate the TOC within my custom HTML structure and include it into my <div>?
By default the TOC goes at the bottom, but you can modify its position manually.
In mPDF's docs there's a nice example in which the TOC is before the content:
$mpdf = new \Mpdf\Mpdf();
$mpdf->WriteHTML('Introduction');
$mpdf->TOCpagebreak();
$mpdf->TOC_Entry("Chapter 1", 0);
$mpdf->WriteHTML('Chapter 1 ...');
$mpdf->Output();
Notice that TOCpagebreak() is invoked before TOC_Entry (the function that adds the entry to the TOC) and before WriteHTML('Chapter 1 ...'). This latter function adds content to the PDF.
By placing TOCpagebreak() before those functions, you make the TOC appear before the contents.
For more details, see mPDF docs on TOCpagebreak()
I have coded PHP script to generate PDF with text contents using TCPDF library. First, the script gets the contents from database and creates temporary .html file. Then the script gets the contents from the .html file and writes to create PDF document.
However, the problem here is it doesn't know when to break a page. So, it looks something like in the image.
I want the script to break the page when the title comes at the bottom of the page and move it to the next page.
There is a function called $pdf->AddPage(); that breaks the page.
Is there any solution to this? Please help.
Have you tried page-break-after CSS property ? Add this to the DIV which is just above the title. So the style of the above DIV will look something like this.
.DIV_CLASS {
page-break-after: always;
}
The page-break-after property sets whether a page break should occur
AFTER a specified element or not.
always value of the property inserts a page break after the element.
Update:
To make sure your particular section/DIV doesn't get divided between pages. You can make use of page-break-inside property.
Use it like this,
.DIV_CLASS {
page-break-inside: avoid;
}
Above CSS will make sure that DIV with class DIV_CLASS will never get divided among pages.
The page-break-inside property sets whether a page break is allowed
inside a specified element.
avoid value of property avoids page break inside the element (if possible)
I have searched but could not find answer to my satisfaction so
I have a header file, which is being included on top of every page and part of the header is a menu with 3 tabs, when user click on tab browser take them to that page (working fine), what i want is, that what ever tab user clicks to be highlighted(diff back color) when that page is loaded.
Here is html :
<div id="top-choicebar">
<ul id="topmenu">
<li><a href="daily.php" class="ww" >Daily</a></li>
<li>< href="weekly.php" class="ww">Weekly</a></li>
<li>< href="monthly.php" class="ww">Monthly</a></li>
</ul>
<div id="event-menu">
New to php and jquery ... any help will be greatly appriciated
You can do that by means of CSS and conditional classes.
Weekly
Monthly
you can try using something like this, but it's very rudimentary:
<?php if (preg_match("/weekly.php/i", $_SERVER["SCRIPT_NAME"])) {
// Tab should be highlighted
< href="weekly.php" class="ww active">Weekly</a>
} else {
< href="weekly.php" class="ww">Weekly</a>
}
?>
this will add an 'active' class to the link, that you can then style with CSS to change the background colour...
What I've always done in the past is pass a parameter to the class that is building the menu based on what page I'm loading.
So daily.php loads up Header.php and passes it a variable like new Header(0) when Header builds the html, it loops through the links to print them, and on the number that's been passed, it adds a class like current.
So if:
Daily == 0
Weekly == 1
Monthly == 2
The header would pick the correct one to apply the class to based on the page that calls it.
Of course, this would only work if your menu links are being stored somewhere besides raw HTML, like in a database or even just an array.
Have a class setup like .selected{background-color:red} That defines the different background color you want to view. Then when you render the page, since you already know which tab it is, you just render the selected tab with that class attached. If you are rendering the tab content through ajax you can just find all tabs with class "selected" and then add the class to the selected tab
$("#topmenu li").live("click", function()
{
$("#topmenu").find(".selected").removeClass("selected");
$(this).addClass("selected");
});