【发布时间】:2017-11-16 09:57:18
【问题描述】:
我有一张名为“Start STP 100”的打印机收据,我的网站使用 mPDF 库创建了一个带有收据格式的 PDF。
以下代码是我生成PDF的类:
class printdoc
{
private $width;
public function __construct()
{
require('mPDF/mpdf.php');
$this->width = 80;
// Default values
$this->mPDF = new mPDF('utf-8', array($this->width, 1000), 9, 'Segoe UI', 5, 5, 0, 0, 5, 5, 'P');
$this->mPDF->setAutoTopMargin = 'pad';
}
public function write($html, $url)
{
$this->mPDF->WriteHTML($html[0]);
$this->mPDF->page = 0;
$this->mPDF->state = 0;
unset($this->mPDF->pages[0]);
$p = 'P';
// At this point the Y size is set according to the dimensions of the PDF
// So the value '1000' set in the __construct() has no effect.
$this->mPDF->_setPageSize(array($this->width, $this->mPDF->y), $p);
foreach($html as $content)
{
$this->mPDF->addPage();
$this->mPDF->WriteHTML($content);
}
$this->mPDF->Output($url);
}
public function create($data)
{
$html = '<html>';
$html .= ' <head></head>';
$html .= ' <body>';
$html .= $this->header($data);
$html .= $this->body($data);
$html .= $this->footer($data);
$html .= ' </body>';
$html .= '</html>';
return $html;
}
}
现在为了创建收据并保存,我有这个功能:
function printreceipt($data)
{
require('printdoc.php');
$file = 'test-receipt.pdf';
$html = $this->printdoc->create($data);
$this->printdoc->write($html, $file);
}
发生的情况是,使用 Chrome PDF 查看器查看时生成的文件具有正确的尺寸(在宽度和高度方面),但在发送到打印机时打印的纸张过多。
基本上这是 PDF 的大小(在浏览器上查看时):
---
| |
| |
| |
---
这是打印时纸张的尺寸:
---
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
---
有什么方法可以强制 mPDF 剪切文件或在我的html 之后写入任何命令以便打印机解释和剪切?
【问题讨论】:
-
在查看 PDF 时,您获得了多少页??
-
你检查过那个吗???
-
@kranthi 只有一页,即使收据的高度为 100 或 500。它是动态的,只创建一个页面。
-
能否请您通过打印html检查一下,是否可以提供HTML和pdf链接???
-
@kranthi 我不明白。你想让我创建一个测试页面并打印随机 HTML 以查看打印机是否切割?