diff --git a/README.md b/README.md index d91ccc2..c5193ee 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,13 @@ options: - `-n`, `--num-labels`: Number of lables to be printed on the sheet - `-p`, `--pages`: Number of pages to be generated, ignored if -n is present. - `-s`, `--start-position`: Positon of first label to be printed, eighter defined as ROW:COLUMN or NUMBER. Starting from 1 eg. to use the whole sheet it would be 1:1 or 1. Useful if you have a partly used sheet from using `-n`. +- `--prefix`: Prefix in front of digits (default: ASN) +- `--omit-prefix`: Do not print prefix in front of digits (just use it in the generated QR code) +- `--x-offset`: Horizontal (X) offset in mm (default: 0) +- `--y-offset`: Vertical (Y) offset in mm (default: 0) +- `--qr-scale-factor`: Scale Factor of QR code (default: 0.9). Makes this option easier to play around until satisfied with the look. +- `--qr-border-size`: Size of white border around QR code (default: 4) Makes this option easier to play around until satisfied with the look. +- `--split-at`: visually split printed number at given digit position. Multiple times allowed to add multiple spaces. (default: no splitting) ## Supported Sheets Some different sheet types are supported with the `-f`/`--format` argument, however, not all are tested. diff --git a/paperless_asn_qr_codes/main.py b/paperless_asn_qr_codes/main.py index 4f0baf5..a1a0f19 100644 --- a/paperless_asn_qr_codes/main.py +++ b/paperless_asn_qr_codes/main.py @@ -10,13 +10,39 @@ def render(c, x, y): global startASN global digits - barcode_value = f"ASN{startASN:0{digits}d}" + global prefix + global omit_prefix + barcode_value = f"{startASN:0{digits}d}" startASN = startASN + 1 + splitting = split_at + qr = QRCodeImage(f"{prefix}{barcode_value}", size=y * + qr_scale_factor, border=qr_border_size) + qr.drawOn(c, 1 * mm, (y * (1-qr_scale_factor))/2) + if omit_prefix: + c.setFont("Helvetica", 3.5 * mm) + c.drawString(y, (y - 2 * mm) / 2, + format_number(barcode_value, splitting)) + else: + c.setFont("Helvetica", 2 * mm) + c.drawString(y, (y - 2 * mm) / 2, + f"{prefix}{format_number(barcode_value, splitting)}") + + +def format_number(s, positions): + # Create a list to store the parts of the string + parts = [] + start = 0 + + # Loop through each position where you want to split the string + for pos in positions: + parts.append(s[start:pos]) + start = pos + + # Add the remaining part of the string after the last position + parts.append(s[start:]) - qr = QRCodeImage(barcode_value, size=y * 0.9) - qr.drawOn(c, 1 * mm, y * 0.05) - c.setFont("Helvetica", 2 * mm) - c.drawString(y, (y - 2 * mm) / 2, barcode_value) + # Join all parts together with a space in between each part + return ' '.join(parts) def main(): @@ -81,12 +107,44 @@ def _start_position(arg): type=_start_position, help="Define the starting position on the sheet, eighter as ROW:COLUMN or COUNT, both starting from 1 (default: 1:1 or 1)", ) + parser.add_argument( + "--prefix", "-P", default="ASN", help="Prefix in front of digits (default: ASN)", type=str + ) + parser.add_argument( + "--omit-prefix", action="store_true", help="Do not print prefix in front of digits" + ) + parser.add_argument( + "--x-offset", "-x", default=0, help="Horizontal (X) offset in mm (default: 0)", type=float + ) + parser.add_argument( + "--y-offset", "-y", default=0, help="Vertical (Y) offset in mm (default: 0)", type=float + ) + parser.add_argument( + "--qr-scale-factor", default=0.9, help="Scale Factor of QR code (default: 0.9)", type=float + ) + parser.add_argument( + "--qr-border-size", default=4, help="Size of white border around QR code (default: 4)", type=float + ) + parser.add_argument( + "--split-at", default=[], help="visually split number at digit. multiple allowed (default: no splitting)", type=int, action='append' + ) args = parser.parse_args() global startASN global digits + global prefix + global omit_prefix + global qr_scale_factor + global qr_border_size + global split_at startASN = int(args.start_asn) digits = int(args.digits) + prefix = args.prefix + omit_prefix = args.omit_prefix + qr_scale_factor = args.qr_scale_factor + qr_border_size = args.qr_border_size + split_at = args.split_at + label = avery_labels.AveryLabel( args.format, args.border, topDown=args.row_wise, start_pos=args.start_position ) @@ -98,5 +156,7 @@ def _start_position(arg): else: # Otherwise number of pages*labels - offset count = args.pages * label.across * label.down - label.position + label.margins = (label.margins[0] + args.x_offset * + mm, label.margins[1] + args.y_offset * mm) label.render(render, count) label.close()