fastlion-amis
Version:
一种MIS页面生成工具
541 lines (540 loc) • 36.2 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.filePrint = exports.labelPrint = exports.billPrint = exports.formPrint = exports.detailPrint = exports.templateDesign = exports.writeFileToTemp = 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 writeFileToTemp(content) {
var LODOP = (0, LodopFuncs_1.getLodop)();
return new Promise(function (resolve) {
LODOP.WRITE_FILE_TEXT('UTF-8', "C:\\Windows\\Temp\\print.html", content);
LODOP.On_Return = function (_taskId, value) {
resolve(value == 'ok' ? 'file:///C:/Windows/Temp/print.html' : value);
};
});
}
exports.writeFileToTemp = writeFileToTemp;
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, "".concat(width, "mm"), "".concat(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, templates, onCompleted) {
var _a, _b, _c, _d, _e, _f;
var printerName = settings.printer, width = settings.width, height = settings.height, direction = settings.direction, copies = settings.copies, page = settings.page, duplex = settings.duplex;
var LODOP = (0, LodopFuncs_1.getLodop)();
var pageList = LODOP.GET_PAGESIZES_LIST(printerName, ',').split(',');
LODOP.PRINT_INIT('report');
if (page === '自定义' || !pageList.includes(page)) {
LODOP.SET_PRINT_PAGESIZE(direction == 'vertical' ? 1 : 2, width * 10, height * 10, 'CreateCustomPage');
}
else {
LODOP.SET_PRINT_PAGESIZE(direction == 'vertical' ? 1 : 2, 0, 0, page);
}
for (var _i = 0, templates_1 = templates; _i < templates_1.length; _i++) {
var template = templates_1[_i];
LODOP.NEWPAGEA();
for (var _g = 0, template_1 = template; _g < template_1.length; _g++) {
var _h = template_1[_g], divider = _h.divider, logo = _h.logo, headerTitle = _h.headerTitle, code = _h.code, codeLabel = _h.codeLabel, extraTitle = _h.extraTitle, title = _h.title, subTitle1 = _h.subTitle1, subTitle2 = _h.subTitle2, subTitle3 = _h.subTitle3, html = _h.html, date = _h.date, printer = _h.printer, sum = _h.sum, num = _h.num, headerLine = _h.headerLine, footerLine = _h.footerLine;
// header LODOP.ADD_PRINT_RECT(`${header.top}mm`, `${header.left}mm`, `${header.width}mm`, `${header.height}mm`, 0, 1)
LODOP.ADD_PRINT_TEXT("".concat(headerTitle.top, "mm"), "".concat(headerTitle.left, "mm"), "".concat(headerTitle.width, "mm"), "".concat(headerTitle.height, "mm"), headerTitle.content);
LODOP.SET_PRINT_STYLEA(0, "FontSize", headerTitle.fontSize);
LODOP.SET_PRINT_STYLEA(0, "FontName", headerTitle.fontFamily);
LODOP.SET_PRINT_STYLEA(0, "ItemType", headerTitle.itemType);
LODOP.ADD_PRINT_IMAGE("".concat(logo.top, "mm"), "".concat(logo.left, "mm"), "".concat(logo.width, "mm"), "".concat(logo.height, "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("".concat(code.top, "mm"), "".concat(code.left, "mm"), "".concat(code.width, "mm"), "".concat(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("".concat(codeLabel.top, "mm"), "".concat(codeLabel.left, "mm"), "".concat(codeLabel.width, "mm"), "".concat(codeLabel.height, "mm"), codeLabel.content);
LODOP.SET_PRINT_STYLEA(0, "Alignment", 3);
LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
}
if (headerLine) {
LODOP.ADD_PRINT_LINE("".concat(headerLine.top, "mm"), "".concat(headerLine.left, "mm"), "".concat(headerLine.top, "mm"), "".concat(headerLine.width + headerLine.left, "mm"), 0, 1);
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("".concat(extraTitle.top, "mm"), "".concat(extraTitle.left, "mm"), "".concat(extraTitle.width, "mm"), "".concat(extraTitle.height, "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("".concat(title.top, "mm"), "".concat(title.left, "mm"), "".concat(title.width, "mm"), "".concat(title.height, "mm"), title.content);
LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);
LODOP.SET_PRINT_STYLEA(0, "FontSize", title.fontSize);
LODOP.SET_PRINT_STYLEA(0, "FontName", title.fontFamily);
LODOP.SET_PRINT_STYLEA(0, "ItemType", title.itemType);
// 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("".concat(subTitle1.top, "mm"), "".concat(subTitle1.left, "mm"), "".concat(subTitle1.width, "mm"), "".concat(subTitle1.height, "mm"), (_a = subTitle1.content) !== null && _a !== void 0 ? _a : '');
LODOP.SET_PRINT_STYLEA(0, "FontSize", subTitle1.fontSize);
LODOP.SET_PRINT_STYLEA(0, "FontName", subTitle1.fontFamily);
LODOP.SET_PRINT_STYLEA(0, "Alignment", subTitle2.width == 0 && subTitle3.width == 0 ? 3 : 1);
LODOP.SET_PRINT_STYLEA(0, "ItemType", subTitle1.itemType);
// LODOP.ADD_PRINT_RECT(`${subTitle2.top}mm`, `${subTitle2.left}mm`, `${subTitle2.width}mm`, `${subTitle2.height}mm`, 0, 1)
LODOP.ADD_PRINT_TEXT("".concat(subTitle2.top, "mm"), "".concat(subTitle2.left, "mm"), "".concat(subTitle2.width, "mm"), "".concat(subTitle2.height, "mm"), (_b = subTitle2.content) !== null && _b !== void 0 ? _b : '');
LODOP.SET_PRINT_STYLEA(0, "FontSize", subTitle2.fontSize);
LODOP.SET_PRINT_STYLEA(0, "FontName", subTitle2.fontFamily);
LODOP.SET_PRINT_STYLEA(0, "Alignment", subTitle3.width == 0 ? 3 : 2);
LODOP.SET_PRINT_STYLEA(0, "ItemType", subTitle2.itemType);
// LODOP.ADD_PRINT_RECT(`${subTitle3.top}mm`, `${subTitle3.left}mm`, `${subTitle3.width}mm`, `${subTitle3.height}mm`, 0, 1)
LODOP.ADD_PRINT_TEXT("".concat(subTitle3.top, "mm"), "".concat(subTitle3.left, "mm"), "".concat(subTitle3.width, "mm"), "".concat(subTitle3.height, "mm"), (_c = subTitle3.content) !== null && _c !== void 0 ? _c : '');
LODOP.SET_PRINT_STYLEA(0, "FontSize", subTitle3.fontSize);
LODOP.SET_PRINT_STYLEA(0, "FontName", subTitle3.fontFamily);
LODOP.SET_PRINT_STYLEA(0, "Alignment", 3);
LODOP.SET_PRINT_STYLEA(0, "ItemType", subTitle3.itemType);
// LODOP.ADD_PRINT_RECT(`${html.top}mm`, `${html.left}mm`, `${html.width}mm`, `${html.height}mm`, 0, 1)
LODOP.ADD_PRINT_HTM("".concat(html.top, "mm"), "".concat(html.left, "mm"), "".concat(html.width, "mm"), "".concat(html.height, "mm"), (_d = html.content) !== null && _d !== void 0 ? _d : 'error');
if (footerLine) {
LODOP.ADD_PRINT_LINE("".concat(footerLine.top, "mm"), "".concat(footerLine.left, "mm"), "".concat(footerLine.top, "mm"), "".concat(footerLine.width + footerLine.left, "mm"), 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("".concat(date.top, "mm"), "".concat(date.left, "mm"), "".concat(date.width, "mm"), "".concat(date.height, "mm"), (_e = date.content) !== null && _e !== void 0 ? _e : '');
LODOP.SET_PRINT_STYLEA(0, "FontSize", date.fontSize);
LODOP.SET_PRINT_STYLEA(0, "FontName", date.fontFamily);
LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);
LODOP.SET_PRINT_STYLEA(0, "ItemType", date.itemType);
// LODOP.ADD_PRINT_RECT(`${printer.top}mm`, `${printer.left}mm`, `${printer.width}mm`, `${printer.height}mm`, 0, 1)
LODOP.ADD_PRINT_TEXT("".concat(printer.top, "mm"), "".concat(printer.left, "mm"), "".concat(printer.width, "mm"), "".concat(printer.height, "mm"), (_f = printer.content) !== null && _f !== void 0 ? _f : '');
LODOP.SET_PRINT_STYLEA(0, "FontSize", printer.fontSize);
LODOP.SET_PRINT_STYLEA(0, "FontName", printer.fontFamily);
LODOP.SET_PRINT_STYLEA(0, "Alignment", 1);
LODOP.SET_PRINT_STYLEA(0, "ItemType", printer.itemType);
// LODOP.ADD_PRINT_RECT(`${num.top}mm`, `${num.left}mm`, `${num.width}mm`, `${num.height}mm`, 0, 1)
LODOP.ADD_PRINT_TEXT("".concat(num.top, "mm"), "".concat(num.left, "mm"), "".concat(num.width, "mm"), "".concat(num.height, "mm"), num.content);
LODOP.SET_PRINT_STYLEA(0, "FontSize", num.fontSize);
LODOP.SET_PRINT_STYLEA(0, "FontName", num.fontFamily);
LODOP.SET_PRINT_STYLEA(0, "Alignment", 3);
LODOP.SET_PRINT_STYLEA(0, "AlignJustify", 1);
LODOP.SET_PRINT_STYLEA(0, "ItemType", num.itemType);
// LODOP.ADD_PRINT_RECT(`${sum.top}mm`, `${sum.left}mm`, `${sum.width}mm`, `${sum.height}mm`, 0, 1)
LODOP.ADD_PRINT_TEXT("".concat(sum.top, "mm"), "".concat(sum.left, "mm"), "".concat(sum.width, "mm"), "".concat(sum.height, "mm"), sum.content);
LODOP.SET_PRINT_STYLEA(0, "FontSize", sum.fontSize);
LODOP.SET_PRINT_STYLEA(0, "FontName", sum.fontFamily);
LODOP.SET_PRINT_STYLEA(0, "Alignment", 3);
LODOP.SET_PRINT_STYLEA(0, "AlignJustify", 1);
LODOP.SET_PRINT_STYLEA(0, "ItemType", sum.itemType);
if (divider) {
LODOP.ADD_PRINT_LINE("".concat(divider.top, "mm"), "".concat(divider.left, "mm"), "".concat(divider.top, "mm"), "".concat(divider.width, "mm"), 2, 1);
LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
}
}
}
LODOP.SET_SHOW_MODE('HIDE_PBUTTIN_PREVIEW', true);
LODOP.SET_SHOW_MODE("LANDSCAPE_DEFROTATED", 1); //横向时的正向显示
LODOP.SET_PRINT_MODE("POS_BASEON_PAPER", true);
if (duplex > 0) {
LODOP.SET_PRINT_MODE("PRINT_DUPLEX", duplex);
LODOP.SET_PRINT_MODE("PRINT_DEFAULTSOURCE", 1);
}
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, duplex = settings.duplex;
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;
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("".concat(logo.top, "mm"), "".concat(logo.left, "mm"), "".concat(logo.width, "mm"), "".concat(logo.height, "mm"), logo.content);
LODOP.SET_PRINT_STYLEA(0, "Stretch", 1);
LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
LODOP.ADD_PRINT_TEXT("".concat(headerTitle.top, "mm"), "".concat(headerTitle.left, "mm"), "".concat(headerTitle.width, "mm"), "".concat(headerTitle.height, "mm"), headerTitle.content);
LODOP.SET_PRINT_STYLEA(0, "FontSize", headerTitle.fontSize);
LODOP.SET_PRINT_STYLEA(0, "FontName", headerTitle.fontFamily);
LODOP.SET_PRINT_STYLEA(0, "ItemType", headerTitle.itemType);
if (headerLine) {
LODOP.ADD_PRINT_LINE("".concat(headerLine.top, "mm"), "".concat(headerLine.left, "mm"), "".concat(headerLine.top, "mm"), "".concat(headerLine.left + headerLine.width, "mm"), 0, 1);
LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
}
// title
if (title.itemType === 1 || isFirstTask) {
LODOP.ADD_PRINT_TEXT("".concat(title.top, "mm"), "".concat(title.left, "mm"), "".concat(title.width, "mm"), "".concat(title.height, "mm"), (_a = title.content) !== null && _a !== void 0 ? _a : '');
LODOP.SET_PRINT_STYLEA(0, "FontSize", title.fontSize);
LODOP.SET_PRINT_STYLEA(0, "FontName", title.fontFamily);
LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);
LODOP.SET_PRINT_STYLEA(0, "ItemType", title.itemType);
}
// subtitle
if (subTitle1.itemType === 1 || isFirstTask) {
LODOP.ADD_PRINT_TEXT("".concat(subTitle1.top, "mm"), "".concat(subTitle1.left, "mm"), "".concat(subTitle1.width, "mm"), "".concat(subTitle1.height, "mm"), (_b = subTitle1.content) !== null && _b !== void 0 ? _b : '');
LODOP.SET_PRINT_STYLEA(0, "FontSize", subTitle1.fontSize);
LODOP.SET_PRINT_STYLEA(0, "FontName", subTitle1.fontFamily);
LODOP.SET_PRINT_STYLEA(0, "Alignment", subTitle2.width == 0 && subTitle3.width == 0 ? 3 : 1);
LODOP.SET_PRINT_STYLEA(0, "ItemType", subTitle1.itemType);
}
if (subTitle2.itemType === 1 || isFirstTask) {
LODOP.ADD_PRINT_TEXT("".concat(subTitle2.top, "mm"), "".concat(subTitle2.left, "mm"), "".concat(subTitle2.width, "mm"), "".concat(subTitle2.height, "mm"), (_c = subTitle2.content) !== null && _c !== void 0 ? _c : '');
LODOP.SET_PRINT_STYLEA(0, "FontSize", subTitle2.fontSize);
LODOP.SET_PRINT_STYLEA(0, "FontName", subTitle2.fontFamily);
LODOP.SET_PRINT_STYLEA(0, "Alignment", subTitle3.width == 0 ? 3 : 2);
LODOP.SET_PRINT_STYLEA(0, "ItemType", subTitle2.itemType);
}
if (subTitle3.itemType === 1 || isFirstTask) {
LODOP.ADD_PRINT_TEXT("".concat(subTitle3.top, "mm"), "".concat(subTitle3.left, "mm"), "".concat(subTitle3.width, "mm"), "".concat(subTitle3.height, "mm"), (_d = subTitle3.content) !== null && _d !== void 0 ? _d : '');
LODOP.SET_PRINT_STYLEA(0, "FontSize", subTitle3.fontSize);
LODOP.SET_PRINT_STYLEA(0, "FontName", subTitle3.fontFamily);
LODOP.SET_PRINT_STYLEA(0, "Alignment", 3);
LODOP.SET_PRINT_STYLEA(0, "ItemType", subTitle3.itemType);
}
// table
LODOP.ADD_PRINT_TABLE("".concat(table.top, "mm"), "".concat(table.left, "mm"), "".concat(table.width, "mm"), "".concat(table.height, "mm"), tableContent);
LODOP.SET_PRINT_STYLEA(0, 'TableHeightScope', 1);
// foot
LODOP.ADD_PRINT_TEXT("".concat(footerTitle.top, "mm"), "".concat(footerTitle.left, "mm"), "".concat(footerTitle.width, "mm"), "".concat(footerTitle.height, "mm"), footerTitle.content);
LODOP.SET_PRINT_STYLEA(0, "FontSize", footerTitle.fontSize);
LODOP.SET_PRINT_STYLEA(0, "FontName", footerTitle.fontFamily);
LODOP.SET_PRINT_STYLEA(0, "ItemType", footerTitle.itemType);
if (footerLine) {
LODOP.ADD_PRINT_LINE("".concat(footerLine.top, "mm"), "".concat(footerLine.left, "mm"), "".concat(footerLine.top, "mm"), "".concat(footerLine.left + footerLine.width, "mm"), 0, 1);
LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
}
LODOP.ADD_PRINT_TEXT("".concat(printer.top, "mm"), "".concat(printer.left, "mm"), "".concat(printer.width, "mm"), "".concat(printer.height, "mm"), printer.content);
LODOP.SET_PRINT_STYLEA(0, "FontSize", printer.fontSize);
LODOP.SET_PRINT_STYLEA(0, "FontName", printer.fontFamily);
LODOP.SET_PRINT_STYLEA(0, "ItemType", printer.itemType);
LODOP.ADD_PRINT_TEXT("".concat(date.top, "mm"), "".concat(date.left, "mm"), "".concat(date.width, "mm"), "".concat(date.height, "mm"), date.content);
LODOP.SET_PRINT_STYLEA(0, "FontSize", date.fontSize);
LODOP.SET_PRINT_STYLEA(0, "FontName", date.fontFamily);
LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);
LODOP.SET_PRINT_STYLEA(0, "ItemType", date.itemType);
LODOP.ADD_PRINT_TEXT("".concat(num.top, "mm"), "".concat(num.left, "mm"), "".concat(num.width, "mm"), "".concat(num.height, "mm"), num.content);
LODOP.SET_PRINT_STYLEA(0, "FontSize", num.fontSize);
LODOP.SET_PRINT_STYLEA(0, "FontName", num.fontFamily);
LODOP.SET_PRINT_STYLEA(0, "Alignment", 3);
LODOP.SET_PRINT_STYLEA(0, "AlignJustify", 1);
LODOP.SET_PRINT_STYLEA(0, "ItemType", num.itemType);
LODOP.ADD_PRINT_TEXT("".concat(sum.top, "mm"), "".concat(sum.left, "mm"), "".concat(sum.width, "mm"), "".concat(sum.height, "mm"), sum.content);
LODOP.SET_PRINT_STYLEA(0, "FontSize", sum.fontSize);
LODOP.SET_PRINT_STYLEA(0, "FontName", sum.fontFamily);
LODOP.SET_PRINT_STYLEA(0, "Alignment", 3);
LODOP.SET_PRINT_STYLEA(0, "AlignJustify", 1);
LODOP.SET_PRINT_STYLEA(0, "ItemType", sum.itemType);
LODOP.SET_SHOW_MODE('HIDE_PBUTTIN_PREVIEW', true);
LODOP.SET_SHOW_MODE("LANDSCAPE_DEFROTATED", 1); //横向时的正向显示
LODOP.SET_PRINT_MODE("POS_BASEON_PAPER", true);
LODOP.SET_PRINT_MODE("CUSTOM_TASK_NAME", "report".concat(index));
if (duplex > 0) {
LODOP.SET_PRINT_MODE("PRINT_DUPLEX", duplex);
LODOP.SET_PRINT_MODE("PRINT_DEFAULTSOURCE", 1);
}
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, "".concat(pageWidth, "mm"), "".concat(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("".concat(marginTop, "mm"), "".concat(marginLeft, "mm"), "".concat(pageWidth, "mm"), "".concat(pageHeight, "mm"), "labelprint_".concat(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("".concat(marginTop, "mm"), "".concat(marginLeft, "mm"), "RightMargin:".concat(marginRight, "mm"), "BottomMargin:".concat(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("".concat(marginTop, "mm"), "".concat(marginLeft, "mm"), "RightMargin:".concat(marginRight, "mm"), "BottomMargin:".concat(marginBottom, "mm"), "<img style=\"width:100%\" src=".concat(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