2017-01-05 69 views
0

我正在使用dompdf生成pdf格式的收據,而不是使用RP327 80mm Thermal Receipt Printer打印。但打印的收據不適合紙張。這是打印的收據pos receipt的附加圖像。 這裏是將其轉化爲一個pdf文件使用RP327 80mm熱敏票據打印機打印pdf格式收據

<?php 
ob_clean(); 
$dompdf = new DOMPDF(); 
$dompdf->set_option('default_font', 'Courier'); 

$customPaper = array(0,0,340,650); 
//$dompdf->set_paper($customPaper); 
$dompdf->set_option('enable_css_float',true); 
//$dompdf->set_paper("A3", "portrait"); 

$html =' <html> 
    <head><style> 
     .table { display: table; width: 100%; border-collapse: collapse; } 
     .table-row { display: table-row; } 
     .table-cell { display: table-cell; border: 1px solid black; padding: 1em; } 
    } 
    span { display: block; } 
    @page table { 
     size: 340px 650px; 
     margin: 0px;; 
    } 

    .table { 
     page: table; 
     page-break-after: always; 
     font-size: 20px; 
    } 
    </style> 
    </head> 
    <body> 
    <div class="table"> 
     <div class="table-row"><div class="table-cell" colspan="3" style="text-align: center"><img src="../../img/top-logo.png"></div></div> 
     <div class="table-row"> 
      <div class="table-cell" ><span><b> Merchant: </b> '.$parceldetails['company'].' </span><span><b> Pick Addr: </b> '.$parceldetails['addr'].' </span><span><b> Mobile: </b> '.$parceldetails['mobile'].' </span></div> 
      <div class="table-cell" style="padding: 0px"> 
      <div class="" >Delivery Date:</div><br> 
      <div class="" style="border-bottom: 1px solid #000000"> '.$parceldetails['r_delivery_time'].' at '.$parceldetails['bytime'].'</div> 

      <div class="">Agent:</div><br> 
      <div class=""> '.$parceldetails['name'].' </div> 
      </div> 
     </div> 
     <div class="table-row"> 
      <div class="table-cell" colspan="3" style="text-align: center"> <b style="font-size: larger">'.$ecr.'</b></div> 
     </div> 
     <div class="table-row"> 
      <div class="table-cell" colspan="1"><span><b>Customer Name:</b> '.$parceldetails['r_name'].'</span><span><b> Addr:</b> '.$parceldetails['r_address'].' </span><span><b> Mobile: </b> '.$parceldetails['r_mobile'].' </span></div> 
      <div class="table-cell" style="padding: 0px"> 
       <div class="" style="border-bottom: 2px solid #000000; text-align: center"><b> '.$parceldetails['paymentmethod'].' </b></div> 
       <div class="" style="text-align: center"><b> '.$parceldetails['product_price'].' BDT </b></div> 
      </div> 
     </div> 
     <div class="table-row"> 
      <div class="table-cell" style="text-align: center"> '.genarateQRCode($data).' </div> 
      <div class="table-cell" style="padding: 0px"> 
       <div class="" style="border-bottom: 2px solid #000000; text-align: center; height:63px"> Delivered </div> 
       <div class="" style="text-align: center; min-height:63px"> Cancel </div> 
      </div> 
      <div class="table-cell" style="padding: 0px"> 
       <div class="" style="border-bottom: 2px solid #000000; text-align: center; height:63px">&#160;</div> 
       <div class="" style="text-align: center; min-height:63px""></div> 
      </div> 
     </div> 
     <div class="table-row"> 
      <div class="table-cell" colspan="3"> 
      <b style="margin-top:50px; margin-bottom:-10px; border-bottom: 1px solid #000000; font-size:10px; margin-left:10px">Agent signature</b> 
      <b style="margin-top:50px; margin-bottom:-10px; border-bottom: 1px solid #000000; font-size:10px; margin-left:50px">Receiver signature</b></div> 
     </div> 
     </div>'; 
     $html .='<table class="table"> 
     <tr> 
     <td colspan="3"><img src="../../img/top-logo.png"></td> 
     </tr> 
     <tr> 
     <td rowspan="2" colspan="2"><span><b> Merchant: </b> '.$parceldetails['company'].' </span><span><b> Pick Addr: </b> '.$parceldetails['addr'].' </span><span><b> Mobile: </b> '.$parceldetails['mobile'].' </span></td> 
     <td>D. Date<span>'.$parceldetails['r_delivery_time'].'</span></td> 
     </tr> 
     <tr> 
     <td>Agent<span>'.$parceldetails['name'].'</span></td> 
     </tr> 
     <tr> 
     <td colspan="3">'.$ecr.'</td> 
     </tr> 
     <tr> 
     <td rowspan="2" colspan="2"><span><b>Customer Name:</b> '.$parceldetails['r_name'].'</span><span><b> Addr:</b> '.$parceldetails['r_address'].' </span><span><b> Mobile: </b> '.$parceldetails['r_mobile'].' </span></td> 
     <td><b>'.$parceldetails['paymentmethod'].'</b></td> 
     </tr> 
     <tr> 
     <td><b>'.$parceldetails['product_price'].' BDT</b></td> 
     </tr> 
     <tr> 
     <td rowspan="2" colspan="1">'.genarateQRCode($data).'</td> 
     <td>Delivered</td> 
     <td></td> 
     </tr> 
     <tr> 
     <td>Cancel</td> 
     <td></td> 
     </tr> 
     <tr> 
     <td colspan="3">&nbsp</td> 
     </tr> 
     <tr> 
     <td colspan="3">Agent Signature Receiver Signature</td> 
     </tr> 
    </table> 
    </body> 
    </html>'; 
$dompdf->load_html($html); 
$dompdf->render(); 
$dompdf->stream("dompdf_out.pdf", array('Attachment' => 0)); 
<?> 

回答

0

根據連鎖打印機規格的打印機能夠打印的要麼72毫米或64毫米的寬度我的HTML表格。這意味着大約分別爲204分和181分。而不是依靠更大的紙張大小和限制您的內容寬度,我會努力在你有限制的範圍內工作。

您還應該記住,dompdf會根據爲您的文檔指定的DPI將基於像素的測量值轉換爲適當的點大小。如果你想在你的HTML文件和渲染的PDF之間建立一對一的對應關係,你應該將Dompdf DPI設置爲72,因爲PDF PPI固定爲72.

考慮到這一點,這裏是我的建議。我假設你正在使用基於方法調用的Dompdf 0.6.x。

  1. 適當設置您的紙張尺寸。假設您有72毫米寬的紙張。

    $dompdf->set_paper(array(0,0,204,650)); 
    
  2. 如果你要使用的佈局的表,那麼你應該只是繼續使用表元素設置你的DPI

    $dompdf->set_option('dpi', 72); 
    
  3. 。使用表格顯示類型對DIV進行造型只會導致它們被視爲表格元素。你有什麼可以正常工作,但是如果你只是使用表格元素,你會發現怎麼回事。

  4. 知道,DOMPDF是相對於表有點古怪。有一點要記住的是,DOMPDF不允許表格單元格比所包含的內容更小(爲正常流動的內容)。


很難給出爲什麼打印機切斷內容的任何輸入。我建議清理你的代碼。我只注意到你有相同的內容兩次,一次是爲的DIV風格是表元素和第二次作爲一個實際的表。

+0

謝謝。我已經解決了這個問題。 –