fastlion-amis
Version:
一种MIS页面生成工具
465 lines (464 loc) • 30.1 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.filePrint = exports.labelPrint = exports.billPrint = exports.formPrint = exports.detailPrint = exports.templateDesign = exports.getPrinterPageSizes = exports.getPrinters = void 0;
var LodopFuncs_1 = require("./LodopFuncs");
var js_base64_1 = require("js-base64");
function default_1() { }
exports.default = default_1;
// 由于getLodop()获取的LODOP是同一个对象,因此LODOP.On_Return重复赋值会被覆盖掉
// 所以将每次打印赋给On_Return的函数依次放到printCallbackArr里,(LODOP的打印任务是依次执行),每次取第一个数组的第一个函数执行
// 当当前任务的打印数达到目标后,删除对应的函数(数组第一个),此时第二个元素变成第一个,再赋值给On_Return
// var printCallbackArr: any[] = []
function new_eval(str) {
var fn = Function;
return new fn(str)();
}
// 获取系统打印机设备信息
function getPrinters() {
var LODOP = (0, LodopFuncs_1.getLodop)();
// 获取系统打印设备数量
var count = LODOP.GET_PRINTER_COUNT();
var printers = [];
for (var i = 0; i < count; i++) {
printers.push(LODOP.GET_PRINTER_NAME(i));
}
return printers;
}
exports.getPrinters = getPrinters;
function getPrinterPageSizes(printer) {
var LODOP = (0, LodopFuncs_1.getLodop)();
return LODOP.GET_PAGESIZES_LIST(printer, ',').split(',');
}
exports.getPrinterPageSizes = getPrinterPageSizes;
function templateDesign(rowData, onCompleted) {
var LODOP = (0, LodopFuncs_1.getLodop)();
var tempContent = rowData.TEMP_CONTENT, width = rowData.WIDTH, height = rowData.HEIGHT;
LODOP.PRINT_INITA(0, 0, width + "mm", height + "mm", 'design');
if (tempContent) {
var temp = (0, js_base64_1.decode)(tempContent); // 解码base64
// 保存模板包括了初始化
// 将初始化语句分离出来
var initalSentenceIndex = temp.indexOf(';');
// 将初始化语句分离后的剩余的模板语句
var restSentence = temp.substring(initalSentenceIndex + 1);
new_eval(restSentence);
}
LODOP.PRINT_DESIGN();
LODOP.On_Return = function (_taskId, value) {
onCompleted((0, js_base64_1.encode)(value));
};
}
exports.templateDesign = templateDesign;
var detailPrint = function (preview, settings, template, onCompleted) {
var _a, _b, _c, _d, _e, _f, _g;
var iframe = document.getElementById('dom-print-container');
var printerName = settings.printer, width = settings.width, height = settings.height, direction = settings.direction, copies = settings.copies, _h = settings.scale, scale = _h === void 0 ? 100 : _h;
var logo = template.logo, code = template.code, codeLabel = template.codeLabel, extraTitle = template.extraTitle, title = template.title, subTitle1 = template.subTitle1, subTitle2 = template.subTitle2, subTitle3 = template.subTitle3, html = template.html, footer = template.footer, date = template.date, printer = template.printer, sum = template.sum, num = template.num;
var LODOP = (0, LodopFuncs_1.getLodop)();
LODOP.PRINT_INIT('report');
LODOP.SET_PRINT_PAGESIZE(direction == 'vertical' ? 1 : 2, width * 10, height * 10, 'CreateCustomPage');
LODOP.NEWPAGEA();
// header LODOP.ADD_PRINT_RECT(`${header.top}mm`, `${header.left}mm`, `${header.width}mm`, `${header.height}mm`, 0, 1)
LODOP.ADD_PRINT_IMAGE(logo.top * (scale / 100) + "mm", logo.left + "mm", logo.width * (scale / 100) + "mm", logo.height * (scale / 100) + "mm", logo.content);
LODOP.SET_PRINT_STYLEA(0, "Stretch", 1);
LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
if (code.content) {
// LODOP.ADD_PRINT_RECT(`${code.top}mm`, `${code.left}mm`, `${code.width}mm`, `${code.height}mm`, 0, 1)
LODOP.ADD_PRINT_BARCODE(code.top + "mm", code.left + "mm", code.width + "mm", code.height + "mm", code.codeType, code.content);
if (code.codeType == 'QRCode') {
LODOP.SET_PRINT_STYLEA(0, "ScalX", 1.15);
LODOP.SET_PRINT_STYLEA(0, "ScalY", 1.15);
}
LODOP.SET_PRINT_STYLEA(0, "ShowBarText", 0);
LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
// LODOP.ADD_PRINT_RECT(`${codeLabel.top}mm`, `${codeLabel.left}mm`, `${codeLabel.width}mm`, `${codeLabel.height}mm`, 0, 1)
LODOP.ADD_PRINT_TEXT(codeLabel.top + "mm", codeLabel.left + "mm", codeLabel.width + "mm", codeLabel.height + "mm", codeLabel.content);
LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
}
// rightTilte LODOP.ADD_PRINT_RECT(`${extraTitle.top}mm`, `${extraTitle.left}mm`, `${extraTitle.width}mm`, `${extraTitle.height}mm`, 0, 1)
LODOP.ADD_PRINT_TEXT(extraTitle.top * (scale / 100) + "mm", extraTitle.left + "mm", extraTitle.width + "mm", extraTitle.height * (scale / 100) + "mm", extraTitle.content);
LODOP.SET_PRINT_STYLEA(0, "Alignment", 3);
LODOP.SET_PRINT_STYLEA(0, "FontSize", 12);
LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
// title LODOP.ADD_PRINT_RECT(`${title.top}mm`, `${title.left}mm`, `${title.width}mm`, `${title.height}mm`, 0, 1)
LODOP.ADD_PRINT_TEXT(title.top * (scale / 100) + "mm", title.left + "mm", title.width + "mm", title.height * (scale / 100) + "mm", title.content);
LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);
LODOP.SET_PRINT_STYLEA(0, "FontSize", 12 * (scale / 100));
LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
// subtitle LODOP.ADD_PRINT_RECT(`${subTitle.top}mm`, `${subTitle.left}mm`, `${subTitle.width}mm`, `${subTitle.height}mm`, 0, 1)
// LODOP.ADD_PRINT_RECT(`${subTitle1.top}mm`, `${subTitle1.left}mm`, `${subTitle1.width}mm`, `${subTitle1.height}mm`, 0, 1)
LODOP.ADD_PRINT_TEXT(subTitle1.top + "mm", subTitle1.left + "mm", subTitle1.width + "mm", subTitle1.height + "mm", (_a = subTitle1.content) !== null && _a !== void 0 ? _a : '');
LODOP.SET_PRINT_STYLEA(0, "FontSize", 10);
LODOP.SET_PRINT_STYLEA(0, "Alignment", subTitle2.width == 0 && subTitle3.width == 0 ? 3 : 1);
LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
// LODOP.ADD_PRINT_RECT(`${subTitle2.top}mm`, `${subTitle2.left}mm`, `${subTitle2.width}mm`, `${subTitle2.height}mm`, 0, 1)
LODOP.ADD_PRINT_TEXT(subTitle2.top + "mm", subTitle2.left + "mm", subTitle2.width + "mm", subTitle2.height + "mm", (_b = subTitle2.content) !== null && _b !== void 0 ? _b : '');
LODOP.SET_PRINT_STYLEA(0, "FontSize", 10);
LODOP.SET_PRINT_STYLEA(0, "Alignment", subTitle3.width == 0 ? 3 : 2);
LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
// LODOP.ADD_PRINT_RECT(`${subTitle3.top}mm`, `${subTitle3.left}mm`, `${subTitle3.width}mm`, `${subTitle3.height}mm`, 0, 1)
LODOP.ADD_PRINT_TEXT(subTitle3.top + "mm", subTitle3.left + "mm", subTitle3.width + "mm", subTitle3.height + "mm", (_c = subTitle3.content) !== null && _c !== void 0 ? _c : '');
LODOP.SET_PRINT_STYLEA(0, "FontSize", 10);
LODOP.SET_PRINT_STYLEA(0, "Alignment", 3);
LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
// LODOP.ADD_PRINT_RECT(`${html.top}mm`, `${html.left}mm`, `${html.width}mm`, `${html.height}mm`, 0, 1)
LODOP.ADD_PRINT_HTM(html.top + "mm", html.left + "mm", html.width + "mm", html.height + "mm", (_e = (_d = iframe === null || iframe === void 0 ? void 0 : iframe.contentWindow) === null || _d === void 0 ? void 0 : _d.document.documentElement.innerHTML) !== null && _e !== void 0 ? _e : 'iframe error');
LODOP.ADD_PRINT_RECT(footer.top - 2 + "mm", footer.left + "mm", footer.width + "mm", "" + 0.3, 0, 1);
LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
// LODOP.ADD_PRINT_RECT(`${date.top}mm`, `${date.left}mm`, `${date.width}mm`, `${date.height}mm`, 0, 1)
LODOP.ADD_PRINT_TEXT(date.top + "mm", date.left + "mm", date.width + "mm", date.height * (scale / 100) + "mm", (_f = date.content) !== null && _f !== void 0 ? _f : '');
LODOP.SET_PRINT_STYLEA(0, "FontSize", 10 * (scale / 100));
LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);
LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
// LODOP.ADD_PRINT_RECT(`${printer.top}mm`, `${printer.left}mm`, `${printer.width}mm`, `${printer.height}mm`, 0, 1)
LODOP.ADD_PRINT_TEXT(printer.top + "mm", printer.left + "mm", printer.width + "mm", printer.height * (scale / 100) + "mm", (_g = printer.content) !== null && _g !== void 0 ? _g : '');
LODOP.SET_PRINT_STYLEA(0, "FontSize", 10 * (scale / 100));
LODOP.SET_PRINT_STYLEA(0, "Alignment", 1);
LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
LODOP.ADD_PRINT_TEXT(num.top + "mm", num.left + "mm", num.width + "mm", num.height + "mm", num.content);
LODOP.SET_PRINT_STYLEA(0, "Alignment", 3);
LODOP.SET_PRINT_STYLEA(0, "AlignJustify", 1);
LODOP.SET_PRINT_STYLEA(0, "ItemType", num.content.length > 0 ? 2 : 0);
LODOP.ADD_PRINT_TEXT(sum.top + "mm", sum.left + "mm", sum.width + "mm", sum.height + "mm", sum.content);
LODOP.SET_PRINT_STYLEA(0, "Alignment", 3);
LODOP.SET_PRINT_STYLEA(0, "AlignJustify", 1);
LODOP.SET_PRINT_STYLEA(0, "ItemType", sum.content.length > 0 ? 3 : 0);
LODOP.SET_SHOW_MODE('HIDE_PBUTTIN_PREVIEW', true);
LODOP.SET_PRINT_MODE("POS_BASEON_PAPER", true);
LODOP.SET_PRINTER_INDEX(printerName);
if (preview) {
LODOP.PREVIEW('detail-preview');
}
else {
LODOP.SET_PRINT_COPIES(copies);
LODOP.PRINT();
}
if (onCompleted) {
LODOP.On_Return = onCompleted;
}
};
exports.detailPrint = detailPrint;
var formPrint = function (preview, settings, template, htmls, onCompleted) {
var printerName = settings.printer, width = settings.width, height = settings.height, direction = settings.direction, copies = settings.copies;
var logo = template.logo, headerTitle = template.headerTitle, headerLine = template.headerLine, title = template.title, subTitle1 = template.subTitle1, subTitle2 = template.subTitle2, subTitle3 = template.subTitle3, table = template.table, footerLine = template.footerLine, footerTitle = template.footerTitle, printer = template.printer, date = template.date, num = template.num, sum = template.sum;
var LODOP = (0, LodopFuncs_1.getLodop)();
var createTask = function (tableContent, index) {
var _a, _b, _c, _d, _e, _f, _g, _h;
var isFirstTask = index == 0;
LODOP.PRINT_INIT('report');
LODOP.SET_PRINT_PAGESIZE(direction == 'vertical' ? 1 : 2, width * 10, height * 10, 'CreateCustomPage');
LODOP.NEWPAGEA();
LODOP.ADD_PRINT_IMAGE(logo.top + "mm", logo.left + "mm", logo.width + "mm", logo.height + "mm", logo.content);
LODOP.SET_PRINT_STYLEA(0, "Stretch", 1);
LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
LODOP.ADD_PRINT_TEXT(headerTitle.top + "mm", headerTitle.left + "mm", headerTitle.width + "mm", headerTitle.height + "mm", headerTitle.content);
LODOP.SET_PRINT_STYLEA(0, "FontSize", 12);
LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
LODOP.ADD_PRINT_RECT(headerLine.top + "mm", headerLine.left + "mm", headerLine.width + "mm", "" + headerLine.height, 0, 1);
LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
// title
if (title.itemType === 1 || isFirstTask) {
LODOP.ADD_PRINT_TEXT(title.top + "mm", title.left + "mm", title.width + "mm", title.height + "mm", (_a = title.content) !== null && _a !== void 0 ? _a : '');
LODOP.SET_PRINT_STYLEA(0, "FontSize", 12);
LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);
LODOP.SET_PRINT_STYLEA(0, "ItemType", (_b = title.itemType) !== null && _b !== void 0 ? _b : 1);
}
// subtitle
if (subTitle1.itemType === 1 || isFirstTask) {
LODOP.ADD_PRINT_TEXT(subTitle1.top + "mm", subTitle1.left + "mm", subTitle1.width + "mm", subTitle1.height + "mm", (_c = subTitle1.content) !== null && _c !== void 0 ? _c : '');
LODOP.SET_PRINT_STYLEA(0, "FontSize", 10);
LODOP.SET_PRINT_STYLEA(0, "Alignment", subTitle2.width == 0 && subTitle3.width == 0 ? 3 : 1);
LODOP.SET_PRINT_STYLEA(0, "ItemType", (_d = subTitle1.itemType) !== null && _d !== void 0 ? _d : 1);
}
if (subTitle2.itemType === 1 || isFirstTask) {
LODOP.ADD_PRINT_TEXT(subTitle2.top + "mm", subTitle2.left + "mm", subTitle2.width + "mm", subTitle2.height + "mm", (_e = subTitle2.content) !== null && _e !== void 0 ? _e : '');
LODOP.SET_PRINT_STYLEA(0, "FontSize", 10);
LODOP.SET_PRINT_STYLEA(0, "Alignment", subTitle3.width == 0 ? 3 : 2);
LODOP.SET_PRINT_STYLEA(0, "ItemType", (_f = subTitle2.itemType) !== null && _f !== void 0 ? _f : 1);
}
if (subTitle3.itemType === 1 || isFirstTask) {
LODOP.ADD_PRINT_TEXT(subTitle3.top + "mm", subTitle3.left + "mm", subTitle3.width + "mm", subTitle3.height + "mm", (_g = subTitle3.content) !== null && _g !== void 0 ? _g : '');
LODOP.SET_PRINT_STYLEA(0, "FontSize", 10);
LODOP.SET_PRINT_STYLEA(0, "Alignment", 3);
LODOP.SET_PRINT_STYLEA(0, "ItemType", (_h = subTitle3.itemType) !== null && _h !== void 0 ? _h : 1);
}
// table
LODOP.ADD_PRINT_TABLE(table.top + "mm", table.left + "mm", table.width + "mm", table.height + "mm", tableContent);
LODOP.SET_PRINT_STYLEA(0, 'TableHeightScope', 1);
// foot
LODOP.ADD_PRINT_TEXT(footerTitle.top + "mm", footerTitle.left + "mm", footerTitle.width + "mm", footerTitle.height + "mm", footerTitle.content);
LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
LODOP.ADD_PRINT_RECT(footerLine.top + "mm", footerLine.left + "mm", footerLine.width + "mm", "" + footerLine.height, 0, 1);
LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
LODOP.ADD_PRINT_TEXT(printer.top + "mm", printer.left + "mm", printer.width + "mm", printer.height + "mm", printer.content);
LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
LODOP.ADD_PRINT_TEXT(date.top + "mm", date.left + "mm", date.width + "mm", date.height + "mm", date.content);
LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);
LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
LODOP.ADD_PRINT_TEXT(num.top + "mm", num.left + "mm", num.width + "mm", num.height + "mm", num.content);
LODOP.SET_PRINT_STYLEA(0, "Alignment", 3);
LODOP.SET_PRINT_STYLEA(0, "AlignJustify", 1);
LODOP.SET_PRINT_STYLEA(0, "ItemType", num.content.length > 0 ? 2 : 0);
LODOP.ADD_PRINT_TEXT(sum.top + "mm", sum.left + "mm", sum.width + "mm", sum.height + "mm", sum.content);
LODOP.SET_PRINT_STYLEA(0, "Alignment", 3);
LODOP.SET_PRINT_STYLEA(0, "AlignJustify", 1);
LODOP.SET_PRINT_STYLEA(0, "ItemType", sum.content.length > 0 ? 3 : 0);
LODOP.SET_SHOW_MODE('HIDE_PBUTTIN_PREVIEW', true);
LODOP.SET_PRINT_MODE("POS_BASEON_PAPER", true);
LODOP.SET_PRINT_MODE("CUSTOM_TASK_NAME", "report" + index);
LODOP.SET_PRINTER_INDEX(printerName);
LODOP.SET_PRINT_COPIES(copies);
};
if (preview) {
createTask(htmls[0], 0);
LODOP.PREVIEW('report-preview');
}
else {
for (var i = 0; i < htmls.length; i++) {
var tableContent = htmls[i];
createTask(tableContent, i);
LODOP.PRINT();
}
}
if (onCompleted) {
LODOP.On_Return = function () { return onCompleted(); };
}
};
exports.formPrint = formPrint;
function billPrint(params, onCompleted) {
var LODOP = (0, LodopFuncs_1.getLodop)();
var templateDatas = params.templateDatas, direction = params.direction, pageWidth = params.pageWidth, pageHeight = params.pageHeight, printer = params.printer, preview = params.preview, count = params.count;
LODOP.PRINT_INITA(0, 0, pageWidth + "mm", pageHeight + "mm", 'billprint');
LODOP.SET_PRINT_PAGESIZE(direction ? 1 : 2, pageWidth * 10, pageHeight * 10, '');
for (var i = 0; i < templateDatas.length; i++) {
LODOP.NEWPAGEA();
var templateData = templateDatas[i];
for (var j = 0; j < templateData.length; j++) {
var labelData = templateData[j];
var labelTexts = labelData.labelTexts, labelHtmls = labelData.labelHtmls, labelImages = labelData.labelImages, labelTables = labelData.labelTables, labelBarCodes = labelData.labelBarCodes, labelRects = labelData.labelRects, labelEllipses = labelData.labelEllipses, labelLines = labelData.labelLines, labelShapes = labelData.labelShapes;
labelTables.forEach(function (table) {
LODOP.ADD_PRINT_TABLE(table.top.strValue, table.left.strValue, table.width.strValue, table.height.strValue, table.content);
var styles = table.styles;
if (styles) {
styles.forEach(function (_a) {
var id = _a[0], name = _a[1], value = _a[2];
LODOP.SET_PRINT_STYLEA(id, name, value);
});
}
});
labelTexts.forEach(function (text) {
var fieldName = text.fieldName;
if (fieldName) {
LODOP.ADD_PRINT_TEXTA(fieldName, text.top.strValue, text.left.strValue, text.width.strValue, text.height.strValue, text.content);
}
else {
LODOP.ADD_PRINT_TEXT(text.top.strValue, text.left.strValue, text.width.strValue, text.height.strValue, text.content);
}
var styles = text.styles;
if (styles) {
styles.forEach(function (_a) {
var id = _a[0], name = _a[1], value = _a[2];
LODOP.SET_PRINT_STYLEA(id, name, value);
});
}
});
labelHtmls.forEach(function (html) {
LODOP.ADD_PRINT_HTM(html.top.strValue, html.left.strValue, html.width.strValue, html.height.strValue, html.content);
var styles = html.styles;
if (styles) {
styles.forEach(function (_a) {
var id = _a[0], name = _a[1], value = _a[2];
LODOP.SET_PRINT_STYLEA(id, name, value);
});
}
});
labelImages.forEach(function (image) {
LODOP.ADD_PRINT_IMAGE(image.top.strValue, image.left.strValue, image.width.strValue, image.height.strValue, image.url);
var styles = image.styles;
if (styles) {
styles.forEach(function (_a) {
var id = _a[0], name = _a[1], value = _a[2];
LODOP.SET_PRINT_STYLEA(id, name, value);
});
}
});
labelBarCodes.forEach(function (barCode) {
var fieldName = barCode.fieldName;
if (fieldName) {
LODOP.ADD_PRINT_BARCODEA(fieldName, barCode.top.strValue, barCode.left.strValue, barCode.width.strValue, barCode.height.strValue, barCode.codeType, barCode.codeValue);
}
else {
LODOP.ADD_PRINT_BARCODE(barCode.top.strValue, barCode.left.strValue, barCode.width.strValue, barCode.height.strValue, barCode.codeType, barCode.codeValue);
}
var styles = barCode.styles;
if (styles) {
styles.forEach(function (_a) {
var id = _a[0], name = _a[1], value = _a[2];
LODOP.SET_PRINT_STYLEA(id, name, value);
});
}
});
labelRects.forEach(function (rect) { return LODOP.ADD_PRINT_RECT(rect.top.strValue, rect.left.strValue, rect.width.strValue, rect.height.strValue, rect.lineStyle, rect.lineWidth); });
labelEllipses.forEach(function (ellipse) { return LODOP.ADD_PRINT_ELLIPSE(ellipse.top.strValue, ellipse.left.strValue, ellipse.width.strValue, ellipse.height.strValue, ellipse.lineStyle, ellipse.lineWidth); });
labelLines.forEach(function (line) { return LODOP.ADD_PRINT_LINE(line.top.strValue, line.left.strValue, line.width.strValue, line.height.strValue, line.lineStyle, line.lineWidth); });
labelShapes.forEach(function (shape) { return LODOP.ADD_PRINT_SHAPE(shape.shapeType, shape.top.strValue, shape.left.strValue, shape.width.strValue, shape.height.strValue, shape.lineStyle, shape.lineWidth, shape.fillColor); });
}
}
if (preview) {
LODOP.SET_SHOW_MODE('HIDE_PBUTTIN_PREVIEW', true);
LODOP.SET_PRINTER_INDEX(printer);
LODOP.PREVIEW('bill-preview');
}
else {
LODOP.SET_PRINT_COPIES(count);
LODOP.SET_PRINTER_INDEX(printer);
LODOP.PRINT();
}
if (onCompleted) {
LODOP.On_Return = function () { return onCompleted(); };
}
}
exports.billPrint = billPrint;
function labelPrint(params, onCompleted) {
var LODOP = (0, LodopFuncs_1.getLodop)();
var templateDatas = params.templateDatas, marginTop = params.marginTop, marginLeft = params.marginLeft, direction = params.direction, pageWidth = params.pageWidth, pageHeight = params.pageHeight, preview = params.preview, printer = params.printer;
LODOP.PRINT_INITA(marginTop + "mm", marginLeft + "mm", pageWidth + "mm", pageHeight + "mm", "labelprint_" + Date.now());
LODOP.SET_PRINT_PAGESIZE(direction ? 1 : 2, pageWidth * 10, pageHeight * 10, '');
for (var i = 0; i < templateDatas.length; i++) {
LODOP.NEWPAGEA();
var templateData = templateDatas[i];
for (var j = 0; j < templateData.length; j++) {
var labelData = templateData[j];
var tempTop = labelData.tempTop, tempLeft = labelData.tempLeft, tempWidth = labelData.tempWidth, tempHeight = labelData.tempHeight, labelTexts = labelData.labelTexts, labelHtmls = labelData.labelHtmls, labelTables = labelData.labelTables, labelImages = labelData.labelImages, labelBarCodes = labelData.labelBarCodes, labelRects = labelData.labelRects, labelEllipses = labelData.labelEllipses, labelLines = labelData.labelLines, labelShapes = labelData.labelShapes;
labelTables.forEach(function (table) {
LODOP.ADD_PRINT_TABLE(table.top.strValue, table.left.strValue, table.width.strValue, table.height.strValue, table.content);
var styles = table.styles;
if (styles) {
styles.forEach(function (_a) {
var id = _a[0], name = _a[1], value = _a[2];
LODOP.SET_PRINT_STYLEA(id, name, value);
});
}
});
labelTexts.forEach(function (text) {
var fieldName = text.fieldName;
if (fieldName) {
LODOP.ADD_PRINT_TEXTA(fieldName, text.top.strValue, text.left.strValue, text.width.strValue, text.height.strValue, text.content);
}
else {
LODOP.ADD_PRINT_TEXT(text.top.strValue, text.left.strValue, text.width.strValue, text.height.strValue, text.content);
}
var styles = text.styles;
if (styles) {
styles.forEach(function (_a) {
var id = _a[0], name = _a[1], value = _a[2];
LODOP.SET_PRINT_STYLEA(id, name, value);
});
}
});
labelHtmls.forEach(function (html) {
LODOP.ADD_PRINT_HTM(html.top.strValue, html.left.strValue, html.width.strValue, html.height.strValue, html.content);
var styles = html.styles;
if (styles) {
styles.forEach(function (_a) {
var id = _a[0], name = _a[1], value = _a[2];
LODOP.SET_PRINT_STYLEA(id, name, value);
});
}
});
labelImages.forEach(function (image) {
LODOP.ADD_PRINT_IMAGE(image.top.strValue, image.left.strValue, image.width.strValue, image.height.strValue, image.url);
var styles = image.styles;
if (styles) {
styles.forEach(function (_a) {
var id = _a[0], name = _a[1], value = _a[2];
LODOP.SET_PRINT_STYLEA(id, name, value);
});
}
});
labelBarCodes.forEach(function (barCode) {
var fieldName = barCode.fieldName;
if (fieldName) {
LODOP.ADD_PRINT_BARCODEA(fieldName, barCode.top.strValue, barCode.left.strValue, barCode.width.strValue, barCode.height.strValue, barCode.codeType, barCode.codeValue);
}
else {
LODOP.ADD_PRINT_BARCODE(barCode.top.strValue, barCode.left.strValue, barCode.width.strValue, barCode.height.strValue, barCode.codeType, barCode.codeValue);
}
var styles = barCode.styles;
if (styles) {
styles.forEach(function (_a) {
var id = _a[0], name = _a[1], value = _a[2];
LODOP.SET_PRINT_STYLEA(id, name, value);
});
}
});
labelRects.forEach(function (rect) { return LODOP.ADD_PRINT_RECT(rect.top.strValue, rect.left.strValue, rect.width.strValue, rect.height.strValue, rect.lineStyle, rect.lineWidth); });
labelEllipses.forEach(function (ellipse) { return LODOP.ADD_PRINT_ELLIPSE(ellipse.top.strValue, ellipse.left.strValue, ellipse.width.strValue, ellipse.height.strValue, ellipse.lineStyle, ellipse.lineWidth); });
labelLines.forEach(function (line) { return LODOP.ADD_PRINT_LINE(line.top.strValue, line.left.strValue, line.width.strValue, line.height.strValue, line.lineStyle, line.lineWidth); });
labelShapes.forEach(function (shape) { return LODOP.ADD_PRINT_SHAPE(shape.shapeType, shape.top.strValue, shape.left.strValue, shape.width.strValue, shape.height.strValue, shape.lineStyle, shape.lineWidth, shape.fillColor); });
if (preview) {
LODOP.ADD_PRINT_RECT(tempTop.strValue, tempLeft.strValue, tempWidth.strValue, tempHeight.strValue, 0, 1);
}
}
}
LODOP.SET_PRINT_MODE("POS_BASEON_PAPER", true);
if (preview) {
LODOP.SET_SHOW_MODE('HIDE_PBUTTIN_PREVIEW', true);
LODOP.SET_PRINTER_INDEX(printer);
LODOP.PREVIEW('label-preview');
}
else {
LODOP.SET_PRINTER_INDEX(printer);
LODOP.PRINT();
}
if (onCompleted) {
LODOP.On_Return = function () { return onCompleted(); };
}
}
exports.labelPrint = labelPrint;
// 文件仅预览
function filePrint(params, onCompleted) {
var LODOP = (0, LodopFuncs_1.getLodop)();
var fileDatas = params.fileDatas, printer = params.printer, direction = params.direction, pageWidth = params.pageWidth, pageHeight = params.pageHeight, preview = params.preview, marginLeft = params.marginLeft, marginTop = params.marginTop, marginRight = params.marginRight, marginBottom = params.marginBottom;
LODOP.PRINT_INIT();
for (var i = 0; i < fileDatas.length; i++) {
LODOP.NEWPAGEA();
var content = fileDatas[i].content;
if (fileDatas[i].type === 'pdf') {
LODOP.ADD_PRINT_PDF(marginTop + "mm", marginLeft + "mm", "RightMargin:" + marginRight + "mm", "BottomMargin:" + marginBottom + "mm", content); // 这里设置的宽高是无效的
LODOP.SET_PRINT_STYLEA(0, 'PDFScalMode', 1);
}
else {
// 测试地址图片 'https://img.zcool.cn/community/0147e86243ff520002c3290f77f99d.jpg@1280w_1l_2o_100sh.jpg'
LODOP.ADD_PRINT_HTML(marginTop + "mm", marginLeft + "mm", "RightMargin:" + marginRight + "mm", "BottomMargin:" + marginBottom + "mm", "<img style=\"width:100%\" src=" + content + " />");
}
// 整页按比例缩放
// 上面的语句会将内容铺满整张纸,由于打印机的可打印区域不是整张纸,因此打印可能会被裁掉部分内容,所以将内容缩小一些
// LODOP.SET_PRINT_MODE('PRINT_PAGE_PERCENT', '95%');
// 对于单页输出,如希望内容超出纸宽或纸高时对应缩小,用如下俩语句:
// LODOP.SET_PRINT_MODE('FULL_WIDTH_FOR_OVERFLOW', true);
// LODOP.SET_PRINT_MODE('FULL_HEIGHT_FOR_OVERFLOW', true);
// LODOP.SET_PRINT_STYLEA(0, 'ScalX', 1.5); // 这个可以设置缩放高度、宽度比例
}
LODOP.SET_PRINT_PAGESIZE(direction ? 1 : 2, pageWidth * 10, pageHeight * 10, ''); // 设置纸张大小
LODOP.SET_PRINTER_INDEX(printer); // 设置打印机
LODOP.SET_SHOW_MODE('HIDE_SBUTTIN_PREVIEW', true); // 预览窗口隐藏设置按钮
LODOP.SET_SHOW_MODE('HIDE_PBUTTIN_PREVIEW', true); // 预览窗口隐藏打印按钮
LODOP.SET_SHOW_MODE('LANDSCAPE_DEFROTATED', true); // 横向打印时正向显示
// LODOP.SET_PRINT_MODE('AUTO_CLOSE_PREWINDOW', true); // 打印完毕自动关闭预览窗口
// LODOP.SET_PREVIEW_WINDOW(1, 0, 1, 900, 600); // 设置预览窗口
if (preview) {
LODOP.SET_SHOW_MODE('HIDE_PBUTTIN_PREVIEW', true);
LODOP.SET_PRINTER_INDEX(printer);
LODOP.PREVIEW('file-preview');
}
else {
LODOP.SET_PRINTER_INDEX(printer);
LODOP.PRINT();
}
if (onCompleted) {
LODOP.On_Return = function () { return onCompleted(); };
}
}
exports.filePrint = filePrint;
//# sourceMappingURL=./utils/print/index.js.map
;