How to set landscape orientation using HTML2PDF
Asked Answered
I

3

9

How to change the page orientation of pdf file generated via HTML2PDF to landscape...? By default, it is opening as Portrait format. I have changed it in html2pdf.class, but nothing changed.Please help me..

This is the php code:

 require('../../includes/html2pdf/html2fpdf.php');
    $pdf=new HTML2FPDF('L','mm','A3');
    $pdf->AddPage();
    $pdf->setFont("arial",'',8);
    $pdf->WriteHTML($data);
    $pdf->Output("outstanding.pdf","I");
Innkeeper answered 26/2, 2013 at 8:16 Comment(1)
have you solved this?Germin
B
5

Using L as the constructor parameter should work just fine. Don't mess with the class internals.

This is my only code and it works fine. Try using the newest release: HTML2PDF.

// convert to PDF
require_once('../../vendor/html2pdf_v4.03/html2pdf.class.php');
try
{
    $html2pdf = new HTML2PDF('L', 'A4', 'en');
    $html2pdf->setDefaultFont('Arial');
    $html2pdf->writeHTML($html, false);
    $html2pdf->Output('output.pdf', 'D');
}
catch(HTML2PDF_exception $e) {
    echo $e;
    exit;
}
Binucleate answered 11/7, 2013 at 18:30 Comment(0)
A
2

Or you can add orientation on tag.

<page orientation="landscape" format="A5" > Landscape </page>

Check out http://demo.html2pdf.fr/examples/pdf/exemple04.pdf for more example.

Althorn answered 4/6, 2014 at 3:10 Comment(0)
E
2

This solution also is very good and it's in the documentation:

var element = document.getElementById('element-to-print');
var opt = {
  margin:       1,
  filename:     'myfile.pdf',
  image:        { type: 'jpeg', quality: 0.98 },
  html2canvas:  { scale: 2 },
  jsPDF:        { unit: 'in', format: 'letter', orientation: 'portrait' }
};

// New Promise-based usage:
html2pdf().set(opt).from(element).save();

// Old monolithic-style usage:
html2pdf(element, opt);
Endear answered 22/4, 2019 at 18:0 Comment(1)
Please try to translate your answer to English, so that everyone can benefit from it.Fluviomarine

© 2022 - 2024 — McMap. All rights reserved.