首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PHP HTML to PDF mikehaertl/phpwkhtmltopdf页面大小问题

PHP HTML to PDF mikehaertl/phpwkhtmltopdf页面大小问题
EN

Stack Overflow用户
提问于 2016-12-19 05:55:39
回答 1查看 1.5K关注 0票数 2

我目前正在运行mikehaertl/phpwkhtmltopdf包将HTML转换为PDF。使用演示数据时,我似乎遇到了PDF呈现正确页面尺寸的问题。我需要用A4布局填充页面,但由于某些原因,我得到的分辨率输出要小得多。我认为要么是我没有意识到的设置,要么是我在HTML/CSS中遗漏了什么?

我正在运行的PHP是:

代码语言:javascript
复制
$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方法:

代码语言:javascript
复制
<!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>
EN

回答 1

Stack Overflow用户

发布于 2016-12-23 02:08:21

尝试将'page-size' => 'A4'添加到wkhtmltopdf选项中。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41213300

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档