7213

Use QrCodeWidget (or PlotArea) with platypus

Question:

My django app is using a multi-frames reportlab pdf report in witch I would like to add some barcodes/qr-codes.

The problem I have is that every object I add to my layout have to be a Flowable. So the question would be as to cast a PlotArea (mother class of QrCodeWidget) as Flowable.

If we have an answer here the error message we can get if we add the QrCodeWidget as

AttributeError: QrCodeWidget instance has no attribute 'getKeepWithNext'

Answer1:

Ok, I made my own Flowable, it was simpler than I taught.

It's as simple as doing it on a canva with this API.

from reportlab.platypus import Flowable from reportlab.graphics.barcode import qr from reportlab.graphics import renderPDF from reportlab.graphics.shapes import Drawing class QRFlowable(Flowable): # usage : # story.append(QRFlowable("http://google.fr")) def __init__(self, qr_value): # init and store rendering value Flowable.__init__(self) self.qr_value = qr_value def wrap(self, availWidth, availHeight): # optionnal, here I ask for the biggest square available self.width = self.height = min(availWidth, availHeight) return self.width, self.height def draw(self): # here standard and documented QrCodeWidget usage on # Flowable canva qr_code = qr.QrCodeWidget(self.qr_value) bounds = qr_code.getBounds() qr_width = bounds[2] - bounds[0] qr_height = bounds[3] - bounds[1] w = float(self.width) d = Drawing(w, w, transform=[w/qr_width, 0, 0, w/qr_height, 0, 0]) d.add(qr_code) renderPDF.draw(d, self.canv, 0, 0)

Answer2:

You should generate an image from your QrCodeWidget and include that in an Image flowable.

Recommend

  • Trapezoidal rule in Python
  • PHP new operator returning reference
  • .net standard 2.0 and System.Security.Cryptography.ProtectedData.Protect
  • Can I use too many background worker threads?
  • jquery mobile, use android hardware back button to close a panel
  • JavaScript/jQuery dropdownlist change event with closure not working
  • Sort by id element using jQuery [duplicate]
  • Get attributes of existing SVG elements and bind as data with d3.js
  • how to swap Image in jquery
  • Set value of radio button based on user selected options
  • Update data in d3.js group
  • jquery draggable stop event
  • Best Datagrid for Bootstrap/jQuery?
  • How to get a android ListView item selector to use state_pressed
  • Inserting a (g) node in the middle of a tree (SVG) using jQuery
  • Build an array of ids of all select boxes
  • WebApp in AppServices vs CloudService
  • changes in jquery 1.4.2 breaking the code?
  • jquery code not working without breakpoint
  • SAVE attribute needed for Fortran variables when only the C_LOC address is returned to a C program?
  • Combining two different ActiveRecord collections into one
  • saving file generated by TCPDF
  • Automatically associate new Sonar project with custom quality profile and quality gate
  • why xml file does not aligned properly after append the string in beginning and end of the file usin
  • d3 v4 drag and drop with TypeScript
  • Refering to the class itself from within a class mehod in Objective C
  • D3 nodes and links from JSON with nested arrays of children
  • Exception “firebase.functions() takes … no argument …” when specifying a region for a Cloud Function
  • Highlight one bar in a series in highcharts?
  • HTML download movie download link
  • Jquery - Jquery Wysiwyg return html as a string
  • Calling of Constructors in a Java
  • Arrays break string types in Julia
  • PHP: When would you need the self:: keyword?
  • WPF Applying a trigger on binding failure
  • NSLayoutConstraint that would pin a view to the bottom edge of a superview
  • Java static initializers and reflection
  • Linking SubReports Without LinkChild/LinkMaster
  • MATLAB: Piecewise function in curve fitting toolbox using fittype
  • XCode 8, some methods disappeared ? ex: layoutAttributesClass() -> AnyClass