How to fix overlaid text in header with MPDF library

Asked

Viewed 997 times

1

I am having a problem with the header in relation to the body text while generating a PDF.

The header is being overwritten by the body text, how to resolve this?

I’m using the method SetHTMLHeader for the header and the methodWriteHTML for the body text. Is there any way to increase the size reserved for the header with that library, or something else that solves?

My current code:

<?php
session_start();
include('mpdf60/mpdf.php');
$paragrafo = "";
for($x=1;$x<=12;$x++){
    $paragrafo.=$_SESSION['c'.$x]."<br/>";
}
$cabecalho = $_POST['cabecalho'];

$mpdf=new mPDF();
$mpdf->SetDisplayMode('fullpage');

$mpdf->SetHTMLHeader($cabecalho);
$mpdf->WriteHTML($paragrafo);
$mpdf->Output();
exit;?>

How I wanted you to stay:

Simulação da saída desejada

How are you getting:

Saída real, com erro

  • You can put the code here?

  • @Giancarloabelgiulian put here

  • The code that makes up the text is just that?

  • @Diegofelipe put the beginning of the code now

  • this is the complete code of the file that mounts the pdf @Diegofelipe

  • Well, you’re not setting the print position on the page, you’re just having "print" a lot of stuff. It’s not the library that will guess where you want the texts, right?

  • but where do I do it? didn’t understand the documentation of this library @Bacco

  • @Alexandremartinsmontebelo has no example of how to position the information in the documentation? Maybe in one of these answers you have something that can be used (I didn’t read it, it’s just a research suggestion) http://answall.com/search?q=mpdf+is%3Aquestion - Anyway, let’s wait if someone posts an answer that helps. In the meantime, if you can, take a peek at the examples.

  • Looking quickly, it seems to me that when creating the PDF, you can specify the page margins, but I don’t know if this would help. In English there are solutions with CSS, maybe serve as a starting point. http://stackoverflow.com/questions/16538109/change-top-margin-of-second-page-using-mpdf Another thing you might want to do is add the header material to the body of the page. Maybe it’s not the most elegant way.

  • I tried this your second option first, to put everything in the body, only the header text was far below the expected, it looked like part of the body even, not with css solved, I’ll see if it’s right this first solution @Bacco

  • I got it! I changed the parameters when instantiating the mpdf class

  • @Alexandremartinsmontebelo I gave a formatted in your question, but since solved, you can post the solution as answer to your own question, in the field below.

Show 7 more comments

1 answer

1


Got it! Thanks @Bacco for the link! I changed the line to follow:

$mpdf=new mPDF();

for :

$mpdf = new mPDF(
             '',    // mode - default ''
             '',    // format - A4, for example, default ''
             0,     // font size - default 0
             '',    // default font family
             15,    // margin_left
             15,    // margin right
             58,     // margin top    -- aumentei aqui para que não ficasse em cima do header
             0,    // margin bottom
             6,     // margin header
             0,     // margin footer
             'L');  // L - landscape, P - portrait
  • Perfect! I used this too and it worked...

  • Very good! I used it here and it also worked. Thanks!

  • Worked Perfectly!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.