Javascript 更改 mPDF 上的页面大小并使浏览器自动打印显示的 PDF 文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4332016/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 11:56:48  来源:igfitidea点击:

Changing page size on mPDF and getting browser to auto print PDF file on display

phpjavascript

提问by methuselah

I am using mPDF (http://mpdf.bpm1.com) to create pdf receipts, but at the moment they only display on a full A4 page.

我正在使用 mPDF ( http://mpdf.bpm1.com) 创建 pdf 收据,但目前它们只显示在完整的 A4 页面上。

I would like to resize them down to a reasonable size because we are using a epson tm-t88iv. This is the first dilemma I have.

我想将它们缩小到合理的大小,因为我们使用的是 epson tm-t88iv。这是我遇到的第一个困境。

The second problem I have involves invoking auto print on the printer attached.

我遇到的第二个问题涉及在连接的打印机上调用自动打印。

I would like to do this when the form is processed (on the same page).

我想在处理表单时执行此操作(在同一页面上)。

But I'm not sure how to implement this into the code I have right now:

但我不确定如何将其实现到我现在拥有的代码中:

  <?php 

// post

$id = $_GET['id'];
$user = $_GET['user'];
$week = $_GET['week'];
$pRent = $_GET['pRent'];
$rentPaid = $_GET['rentPaid'];
$result = $_GET['result'];
$pDate = date("d/m/Y");

$html = '

<style>
@page {
 margin-top: 20px;
 margin-left: 20px;
}
</style>

<div style="text-align:center; font-family: Arial, Helvetica, sans-serif;">
        <div style="border: 0px; padding: 0px; width: 175px; text-align:center;">
        <img src="resources/speedline.png" width="161" height="58" />
        <p style="font-weight: bold;" align="center">
        DRIVER '.$id.' RECEIPT</p>    
  <p style="font-size: 12px; font-family: Arial, Helvetica, sans-serif;">'.$week.'</p>
    <span style="font-size: 10px;">PROCESSED BY '.$user.'</span><p>
          <table width="100%" border="0" cellspacing="0" cellpadding="0" >
  <tr>
    <td align="left" style="font-weight: bold; font-family: Arial, Helvetica, sans-serif;">DATE PAID</td>
    <td style="font-size: 12px; font-family: Arial, Helvetica, sans-serif;" align="right">'.$pDate.'</td>
  </tr>
  <tr>
    <td align="left"></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td align="left" style="font-weight: bold; font-family: Arial, Helvetica, sans-serif;">TOTAL RENT</td>
    <td style="font-size: 12px; font-family: Arial, Helvetica, sans-serif;" align="right">£'.$pRent.'</td>
  </tr>
  <tr>
    <td align="left" style="font-weight: bold; font-family: Arial, Helvetica, sans-serif;">RENT PAID</td>
    <td style="font-size: 12px; font-family: Arial, Helvetica, sans-serif;" align="right">£'.$rentPaid.'</td>
  </tr>
  <tr>
    <td align="left">&nbsp;</td>
    <td></td>
  </tr>
  <tr>
    <td align="left" style="font-weight: bold; font-family: Arial, Helvetica, sans-serif;">REMAINING</td>
    <td align="right" style="font-family: Arial, Helvetica, sans-serif;">£'.$result.'</td>
  </tr>
</table>
<br />
<span style="font-size:8px">THANK YOU FOR YOUR PAYMENT. PLEASE KEEP THIS RECEIPT FOR FUTURE REFERENCE. YOU WILL BE ASKED TO PRESENT IT AS EVIDENCE OF PAYMENT MADE.</span>
  </div>';

//==============================================================
//==============================================================
//==============================================================
include("mpdf/mpdf.php");
$mpdf=new mPDF('UTF-8-s','');
$mpdf->WriteHTML($html);
$mpdf->Output();
exit;
//==============================================================
//==============================================================
//==============================================================
//==============================================================
//==============================================================
?>

回答by mozgras

Try: $mpdf = new mPDF('', 'Letter', 0, '', 12.7, 12.7, 14, 12.7, 8, 8);

试试: $mpdf = new mPDF('', 'Letter', 0, '', 12.7, 12.7, 14, 12.7, 8, 8);

and adjust the values at the end for the margins you want. Check out their documentation

并调整最后的值以获得所需的边距。查看他们的文档

Sorry, not sure about auto printing, but there is some info here

对不起,不知道自动打印,但有一些信息在这里