我在我的application.There中生成了application.There中的一些问题,比如打印barCode和导出pdf file.In --这是barCode没有显示在打印或pdf文件中的情况,我使用angularjs js指令生成barCod。
这是我的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>发布于 2016-12-04 15:42:49
您需要在新窗口中包含CSS和媒体类型为all,否则它将在打印中被忽略。此外,浏览器没有打印条形码时也会出现问题,因为默认情况下,它们会禁用打印背景图像。您可以更改Chrome的CSS,这样它就可以覆盖这个。但是,在IE中,用户需要从工具->Print-> page setup中更改他们的页面设置选项。
将$timeout服务添加到控制器中,并按如下方式更改_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>https://stackoverflow.com/questions/40957436
复制相似问题