【问题标题】:PHP HTML to PDF mikehaertl/phpwkhtmltopdf Page Size IssuePHP HTML 到 PDF mikehaertl/phpwkhtmltopdf 页面大小问题
【发布时间】:2017-05-03 22:57:18
【问题描述】:

我目前正在运行 mikehaertl/phpwkhtmltopdf 包来将 HTML 转换为 PDF。使用演示数据,我似乎遇到了 PDF 呈现正确页面尺寸的问题。我需要用 A4 布局填充页面,但由于某种原因,我得到的分辨率输出要小得多。我相信有一个我不知道的设置,或者我在 HTML/CSS 中遗漏了一些东西?

我正在运行的 PHP 是:

$pdf = new mikehaertl\wkhtmlto\Pdf(
                    array(
                    'binary' => '/usr/local/bin/wkhtmltopdf',
                        'no-outline',         // Make Chrome not complain
                            'margin-top'    => 0,
                            'margin-right'  => 0,
                            'margin-bottom' => 0,
                            'margin-left'   => 0,

                            // Default page options
                            'disable-smart-shrinking'

                )
                );
                $pdf->addPage($this->getOrderPrint($objectId));


// Save the PDF
                $pdf->saveAs(dirname(__FILE__).'/test.pdf');

getOrderPrint 方法在以下 HTML 中正确返回:

<!DOCTYPE html>
<head>

  <style type="text/css">
    body {
      margin:     0;
      padding:    0;
      width:      21cm;
      height:     29.7cm;
    }

    /* Printable area */
    #print-area {
      position:   relative;
      top:        1cm;
      left:       1cm;
      width:      19cm;
      height:     27.6cm;

      font-size:      10px;
      font-family:    Arial;
    }

    #header {
      height:     3cm;

      background: #ccc;
    }
    #footer {
      position:   absolute;
      bottom:     0;
      width:      100%;
      height:     3cm;

      background: #ccc;
    }
  </style>
</head>
<body>

<div id="print-area">
  <div id="header">
    This is an example headernbmv.
  </div>
  <div id="content">
    <h1>Demo</h1>
    <p>This is example content</p>
  </div>
  <div id="footer">
    This is an example footer.
  </div>
</div>

</body>
</html>

【问题讨论】:

    标签: php html pdf wkhtmltopdf


    【解决方案1】:

    尝试将'page-size' =&gt; 'A4' 添加到您的 wkhtmltopdf 选项中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-07
      • 1970-01-01
      • 2013-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多