【问题标题】:PHP mPDF with cut command - printing too much paper带有剪切命令的 PHP mPDF - 打印太多纸张
【发布时间】: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 以查看打印机是否切割?

标签: php pdf mpdf


【解决方案1】:

似乎 Start STP 100 的 Google Chrome 存在一个错误,该错误会产生额外的纸张。 使用 firefox 解决了这个问题。

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-24
    相关资源
    最近更新 更多