Text on header not appear in first page (PDF) using FPDF - php

I have a PHP that creates a PDF from DB data using FPDF library.
I use a header for show a title and logo. The logo shows correct in all pages, but the text not appear in the first page, only on others.
I use this function:
function Header() {
$this->SetDrawColor(31,124,14);
$this->Line(10,15,17,15);
$this->Image('someLogo.png',20,10);
$this->Text(100,25,"TITTLE");
$this->Line(50,15,200,15);
$this->Line(200,15,200,20);
$this->Line(10,32,17,32);
$this->Line(50,32,200,32);
$this->Line(200,32,200,27);
$this->Ln(50);
}
The lines draw something like a frame.
Thanks!

Solved. I miss to define typography for header text, then they get it from the table function and shows on next page...
Ty! ;D

Related

mPDF pagination problem when using WriteHTML function

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);

How to push the title of the content to the next page in PDF

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)

Is there any way to put a footnote in MPDF document?

I would like to put a footnote in my PDF, created by MPDF from html. I didn't find any function or tag for that. I tried put notes in footer, changing it by tag, but that was changing footers for all even/odd pages. Maybe is there a way to change footer starting from next page? Then I would change footer with my note text and immediately after change it to standard footer.
$mpdf->SetFooter('{DATE d/m/Y }|{PAGENO}/{nb}|Sym Consultoria');

php-jquery-pdf load a pdf on a div

I'm trying to display by jquery load() a dynamically generated PDF created by PHP with FPDFlib on a div but what I get is a jam of chars. Is there a way to resolve it?
thanks in advance
I've tried to correct my code in this way but continue to display jam
$.post("./php/stampa_login.php",
{piatta:'<? echo $_POST["piatta"] ?>'},
function(data){
$("#stampa_content").load("./temp/login.pdf")
});
ciao
h.
That seems to be correct. jQuery's load() fetches an URL through AJAX; if that URL is PDF, it appears as "jam of chars" to the browser, as PDF and HTML aren't compatible at all, the formats are completely different.
What you probably want is to open the PDF as an <object>, but then you're hoping that the user has some PDF plugin installed in their browser. Let's take a step back: what are you trying to achieve here, by displaying a PDF?
You can create a blank embed tag and give src attribute as link. in your call back function. This will load the pdf file perfectly.
$("#embed_tag_id").attr("src", "./temp/login.pdf");
Instead of using $("#whatever").load();
You'll want something like this:
$("#stampa_content").html ($("<object>", {
data : "./temp/login.pdf",
type : "application/pdf",
width : 800,
height : 600
}));
What that will do is instead of trying to load the contents of the PDF into a DIV, it will create an <object> block that will start up your PDF reader (such as Adobe Reader) which will then load the PDF itself and display it.
ya, seems to be an output issue. Have you tried header function to output it correctly ? try for proper output or instead of opening the pdf in div, just update the pdf's link there

Page break in Html2Pdf

I am in the process of generating a dynamic pdf file, which contains data of around 10,000 users, in general the app is developed using MySQL and PHP. The dynamic content is so heavy that, I found it difficult to process with fpdf() class. So I converted my output PHP page as a HTML file using ob_get_clean(). Now the html file is generated successfully and also the pdf file. But i want to leave a page break after each user's data, that is every user's data must start in a fresh page. I couldn't use any HTML tags because, in the dynamically generated HTML file, everything is out of the <html> and </html> tags. Please help me so that some how i make a page break in the pdf file after every user's data... Thanks in advance :)
html2pdf supports page tag:
protected function _tag_open_PAGE($param) {}
at line 2229. You can see there what attributes are supported. For example following creates one page in landscape and one in portrait mode:
<page orientation="l">
... some content ...
</page>
<page orientation="p">
... some content ...
</page>
Basing on macdabby's work (which doesn't work). But thanks to him, the idea is correct.
Html2Pdf v4.03
For example we want to parse a tag DIV:
html2pdf.class.php line 2948:
protected function _tag_close_DIV($param, $other='div')
{
if ($this->parsingCss->value['page-break-after'] == "always")
$this->_setNewPage(null, '', null, $this->_defaultTop);
$this->parsingCss->setPosition();
...
}
parsingCss.class.php Line 114:
//add a new style declaration
public function initStyle()
{
...
$this->value['page-break-after'] = null;
}
Line 1024 add a new handler to the switch case:
case 'page-break-after':
$this->value[$nom] = $val;
break;
And then for it to work, your html content should contain the break element
<div style="page-break-after:always; clear:both"></div>
Watch out for case sensitive style, not sure if the plugin handle it
i just figured this out after having the same problem. the parser that they use DOES support the page-break-after tag, but the html2pdf does not work.
i think i have it working by doing the following modifications to html2pdf.class:
around line 4174, the first thing inside:
protected function _tag_close_P($param){
should be:
if($this->parsingCss->value['page-break-after'] == "always")
$this->_setNewPage();
around line 2961, the first thing inside:
protected function _tag_close_DIV($param, $other='div'){
should be:
if($this->parsingCss->value['page-break-after'] == "always")
$this->_setNewPage();
You possibly want to use some css, eg:
h1 {page-break-before:always}

Categories