Skip to content

How to embed QR codes into your forms and print them

License

Notifications You must be signed in to change notification settings

matiyas-develop/frappe_qr_demo

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

QR Demo

Demo app for QR codes and barcodes in ERPNext print formats.

This app contains a DocType QR Demo. You can create a new QR Demo, fill the Title field and save.

In the backend, the title is converted to a QR code image with these steps:

  1. Create QR code, using https://pypi.org/project/qrcode/
  2. Convert the raw bytes of QR code to a base64 encoded string
  3. Add info about filetype and encoding for the browser
  4. Save the QR Code data in the field QR Code

Form: saved QR Demo

The QR Demo DocType also has a field QR Image, which just displays the data stored in QR Code.

Note: In a production application, you'll want to set the field QR Code as hidden, so the user doesn't see the raw data.

Try to print the document, using the print format "QR Demo". The QR code will work flawlessly in print preview and PDF. The print format is very simple. It uses the data from QR Code like this:

<p>QR Code stored in field <i>QR Code</i>:</p>
<img src="{{ doc.qr_code }}" alt="{{ doc.title }}"/>

For cases when we need dynamic QR codes, that are not stored in the document, we can generate them ad-hoc by calling get_qr_code in the print format:

<p>QR Code generated ad-hoc:</p>
<img src="{{ get_qr_code('Hello World!') }}" alt="Hello World!"/>

We achieved this by adding the get_qr_code() method to the jinja configuration in our hooks.py file, like this:

jinja = {
	"methods": [
		"qr_demo.qr_code.get_qr_code"
	],
}

Print Preview

Form: saved QR Demo

Print PDF

Form: saved QR Demo

Barcode

A Code 128 barcode can be printed as follows:

<p>Barcode:</p>
{{ get_barcode_svg(data="Test123", module_width_mm=0.2, module_height_mm=15.0) }}

About

How to embed QR codes into your forms and print them

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 97.6%
  • JavaScript 2.4%