LoginSignup
5
2

More than 5 years have passed since last update.

サーマルプリンタで印刷する: Webアプリ編

Last updated at Posted at 2018-11-24

0. 前回までのあらすじ

  1. サーマルプリンタをLinuxから印刷できるようにセットアップしました。
  2. Raspberry Piから文字、画像をテスト印刷しました。
  3. 画像を印刷するための印刷サービスを構築しました。
  4. HTMLを画像に変換するためにレンダリングサービスを構築しました。

これまでの記事については『目次』をご覧ください。

1. Webアプリをセットアップする

印刷サービスレンダリングサービスによって、HTMLをサーマルプリンタで印刷できるようになりました。
続いて、2つのWebサービスを呼び出す、簡単なWebアプリを実装しました。
ソースコードは https://github.com/nayutaya/thermal-printer/tree/master/tool/html_print を参照してください。

# thermal-printerリポジトリをclone済みの場合は、以下の3行は不要です。
pi@raspi-3bp$ mkdir -p ~/repo/github.com/nayutaya
pi@raspi-3bp$ cd ~/repo/github.com/nayutaya/
pi@raspi-3bp$ git clone https://github.com/nayutaya/thermal-printer.git

pi@raspi-3bp$ cd ~/repo/github.com/nayutaya/thermal-printer/
pi@raspi-3bp$ git pull
pi@raspi-3bp$ git checkout tool-html-print-v1.0.0
pi@raspi-3bp$ git branch -v
* (HEAD detached at tool-html-print-v1.0.0) f44670c Merge pull request #13 from nayutaya/update_html_print_tool
  master f44670c Merge pull request #13 from nayutaya/update_html_print_tool

pi@raspi-3bp$ cd ~/repo/github.com/nayutaya/thermal-printer/tool/html_print/
pi@raspi-3bp$ ./build_image.sh
pi@raspi-3bp$ ./run_service.sh
pi@raspi-3bp$ docker ps
CONTAINER ID        IMAGE                               COMMAND                  CREATED             STATUS              PORTS                    NAMES
299bdfe54be2        thermal-printer/tool/html_print     "serve --single --li…"   16 seconds ago      Up 13 seconds       0.0.0.0:3032->8080/tcp   thermal-printer_tool_html_print
3fac97d75973        thermal-printer/service/rendering   "/bin/bash --login -…"   3 hours ago         Up 3 hours          0.0.0.0:3031->8080/tcp   thermal-printer_service_rendering
3798bbbc7239        thermal-printer/service/printing    "uwsgi --module=app …"   2 weeks ago         Up 2 weeks          0.0.0.0:3030->8080/tcp   thermal-printer_service_printing

2. Webアプリで印刷する。

Webアプリは3032/tcpで待機しています。Webブラウザで http://raspi-3bp.local:3032/ (ホスト名がraspi-3bpでmDNSが有効な場合)にアクセスすることで、Webアプリにアクセスすることができます。

screenshot.png

「HTML」のテキストエリアを変更し、「Preview」ボタンを押下することで、HTMLのレンダリング結果が表示されます。
続いて「Print」ボタンを押下することで、サーマルプリンタから印刷されます。

印刷例は以下の通りです。

photo.jpg

5
2
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
5
2