简体   繁体   中英

PHP HTML to PDF mikehaertl/phpwkhtmltopdf Page Size Issue

I'm currently running mikehaertl/phpwkhtmltopdf package to convert HTML to PDF. Using the demo data I appear to be having issues with the PDF rendering the correct page dimensions. I need the page to be filled with an A4 layout, but I'm getting a much smaller resolution output for some reason. I believe there is either a setting I'm not aware of or I'm missing something in the HTML/CSS?

在此处输入图片说明

The PHP I am running is:

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

The getOrderPrint method is correctly returnin the below 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>

尝试在您的wkhtmltopdf选项中添加'page-size' => 'A4'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM