php 如何使用 HTML2PDF 设置横向

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15084329/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 08:32:03  来源:igfitidea点击:

How to set landscape orientation using HTML2PDF

phphtmlpdfhtml2pdf

提问by sjkon

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..

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

This is the php code:

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

采纳答案by codepushr

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

使用L作为构造函数的参数应该只是罚款。不要弄乱类的内部结构。

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

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

回答by Reyhan Sofian Haqqi

Or you can add orientation on tag.

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

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

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

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

回答by Thiancsc

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