Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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");
like image 746
sjkon Avatar asked Feb 26 '13 08:02

sjkon


3 Answers

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;
}
like image 90
codepushr Avatar answered Nov 05 '22 06:11

codepushr


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.

like image 36
Reyhan Sofian Haqqi Avatar answered Nov 05 '22 06:11

Reyhan Sofian Haqqi


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);
like image 1
cscthian Avatar answered Nov 05 '22 05:11

cscthian