【问题标题】:html2pdf adjust page sizehtml2pdf 调整页面大小
【发布时间】:2012-02-01 07:21:15
【问题描述】:

我的 html2pdf 很好地工作,可以将 pdf 附加到电子邮件 但是,我需要将页面宽度调整为 606px 我可以在 html 中执行此操作,但 html 是 606px,而 pdf 本身是 portait 中的标准字母宽度。 有什么方法可以将文档限制为我需要的宽度? 谢谢

标记

【问题讨论】:

  • AFAICT 你不能用 HTML2PDF 做到这一点,但是你可以用 mPDF mpdf1.com

标签: html2pdf


【解决方案1】:

这里是这个问题的解决方案:

$html2pdf = new HTML2PDF('P', array($width_in_mm,$height_in_mm), 'en', true, 'UTF-8', array(0, 0, 0, 0));

宽度和高度应以 MM 为单位。如果您使用英寸将其转换为 MM。

公式:

$width_in_mm = $width_in_inches * 25.4; 
$height_in_mm = $height_in_inches * 25.4;

不要四舍五入。使用精确的转换,即使它有小数点。

希望这个答案能解决你的问题。

【讨论】:

    【解决方案2】:

    在构建 HTML2PDF 时,您可以更改 PDF 的输出以更适合您的目的。

    http://www.prepressure.com/library/paper-sizes

    以下是一些兼容的页面尺寸。

    【讨论】:

      【解决方案3】:

      HTML2PDF 类的构造函数

      public function __construct($orientation = 'P', $format = 'A4', $langue='fr', $unicode=true, $encoding='UTF-8', $marges = array(5, 5, 5, 8))
      {
      

      通过定义页面大小来调整 $format 变量

      $format =array('user_defined_height','user_defined_width'); //for user-defined sizes accepts only in millimeter
      

      在你的情况下 606px = 160.3375mm

      $format =array('160.3375','160.3375');

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-10-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-05-20
        相关资源
        最近更新 更多