PHP 带有剪切命令的 mPDF - 打印太多纸张
PHP mPDF with cut command - printing too much paper
我有一张名为 "Start STP 100" 的打印机收据,我的网站使用 mPDF 库创建了一个带有收据格式的 PDF。
下面的代码是我class生成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
之后剪切文件或写任何命令以便打印机解释和剪切?
Start STP 100 似乎有一个错误 Google Chrome 会创建额外的文件。
使用 firefox 解决了这个问题。
Please note that the preview for receipts from a Star printer is almost always wrong, showing an extremely long run of receipt paper. Please disregard this, you will be safe to print.
我有一张名为 "Start STP 100" 的打印机收据,我的网站使用 mPDF 库创建了一个带有收据格式的 PDF。
下面的代码是我class生成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
之后剪切文件或写任何命令以便打印机解释和剪切?
Start STP 100 似乎有一个错误 Google Chrome 会创建额外的文件。 使用 firefox 解决了这个问题。
Please note that the preview for receipts from a Star printer is almost always wrong, showing an extremely long run of receipt paper. Please disregard this, you will be safe to print.