WIP: final positioning for the tickets
Generate with: python generate.py -n 24 --size 93 -m 20 -o eintrittskarten.pdf https://kara.d3q.de -g 12
This commit is contained in:
parent
2e001e5858
commit
64aa6b82ff
24
generate.py
24
generate.py
@ -29,6 +29,7 @@ if __name__ == "__main__":
|
|||||||
parser.add_argument("-o", "--output", type=str, help="Output file, defaults to 'qrcodes.pdf'.", default="qrcodes.pdf")
|
parser.add_argument("-o", "--output", type=str, help="Output file, defaults to 'qrcodes.pdf'.", default="qrcodes.pdf")
|
||||||
parser.add_argument("-s", "--size", type=int, help="Ticket height, defaults to 150.", default=150)
|
parser.add_argument("-s", "--size", type=int, help="Ticket height, defaults to 150.", default=150)
|
||||||
parser.add_argument("-m", "--margin", type=int, help="Margin (depends on printer), defaults to 0.", default=0)
|
parser.add_argument("-m", "--margin", type=int, help="Margin (depends on printer), defaults to 0.", default=0)
|
||||||
|
parser.add_argument("-g", "--gap", type=int, help="Gap between tickets, defaults to 0.", default=0)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
@ -53,16 +54,16 @@ if __name__ == "__main__":
|
|||||||
used_usernames = set()
|
used_usernames = set()
|
||||||
|
|
||||||
ticket_height = args.size
|
ticket_height = args.size
|
||||||
qr_code_size = ticket_height/2
|
qr_code_size = ticket_height/1.5
|
||||||
logo = svg2rlg("img/karaoke-outline.svg")
|
logo = svg2rlg("img/karaoke-outline.svg")
|
||||||
scaling_factor = ticket_height/logo.height
|
scaling_factor = ticket_height/logo.height/2
|
||||||
logo.scale(scaling_factor, scaling_factor)
|
logo.scale(scaling_factor, scaling_factor)
|
||||||
logo_width = logo.width*scaling_factor
|
logo_width = logo.width*scaling_factor
|
||||||
logo_height = logo.height*scaling_factor
|
logo_height = logo.height*scaling_factor
|
||||||
|
|
||||||
ticket_width = logo_width + qr_code_size
|
ticket_width = logo_width + qr_code_size
|
||||||
codes_per_row = floor((page_width-args.margin*2)/ticket_width)
|
codes_per_row = floor((page_width-args.margin*2)/(ticket_width+args.gap))
|
||||||
codes_per_col = floor((page_height-args.margin*2)/ticket_height)
|
codes_per_col = floor((page_height-args.margin*2)/(ticket_height+args.gap/2))
|
||||||
if codes_per_col == 0 or codes_per_row == 0:
|
if codes_per_col == 0 or codes_per_row == 0:
|
||||||
raise Exception(f"There is not enough space on A4 page to fit a QR code of size {ticket_width}x{ticket_height}!")
|
raise Exception(f"There is not enough space on A4 page to fit a QR code of size {ticket_width}x{ticket_height}!")
|
||||||
codes_per_page = codes_per_row*codes_per_col
|
codes_per_page = codes_per_row*codes_per_col
|
||||||
@ -79,15 +80,20 @@ if __name__ == "__main__":
|
|||||||
code_width = bounds[2] - bounds[0]
|
code_width = bounds[2] - bounds[0]
|
||||||
code_height = bounds[3] - bounds[1]
|
code_height = bounds[3] - bounds[1]
|
||||||
|
|
||||||
|
current_x = args.margin+(ticket_width+args.gap)*x
|
||||||
|
current_y = args.margin+(ticket_height+args.gap/1.2)*y
|
||||||
|
|
||||||
drawing = Drawing(ticket_height, ticket_height, transform=[qr_code_size/code_width, 0, 0, qr_code_size/code_height, 0, 0])
|
drawing = Drawing(ticket_height, ticket_height, transform=[qr_code_size/code_width, 0, 0, qr_code_size/code_height, 0, 0])
|
||||||
drawing.add(qr_code)
|
drawing.add(qr_code)
|
||||||
renderPDF.draw(logo, pdf, args.margin+ticket_width*(x%codes_per_row), args.margin+ticket_height*(y%codes_per_col))
|
renderPDF.draw(logo, pdf, current_x, current_y+35)
|
||||||
pdf.drawString(args.margin+ticket_width*(x%codes_per_row), args.margin+ticket_height*(y%codes_per_col), url)
|
|
||||||
|
pdf.setFont("Helvetica", 12)
|
||||||
|
pdf.drawRightString(current_x+logo_width, current_y+16, "Hier anmelden →")
|
||||||
|
|
||||||
pdf.drawString(args.margin+ticket_width*(x%codes_per_row), args.margin+ticket_height*(y%codes_per_col)+logo_height, "Hier Code scannen")
|
pdf.setFont("Helvetica", 8)
|
||||||
pdf.drawString(args.margin+ticket_width*(x%codes_per_row), args.margin+ticket_height*(y%codes_per_col)+logo_height-10, "und Song anmelden!")
|
pdf.drawRightString(current_x+logo_width+qr_code_size-7, current_y, url)
|
||||||
|
|
||||||
renderPDF.draw(drawing, pdf, args.margin+ticket_width*(x%codes_per_row)+logo_width, args.margin+ticket_height*(y%codes_per_col))
|
renderPDF.draw(drawing, pdf, current_x+logo_width, current_y+5)
|
||||||
generated_codes += 1
|
generated_codes += 1
|
||||||
if generated_codes >= args.number:
|
if generated_codes >= args.number:
|
||||||
pdf.save()
|
pdf.save()
|
||||||
|
File diff suppressed because one or more lines are too long
Before Width: | Height: | Size: 101 KiB After Width: | Height: | Size: 25 KiB |
Loading…
x
Reference in New Issue
Block a user