Python ReportLab: An Example of bar code and two-dimensional code drawing, pythonreportlab

Source: Internet
Author: User

Python ReportLab: An Example of bar code and two-dimensional code drawing, pythonreportlab

Barcode and QR code

# Introduce the required basic package from reportlab.pdf gen import canvasfrom reportlab. graphics. barcode import code39, code128, code93from reportlab. graphics. barcode import eanbc, qr, uspsfrom reportlab. graphics. shapes import Drawing from reportlab. lib. units import mmfrom reportlab. graphics import renderPDF # export def createBarCodes (c): barcode_value = "1234567890" barcode39 = code39.Extended39 (barcode_value) barcode39Std = code39.Standard39 (barcode_value, barHeight = 20, stop = 1) # code93 also has an Extended and MultiWidth version barcode93 = partition (barcode_value) barcode128 = partition (barcode_value) # the multiwidth barcode appears to be broken # barcode128Multi = partition (barcode_value) Partition = usps. POSTNET ("50158-9999") codes = [barcode39, barcode39Std, barcode93, barcode128, barcode_usps] x = 1 * mm y = 285 * mm for code in codes: code. drawOn (c, x, y) y = y-15 * mm # draw the eanbc8 code barcode_eanbc8 = eanbc. ean8BarcodeWidget (barcode_value) d = Drawing (50, 10) d. add (barcode_eanbc8) renderPDF. draw (d, c, 15,555) # draw the eanbc13 code barcode_eanbc13 = eanbc. ean13BarcodeWidget (barcode_value) d = Drawing (50, 10) d. add (barcode_eanbc13) renderPDF. draw (d, c, 15,465) # draw a QR code qr_code = qr. qrCodeWidget ('HTTP: // blog.csdn.net/webzhuce') bounds = qr_code.getBounds () width = bounds [2]-bounds [0] height = bounds [3]-bounds [1] d = Drawing (45, 45, transform = [45. /width, 0, 0, 45. /height, 0, 0]) d. add (qr_code) renderPDF. draw (d, c, 15,405) # define the name of the pdf to be generated c = canvas. canvas ("barcodes.pdf") # Call the function to generate a barcode and a QR code, and pass the canvas object as a parameter to createBarCodes (c) # showPage function: Save canvasc on the current page. showPage () # save function: save the file and close canvasc. save ()

Running result:

The Python ReportLab example for bar code and two-dimensional code is all the content shared by the editor. I hope you can give us a reference and support for the customer's house.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.