如何使用HTML2PDF设置横向方向

问题描述 投票:8回答:3

如何将通过HTML2PDF生成的pdf文件的页面方向更改为横向...?默认情况下,它以纵向格式打开。我在html2pdf.class中更改了它,但没有任何改变。请帮帮我..

这是php代码:

 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");
php html pdf html2pdf
3个回答
3
投票

使用L作为构造函数参数应该可以正常工作。不要乱搞班级内部。

这是我唯一的代码,它工作正常。尝试使用最新版本: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;
}

2
投票

或者您可以在标签上添加方向。

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

查看http://demo.html2pdf.fr/examples/pdf/exemple04.pdf了解更多示例。


-1
投票

这个解决方案也非常好,它在文档中:

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);
© www.soinside.com 2019 - 2024. All rights reserved.