LoginSignup
7
1

More than 3 years have passed since last update.

receiptline でレシートプリンター型日めくりカレンダーを作ってみた

Last updated at Posted at 2021-04-01

さあみなさん、買わなくていいのでちょっと見ていってください。

本日ご紹介する商品は、こちらの日めくりカレンダーです。
どうですこのボディー。レシートプリンターそっくりでしょう?
01.jpg

実はカレンダーを毎朝6時30分に印刷する優れものなんです!
もちろん印刷時刻はお好みに合わせて変更することができます。
02.jpg

カレンダーをめくるのに失敗してがっかりしたことありますよね?
この商品があれば再印刷できるので何度でもやり直しができます!
03.jpg

しかも印刷時にピヨピヨと鳴るメーカーオプションの大音量ブザー付き!
音量は調節できるので、目覚まし時計としてもお使いいただけます!
04.jpg

これだけではありません!今回は特別に Node.js のソースコードもお付けします!
LAN 対応のローカル版、さらに CloudPRNT 対応のクラウド版をご用意いたしました。

ローカル版

local.js
const net = require('net');
const cron = require('node-cron');
const receiptline = require('receiptline');
const { convert } = require('convert-svg-to-png');

cron.schedule('0 30 6 * * *', () => {
    // ReceiptLine
    const text = `\n\n\n\n\n\n\n\n
    \`"^^^~~~~~~~2021年~~~~~~~

    ^令和3年

    April|^^^^"4月|卯月

    "^^^^^^^1

    ^^^木曜日
    Thursday

    -

    \エイプリルフール/

    {b:line}
    |"2021年 3月|"2021年 4月|
    -
    |_日 月 火 水 木 金 土|_日 月 火 水 木 金 土|
    |~~ 1 2 3 4 5 6|~~ ~~ ~~ ~~ 1 2 3|
    |\`\` 8 9 10 11 12 13|\`\` 5 6 7 8 9 10|
    |\`14\` 15 16 17 18 19 \`20\`|\`11\` 12 13 14 15 16 17|
    |\`21\` 22 23 24 25 26 27|\`18\` 19 20 21 22 23 24|
    |\`28\` 29 30 31 ~~ ~~ ~~|\`25\` 26 27 28 \`29\` 30 ~~|
    {b:space}`;
    // SVG
    const svg = receiptline.transform(text, { encoding: 'cp932' });
    // PNG
    convert(svg).then(png => {
        // Printer
        const printer = {
            host: '192.168.1.253',
            port: 9100,
            gamma: 1.0,
            upsideDown: true,
            cutting: false,
            command: 'starmbcs'
        };
        const socket = net.connect(printer.port, printer.host, () => {
            socket.end(receiptline.transform(`{x:\x07}\n|{i:${png.toString('base64')}}`, printer), 'binary');
        });
        socket.on('error', err => {
            console.log(err.message);
        });
    });
});

クラウド版

cloud.js
const express = require('express');
const app = express();
const cron = require('node-cron');
const receiptline = require('receiptline');
const { convert } = require('convert-svg-to-png');

// ReceiptLine
let text = '';
cron.schedule('0 30 6 * * *', () => {
    // ReceiptLine
    text = `\n\n\n\n\n\n\n\n
    \`"^^^~~~~~~~2021年~~~~~~~

    ^令和3年

    April|^^^^"4月|卯月

    "^^^^^^^1

    ^^^木曜日
    Thursday

    -

    \エイプリルフール/

    {b:line}
    |"2021年 3月|"2021年 4月|
    -
    |_日 月 火 水 木 金 土|_日 月 火 水 木 金 土|
    |~~ 1 2 3 4 5 6|~~ ~~ ~~ ~~ 1 2 3|
    |\`\` 8 9 10 11 12 13|\`\` 5 6 7 8 9 10|
    |\`14\` 15 16 17 18 19 \`20\`|\`11\` 12 13 14 15 16 17|
    |\`21\` 22 23 24 25 26 27|\`18\` 19 20 21 22 23 24|
    |\`28\` 29 30 31 ~~ ~~ ~~|\`25\` 26 27 28 \`29\` 30 ~~|
    {b:space}`;
});

// Server
app.post('/calendar', (req, res) => {
    // Print Job
    if (text.length > 0) {
        res.json({ jobReady: true, mediaTypes: [ 'application/vnd.star.starprnt' ] });
    } else {
        res.json({ jobReady: false });
    }
})
app.get('/calendar', (req, res) => {
    // SVG
    const svg = receiptline.transform(text, { encoding: 'cp932' });
    // PNG
    convert(svg).then(png => {
        // Printer
        const printer = { gamma: 1.0, upsideDown: true, cutting: false, command: 'starmbcs' };
        // Command
        const command = Buffer.from(receiptline.transform(`{x:\x07}\n|{i:${png.toString('base64')}}`, printer), 'binary');
        res.status(200).type('application/vnd.star.starprnt').send(command);
        text = '';
    });
});
app.listen(8080, () => {
    console.log('Server running at http://localhost:8080/');
});

さらにさらに!日めくりカレンダーのデザインをカスタマイズできるツールも無料でご提供!
https://receiptline.github.io/designer/

ReceiptLine
`"^^^~~~~~~~2021年~~~~~~~

^令和3年

April|^^^^"4月|卯月

"^^^^^^^1

^^^木曜日
Thursday

-

\エイプリルフール/

{b:line}
|"2021年 3月|"2021年 4月|
-
|_日 月 火 水 木 金 土|_日 月 火 水 木 金 土|
|~~ 1 2 3 4 5 6|~~ ~~ ~~ ~~ 1 2 3|
|`7` 8 9 10 11 12 13|`4` 5 6 7 8 9 10|
|`14` 15 16 17 18 19 `20`|`11` 12 13 14 15 16 17|
|`21` 22 23 24 25 26 27|`18` 19 20 21 22 23 24|
|`28` 29 30 31 ~~ ~~ ~~|`25` 26 27 28 `29` 30 ~~|
{b:space}

05.png
どうですみなさん、すごいでしょう?
・・・エイプリルフールネタにしてみました。

マークダウン言語で紙のレシートや電子レシートを簡単に作れる receiptline。
パッケージに添付されているプログラム例を参考に作りました。
https://github.com/receiptline/receiptline

receiptline で SVG に変換後、さらにプリンターコマンドに変換しています。
4月1日固定なので、当日の日付を印刷するように修正してくださいね!

また何か作ったら投稿します。ではまた!

7
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
1