Filename: Private: No Yes Filetype: Auto ABAP Sophia Apex Azure CLI Batch Bicep C Cameligo Clojure CoffeeScript C++ C# CSP CSS Cypher Dart Dockerfile ECL Elixir Flow9 FreeMarker2 FreeMarker2 (Angle/Bracket) FreeMarker2 (Angle/Dollar) FreeMarker2 (Auto/Bracket) FreeMarker2 (Auto/Dollar) FreeMarker2 (Bracket/Bracket) FreeMarker2 (Bracket/Dollar) F# Go GraphQL Handlebars Terraform HTML Ini Java JavaScript Julia Kotlin Less Lexon Liquid Lua Modula-3 Markdown MDX MIPS DAX MySQL Objective-C Pascal Pascaligo Perl PostgreSQL PHP Plain text ATS PQ PowerShell Protobuf Pug Python Q# R Razor Redis Redshift ReStructuredText Ruby Rust Small Basic Scala Scheme Sass Shell Solidity SPARQL SQL StructuredText Swift SV Tcl Twig TypeScript TypeSpec Visual Basic V WebGPU Shading Language XML YAML Indentation: Spaces Tabs 1 2 3 4 5 6 7 8 Clone import qrcode from reportlab.lib.pagesizes import letter from reportlab.pdfgen import canvas from reportlab.lib.units import inch from reportlab.pdfbase.ttfonts import TTFont from reportlab.pdfbase import pdfmetrics def load_vcards(filename): """ Load vCard data from the specified file. """ with open(filename, 'r') as file: vcards_data = file.read().strip().split('\n\n') # Assuming each vCard is separated by a blank line return vcards_data def extract_vcard_info(vcard): lines = vcard.split('\n') info = {} for line in lines: if line.startswith('FN:'): info['name'] = line[3:] return info def generate_qr_code(data, filename): qr = qrcode.QRCode( version=1, error_correction=qrcode.constants.ERROR_CORRECT_L, box_size=10, border=4, ) qr.add_data(data) qr.make(fit=True) img = qr.make_image(fill='black', back_color='white') img.save(filename) def create_pdf(filename, labels): # Avery 5164 label dimensions and layout page_width, page_height = letter labels_per_row = 2 labels_per_column = 3 label_width = 4.0 * inch label_height = 3.33 * inch margin_x = 0.156 * inch margin_y = 0.5 * inch # Register the Arial font font_path = "/usr/share/fonts/truetype/msttcorefonts/Arial.ttf" # Path to Arial font pdfmetrics.registerFont(TTFont('Arial', font_path)) # Create a canvas to draw the PDF c = canvas.Canvas(filename, pagesize=letter) c.setFont("Arial", 22) # Draw each label on the PDF for i, (name, qr_code_file) in enumerate(labels): col = i % labels_per_row row = i // labels_per_row if row >= labels_per_column: break x = margin_x + col * (label_width + margin_x) y = page_height - margin_y - (row + 1) * label_height # Draw name at the top c.drawString(x + label_width / 2 - inch, y + label_height - 60, name) # Center the QR code in the label qr_code_size = 2 * inch # Size of the QR code qr_code_x = x + (label_width - qr_code_size) / 2 qr_code_y = y + (label_height - qr_code_size) / 2 - 20 # Adjust the QR code position to leave space for the name c.drawImage(qr_code_file, qr_code_x, qr_code_y, width=qr_code_size, height=qr_code_size) c.save() def main(): # vcards = load_vcards('vcards.txt') labels = [] for i, vcard in enumerate(vcards): info = extract_vcard_info(vcard) name = info.get('name', 'No Name') qr_code_file = f'qr_code_{i}.png' generate_qr_code(vcard, qr_code_file) labels.append((name, qr_code_file)) create_pdf('labels.pdf', labels) vcards = [ "BEGIN:VCARD\nVERSION:3.0\nN:DevOpsDays Montreal 2024\nFN:DevOpsDays Montreal 2024\nORG:\nTITLE:N1\nTEL;TYPE=WORK,VOICE:(111) 111-1111\nADR;TYPE=HOME:;;2200 rue Mansfield;Montreal;QC;H3A3R8;Canada\nEMAIL:montreal@devopsdays.org\nEND:VCARD", "BEGIN:VCARD\nVERSION:3.0\nN:DevOpsDays Montreal 2024\nFN:DevOpsDays Montreal 2024\nORG:\nTITLE:N2\nTEL;TYPE=WORK,VOICE:(111) 111-1111\nADR;TYPE=HOME:;;2200 rue Mansfield;Montreal;QC;H3A3R8;Canada\nEMAIL:montreal@devopsdays.org\nEND:VCARD", "BEGIN:VCARD\nVERSION:3.0\nN:DevOpsDays Montreal 2024\nFN:DevOpsDays Montreal 2024\nORG:\nTITLE:N3\nTEL;TYPE=WORK,VOICE:(111) 111-1111\nADR;TYPE=HOME:;;2200 rue Mansfield;Montreal;QC;H3A3R8;Canada\nEMAIL:montreal@devopsdays.org\nEND:VCARD", "BEGIN:VCARD\nVERSION:3.0\nN:DevOpsDays Montreal 2024\nFN:DevOpsDays Montreal 2024\nORG:\nTITLE:N4\nTEL;TYPE=WORK,VOICE:(111) 111-1111\nADR;TYPE=HOME:;;2200 rue Mansfield;Montreal;QC;H3A3R8;Canada\nEMAIL:montreal@devopsdays.org\nEND:VCARD", "BEGIN:VCARD\nVERSION:3.0\nN:DevOpsDays Montreal 2024\nFN:DevOpsDays Montreal 2024\nORG:\nTITLE:N5\nTEL;TYPE=WORK,VOICE:(111) 111-1111\nADR;TYPE=HOME:;;2200 rue Mansfield;Montreal;QC;H3A3R8;Canada\nEMAIL:montreal@devopsdays.org\nEND:VCARD", "BEGIN:VCARD\nVERSION:3.0\nN:DevOpsDays Montreal 2024\nFN:DevOpsDays Montreal 2024\nORG:\nTITLE:N6\nTEL;TYPE=WORK,VOICE:(111) 111-1111\nADR;TYPE=HOME:;;2200 rue Mansfield;Montreal;QC;H3A3R8;Canada\nEMAIL:montreal@devopsdays.org\nEND:VCARD" ] # Run the main function if __name__ == "__main__": main() Paste