簡體   English   中英

如何使用Nodejs打印lbl文件?

[英]How do i print an lbl file using Nodejs?

我正在嘗試使用Nodejs打印.lbl文件。 我一直在尋找npm和google但是,我不太確定最佳路線是什么。 我正在考慮修改一個npm以合並我需要的打印機。 但是,如果有一般的NPM會更好。

任何感興趣的人的背景信息:我想使用我從下拉列表中選擇的打印機。 一旦選擇調用.lbl文件並從我的打印機下拉框旁邊的框中打印正確的數量。

我需要在打印之前用我在屏幕上其他地方選擇的各種東西替換標簽上的一些值。

我在這里使用Datamax-O'neil打印機,但在其他地方可能有不同的打印機。

我向您提問:是否有人推薦的節點包? 我看過節點打印機 ,cordova-plugin-thermal-printer和dymo以及更多。 列出的三個似乎是正確的方向。

你知道我可以看到的任何一個可能指向正確方向的例子嗎?

對不起,如果這是一個重復的問題,我感謝所有的幫助,並提前感謝您。

安東尼

我最終這樣做了。 雖然目前它仍在進行中,但它會給任何可能遇到同樣問題的人提供一些幫助,或者至少可能會給你某種方向。 我使用這個工具來幫助我更換零件。 希望能幫助到你。

const cmd = require('node-cmd'),
  fs = require('fs');

print: (entity) => {
pool.open(cn, (err, conn) => {
    let quantityToPrint = entity.quantityToPrint; //Get Quantity from inputbox

    let getNeededData = () => {
        return new Promise((resolve, reject) => {
            sql = `select * from Table where Blah = 'BlahBlah'`

            conn.query(sql, (err, data) => {
                var obj = {};
                obj.ReplacementValue1 = (data.length > 0 && typeof data[0].ReplacementValue1 !== 'undefined') ? data[0].ReplacementValue1 : '';
                obj.ReplacementValue2 = (data.length > 0 && typeof data[0].ReplacementValue2 !== 'undefined') ? data[0].ReplacementValue2 : '';
                obj.ReplacementValue3 = (data.length > 0 && typeof data[0].ReplacementValue3 !== 'undefined') ? data[0].ReplacementValue3 : '';
                resolve(obj);
            })
        })
    }
    let getPrintLabel = (obj) => {
        return new Promise((resolve, reject) => {

            let printer = entity.printer, //Printer I call from a drop down
                labelFile = 'labels/lablefile.lbl',
                inputLine;
            var filename = 'tempLabel_' + new Date().getTime() + '.lbl';
            var gvOutFile = 'labels/temp/templabel_' + new Date().getTime() + '.lbl';

            fs.createReadStream(labelFile).pipe(fs.createWriteStream(gvOutFile, { options: { flags: 'r+', mode: 666, encoding: 'utf8' } }));
            setTimeout(function () {
                var data = fs.readFileSync(gvOutFile, 'utf8');
                var newValue = data.replace(/(\[ValueToReplace1\])/gim, month + '/' + day + '/' + years)
                    .replace(/(\[ValueToReplace1\])/gim, obj.ReplacementValue1)
                    .replace(/(\[ValueToReplace2\])/gim, obj.ReplacementValue2)
                    .replace(/(\[ValueToReplace3\])/gim, obj.ReplacementValue3)
                    //NOTE, You may need to change how you are replacing. I replace brackets in my lbl file.

                fs.writeFileSync(gvOutFile, newValue, { options: { flags: 'r+', mode: 666, encoding: 'utf8' } });
                cmd.run('lp -s -c -d ' + printer + ' ' + gvOutFile);
            }, (2 * 1000))// 2 Seconds

            resolve();
        })
    }
    for (var item = 0, x = quantityToPrint; item < x; item++) {
        getNeededData().then(getPrintLabel).then((data) => {
            pool.close(function () { });
            entity.res.json(data);
        })
    }
})
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM