2016-12-04 78 views
0

打印我生成條碼在我application.There一些問題,打印條碼,並導出PDF file.In這種情況下,條形碼不打印版或PDF file.I顯示有使用angularjs js通過指令生成barCod。如何使用條形碼JavaScript或出口條形碼在PDF

這裏是我的JavaScript

$scope._printBarCode = function (printSectionId) { 

    var innerContents = document.getElementById(printSectionId).innerHTML; 
    var popupWinindow = window.open();//'', '_blank'); 
    popupWinindow.document.open(); 
    popupWinindow.document.write('<html><head><link rel="stylesheet" type="text/css" href="Content/assets/css/barCode.css" /></head><body onload="window.print()">' + innerContents + '</html>'); 
    popupWinindow.document.close(); 

} 

,這裏是我的html

    <input type="button" value="Prnt" ng-click="_printBarCode('barCodeId')" class="btn btn-primary" /> 
          <div class="barcodeplace"> 
           <div class="col-sm-12"> 
            <div barcode-generator="{{_barCodeGeneraterId}}" style="height:20px;"> 
           </div> 
          </div> 
          </div> 

回答

1

您需要包括與否則會在被忽略所有的媒體類型,在新窗口中的CSS打印。另外,如果瀏覽器不打印條形碼,默認情況下會禁用打印背景圖像。您可以更改Chrome瀏覽器的CSS,以覆蓋此設置。但是,在IE中,用戶需要從工具 - >打印 - >頁面設置中更改頁面設置選項。

添加$超時服務,您的控制器和改變_printBarCode功能如下:

.controller('MyCtrl', function($scope,$timeout) { 
$scope._printBarCode = function(printSectionId) { 

    var innerContents = document.getElementById(printSectionId).innerHTML; 
    var popupWindow = window.open('', 'Print'); 

    popupWindow.document.write('<!DOCTYPE html><html><head><style type="text/css">@media print { body { -webkit-print-color-adjust: exact; } }</style><link rel="stylesheet" type="text/css" href="barcode.css" media="all" /></head><body> ' + innerContents + '</body></html>'); 
    $timeout(function() { 
     popupWindow.focus(); 
     popupWindow.print(); 
     popupWindow.close(); 
    }); 
}; 

然後在你的HTML你的NG-點擊需要引用的頁面上的元素的ID:

<input type="button" value="Prnt" ng-click="_printBarCode('barCodeId')" class="btn btn-primary" /> 
<div id="barCodeId" class="barcodeplace"> 
    <div class="col-sm-12"> 
     <div barcode-generator="{{_barCodeGeneraterId}}" style="height:20px;"> 
     </div> 
    </div> 
</div> 
+0

感謝您的寶貴時間。這個代碼運行不好,我有同樣的問題.barCode不打印。請問我可以在jsfiddle示例中顯示這個示例 – Sundar

+0

https://plnkr.co/edit/ e0KZY0olmjM6PXZzTceQ?p =預覽 – jtsnr

+0

謝謝你這麼多jtsnr – Sundar