带有剪切命令的PHP mPDF - 打印太多纸张



我有一张名为"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 Viewer查看时生成的文件具有正确的尺寸(在宽度和高度方面(,但是当发送到打印机时,它会打印太多纸张。

基本上这是PDF的大小(在浏览器上查看时(:

 ---
|   |
|   |
|   |
 ---

这是打印时纸张的大小:

 ---
|   |
|   |
|   |
|   |
|   |
|   |
|   |
|   |
|   |
|   |
 ---

有没有办法强制mPDF剪切文件或在我html后编写任何命令,以便打印机解释和剪切?

似乎Start STP 100在Google Chrome中有一个错误,该错误创建了额外的纸张。使用火狐解决了这个问题。

请注意,来自 Star 打印机的收据预览几乎总是错误的,显示的收据纸张非常长。请忽略这一点,您将可以安全地打印。

https://www.websitesupport.info/hc/en-us/articles/205959070-Setting-Up-Chrome-For-Windows-To-Print-From-The-Rain-Point-Of-Sale

最新更新