Giter Club home page Giter Club logo

frappe_qr_demo's Introduction

QR Demo

Demo app for printing QR Codes.

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.