def _render(self, parent): qrcode = self._generate() if not qrcode: return # Parse SVG and draw elements to the workspace output = StringIO() qrcode.save(output) output.seek(0) tree = ElementTree() tree.parse(output) root = tree.getroot() vbox = map(int, root.get("viewBox").split()) vbox = vbox[0]-self.options.padding*self.options.size/10, \ vbox[1]-self.options.padding*self.options.size/10, \ vbox[2]+2*self.options.padding*self.options.size/10, \ vbox[3]+2*self.options.padding*self.options.size/10 vbox = map(str, vbox) rect = inkex.etree.SubElement( parent, inkex.addNS('rect', 'svg'), {"x": vbox[0], "y": vbox[1], "width": vbox[2], "height": vbox[3], "style": "fill:#fff;"}) for m in root.getchildren(): attribs = {} for k in m.keys(): attribs[k] = str(m.get(k)) inkex.etree.SubElement(parent, inkex.addNS('path', 'svg'), attribs)
def qrcode_to_svgfigure(qrcode: qrcode.image.svg.SvgPathImage, color: str = "") -> sg.SVGFigure: tmp_file = tempfile.NamedTemporaryFile(mode="w+b", delete=True) qrcode.save(tmp_file.name) if color: replace_file_content(tmp_file.name, "fill:#000000", "fill:#{}".format(color)) return sg.fromfile(tmp_file.name)
def _qrcode_to_file(qrcode, out_filepath): """ Save a `qrcode` object into `out_filepath`. Parameters ---------- qrcode: qrcode object out_filepath: str Path to the output file. """ try: qrcode.save(out_filepath) except Exception as exc: raise IOError('Error trying to save QR code file {}.'.format(out_filepath)) from exc else: return qrcode
def qrcrt(): while True: ssid = input("SSID: ") if ssid == "": print("Input is not valid!") else: break while True: hidden = input("Is the network hidden (default is false): ").lower() if hidden in ['yes', 'y', 'true', 't']: hidden = True break elif hidden in ['', 'no', 'n', 'false', 'f']: hidden = False break else: print("Input is not valid!") while True: print("Authentication types: WPA/WPA2, WEP, nopass") authentication_type = input("Authentication type (default is " "WPA/WPA2): ").lower() if authentication_type in ['', 'wpa2', 'wpa', 'wpa/wpa2', 'wpa2/wpa']: authentication_type = 'WPA' break elif authentication_type == 'WEP' or authentication_type == 'nopass': break else: print("Input is not valid!") while True: if authentication_type == 'nopass': password = None break password = getpass.getpass("Password: "******"": print("Input not valid!") else: break qrcode = wifi_qrcode(ssid, hidden, authentication_type, password) qrcode.save('/tmp/key.png') print("The qr code has been created.")
def generate_pdf(card, qrcode_enabled=True) -> str: """ Make a PDF from a card :param card: dict from fetcher.py :return: Binary PDF buffer """ from eclaire.base import SPECIAL_LABELS, MAX_LABEL_CHARS pdf = FPDF("L", "mm", (62, 140)) pdf.set_margins(2.8, 2.8, 2.8) pdf.set_auto_page_break(False, margin=0) pdf.add_page() font = pkg_resources.resource_filename("eclaire", "font/Clairifont.ttf") pdf.add_font("Clairifont", fname=font, uni=True) pdf.set_font("Clairifont", size=40) pdf.multi_cell(0, 18, txt=card.name.upper(), align="L") if qrcode_enabled: qrcode = generate_qr_code(card.shortUrl) qrcode_file = mktemp(suffix=".png", prefix="trello_qr_") qrcode.save(qrcode_file) pdf.image(qrcode_file, 118, 35, 20, 20) os.unlink(qrcode_file) # May we never speak of this again. pdf.set_fill_color(255, 255, 255) pdf.rect(0, 55, 140, 20, "F") pdf.set_font("Clairifont", "", 14) pdf.set_y(-4) labels = ", ".join([ label.name for label in card.labels if label.name not in SPECIAL_LABELS ])[:MAX_LABEL_CHARS] pdf.multi_cell(0, 0, labels, 0, "R") return pdf.output(dest="S").encode("latin-1")
def generate_pdf(card): """ Make a PDF from a card :param card: dict from fetcher.py :return: Binary PDF buffer """ from eclaire.base import SPECIAL_LABELS pdf = FPDF('L', 'mm', (62, 140)) pdf.set_margins(2.8, 2.8, 2.8) pdf.set_auto_page_break(False, margin=0) pdf.add_page() font = pkg_resources.resource_filename('eclaire', 'font/Clairifont.ttf') pdf.add_font('Clairifont', fname=font, uni=True) pdf.set_font('Clairifont', size=48) pdf.multi_cell(0, 18, txt=card.name.upper(), align='L') qrcode = generate_qr_code(card.url) qrcode_file = mktemp(suffix='.png', prefix='trello_qr_') qrcode.save(qrcode_file) pdf.image(qrcode_file, 118, 35, 20, 20) os.unlink(qrcode_file) # May we never speak of this again. pdf.set_fill_color(255, 255, 255) pdf.rect(0, 55, 140, 20, 'F') pdf.set_font('Clairifont', '', 16) pdf.set_y(-4) labels = ', '.join([ label.name for label in card.labels if label.name not in SPECIAL_LABELS ]) pdf.multi_cell(0, 0, labels, 0, 'R') return pdf.output(dest='S')
def generate_pdf(card): """ Make a PDF from a card :param card: dict from fetcher.py :return: Binary PDF buffer """ from eclaire.base import SPECIAL_LABELS pdf = FPDF('L', 'mm', (62, 140)) pdf.set_margins(2.8, 2.8, 2.8) pdf.set_auto_page_break(False, margin=0) pdf.add_page() font = pkg_resources.resource_filename('eclaire', 'font/Clairifont.ttf') pdf.add_font('Clairifont', fname=font, uni=True) pdf.set_font('Clairifont', size=48) pdf.multi_cell(0, 18, txt=card.name.upper(), align='L') qrcode = generate_qr_code(card.url) qrcode_file = mktemp(suffix='.png', prefix='trello_qr_') qrcode.save(qrcode_file) pdf.image(qrcode_file, 118, 35, 20, 20) os.unlink(qrcode_file) # May we never speak of this again. pdf.set_fill_color(255, 255, 255) pdf.rect(0, 55, 140, 20, 'F') pdf.set_font('Clairifont', '', 16) pdf.set_y(-4) labels = ', '.join([label.name for label in card.labels if label.name not in SPECIAL_LABELS]) pdf.multi_cell(0, 0, labels, 0, 'R') return pdf.output(dest='S')
drawing_obj.add(qrcode) renderPM.drawToFile(drawing_obj, fn="roni.png" ) #generate qrcode using qrcode package import qrcode from reportlab.platypus import SimpleDocTemplate,Image from reportlab.lib.styles import getSampleStyleSheet from reportlab.pdfgen import canvas from reportlab.lib.units import cm pdf=canvas.Canvas("tutorial41_1.pdf") pdf.translate(cm,cm) flow_obj=[] code="www.totaltechnoogy123456.com" qrcode=qrcode.make(code) qrcode.save("roni1.png") pdf.drawImage("roni.png",10,50,800,800) pdf.save()