-
百度搜索lodop,下载好并安装后
lodop.png -
把上图中得LodopFuncs.js放进项目中,由于我是使用的vue,因此改造了一下,在每个方法前加上了
export
export function needCLodop() {......}
export function loadCLodop() {......}
export function getLodop() {......}
- 使用方法
<template>
<div class="demo">
<el-button @click="printPdf" >打印</el-button>
<el-select v-model="printValue" placeholder="请选择">
<el-option v-for="item in printOptions"
:key="item.value"
:label="item.label"
:value="item.value"></el-option>
</el-select>
</div>
</template>
<script>
var LODOP;
import {getLodop} from '../common/LodopFuncs'
export default {
name: "demo",
data() {
return {
printOptions: [],
printValue: '-1'
}
},
methods: {
//选择打印机
getLodopData () {
LODOP = getLodop();
let arr = []
let iPrinterCount = LODOP.GET_PRINTER_COUNT();
for (let i = 0; i < iPrinterCount; i++) {
arr.push({
label: LODOP.GET_PRINTER_NAME(i),
value: i
})
}
let defaultName = LODOP.GET_PRINTER_NAME('-1') //GET_PRINTER_NAME(intPrinterIndex);用序号获得打印机名,一般序号从0开始,-1特指默认打印机;
arr.forEach(item => {
if (item.label === defaultName) {
item.value = '-1'
item.label += '-默认打印机'
}
})
console.log(defaultName)
this.printOptions = arr
},
// 查询数据
printPdf() {
LODOP = getLodop();
LODOP.SET_PRINTER_INDEX(this.printValue)//设置打印机
let he = "<p style=\"font-size:12px;\">"
LODOP.PRINT_INIT("打印小票"); //首先一个初始化语句
LODOP.SET_PRINT_PAGESIZE(1, '70mm', '110mm', ''); //设置纸张高度(仅仅只是用来调整高度的--也就是长度)
LODOP.ADD_PRINT_HTM(i, 0, 300, 140, '<p style="font-size:20px;text-align: center;">xxxxx有限公司');
LODOP.ADD_PRINT_HTM(i += 40, 0, 300, 140, he + '地址:' "</div>");
// LODOP.ADD_PRINT_HTM(i+=20, 0, 300, 140, '东荔商业大厦601');
LODOP.ADD_PRINT_HTM(i += 20, 0, 300, 140, he + '電話:' );
LODOP.ADD_PRINT_HTM(i += 20, 0, 300, 140, he + 'FAX:' );
LODOP.ADD_PRINT_HTM(i += 20, 0, 300, 140, he + "Time:" );
LODOP.ADD_PRINT_HTM(i += 20, 0, 300, 140, he + "Staff-Staff:" ); //员工
LODOP.ADD_PRINT_HTM(i += 20, 0, 300, 140, he + "ID:");
LODOP.ADD_PRINT_HTM(i += 20, 0, 300, 140, he + "SN:");
LODOP.ADD_PRINT_HTM(i += 20, 0, 300, 140, he + "----CloseReceipt----");
LODOP.ADD_PRINT_HTM(i += 20, 0, 300, 140, he +
"- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -");
LODOP.ADD_PRINT_HTM(i += 20, 0, 300, 140, "             " +
sale.cntAmount);
LODOP.ADD_PRINT_HTM(i += 20, 0, 300, 140, he +
"- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -");
LODOP.ADD_PRINT_HTM(i += 20, 0, 300, 140, he + "**************************************");
LODOP.ADD_PRINT_HTM(i += 20, 0, 300, 140, he + "Welcome");
LODOP.ADD_PRINT_HTM(i += 20, 0, 300, 140, he + "**************************************");
// LODOP.PRINT(); //静默打印
LODOP.PREVIEW(); //预览
},
}
}
</script>
网友评论