dareway-rui
Version:
92 lines (80 loc) • 2.96 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', {
value: true
});
exports.initializePrintEnviroment = initializePrintEnviroment;
exports.isPrinterExist = isPrinterExist;
exports.convertHtmlToBePrinted_To_HtmlToPreview = convertHtmlToBePrinted_To_HtmlToPreview;
/*打印环境初始化*/
function initializePrintEnviroment(printerName, printDirection, LODOP) {
if (printerName === '' || typeof printerName === 'undefined') {
printerName = -1; // 使用系统默认打印机
}
if (printDirection === '' || typeof printDirection === 'undefined') {
printDirection = 0; // 使用默认的打印方向
}
LODOP.PRINT_INITA(0, 0, '100%', '100%', '打印任务名');
LODOP.SET_PRINT_STYLE('Alignment', 1);
LODOP.SET_PRINTER_INDEXA(printerName);
LODOP.SET_PRINT_PAGESIZE(printDirection, 0, 0, '');
return LODOP;
}
/* 判定指定的打印机是否存在*/
function isPrinterExist(printerName, printerMap) {
for (var key in printerMap) {
if (printerMap[key] === printerName) {
return true;
}
}
return false;
}
function replaceAll(str, aFindText, aRepText) {
var char = null,
charArr = [],
specialCharMap = {
'(': '\\(',
'[': '\\[',
'{': '\\{',
'^': '\\^',
$: '\\$',
'|': '\\|',
')': '\\)',
'?': '\\?',
'*': '\\*',
'.': '\\.'
};
str = str || '';
for (var i = 0; i < aFindText.length; i++) {
char = aFindText.substr(i, 1);
if (char in specialCharMap) {
charArr.push(specialCharMap[char]);
} else {
charArr.push(char);
}
}
return str.replace(new RegExp(charArr.join(''), 'gmi'), aRepText);
}
function convertHtmlToBePrinted_To_HtmlToPreview(htmlToBePrinted) {
var lastChpg = null;
var temphtmlPreview = null;
var htmlPreview =
"<div style='position:relative;overflow:auto;height:100%;white-space:nowrap;background-color:transparent;text-align:left;border:none;' >" +
htmlToBePrinted +
'</div>';
htmlPreview = replaceAll(htmlPreview, '<a name="JR_PAGE_ANCHOR_0_1"></a>', '*******The first*****Page');
htmlPreview = replaceAll(
htmlPreview,
'<a name="JR_PAGE_ANCHOR',
'<p style="page-break-after:always"> </p><a name="JR_PAGE_ANCHOR'
);
htmlPreview = htmlPreview.replace('*******The first*****Page', '<a name="JR_PAGE_ANCHOR_0_1"></a>');
lastChpg = htmlPreview.lastIndexOf('<p style="color:#fff;page-break-after:always">');
temphtmlPreview = htmlPreview.substring(lastChpg);
temphtmlPreview = temphtmlPreview.replace(
'<p style="color:#fff;page-break-after:always">',
'<p style="color:#fff;">'
);
htmlPreview = htmlPreview.substring(0, lastChpg) + temphtmlPreview;
return htmlPreview;
}
//@ sourceMappingURL=utils.js.map