sjkon
sjkon

Reputation: 633

How to set landscape orientation using HTML2PDF

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

Upvotes: 9

Views: 36588

Answers (3)

Reyhan Sofian Haqqi
Reyhan Sofian Haqqi

Reputation: 57

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.

Upvotes: 2

cscthian
cscthian

Reputation: 51

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

Upvotes: 2

user986408
user986408

Reputation:

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

Upvotes: 5

Related Questions