File: code128_barcode.py

package info (click to toggle)
fpdf2 2.8.4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 53,860 kB
  • sloc: python: 39,487; sh: 133; makefile: 12
file content (22 lines) | stat: -rw-r--r-- 479 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from io import BytesIO
from fpdf import FPDF
from barcode import Code128
from barcode.writer import SVGWriter

# Create a new PDF document
pdf = FPDF()
pdf.add_page()

# Set the position and size of the image in the PDF
x = 50
y = 50
w = 100
h = 70

# Generate a Code128 Barcode as SVG:
svg_img_bytes = BytesIO()
Code128("100000902922", writer=SVGWriter()).write(svg_img_bytes)
pdf.image(svg_img_bytes, x=x, y=y, w=w, h=h)

# Output a PDF file:
pdf.output("code128_barcode.pdf")