Skip to content

Commit

Permalink
[Added] Doc on generating Code128 Barcode (#746)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssavi-ict authored Mar 31, 2023
1 parent 338977a commit 88b41b7
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ This can also be enabled programmatically with `warnings.simplefilter('default',
### Fixed
- the SVG parser now accepts `<rect>` with `width` / `height` defined as percents

### Added
- documentation on how to generate Code128 barcodes using the `python-barcode` lib: [documentation section](https://pyfpdf.github.io/fpdf2/Barcodes.html#Code128)

## [2.7.1] - 2023-03-27
### Changed
- renamed `fonts.FontStyle` to [`fonts.FontFace`](https://pyfpdf.github.io/fpdf2/fpdf/fonts.html#fpdf.fonts.FontFace), and `FPDF.use_font_style` to [`FPDF.use_font_face`](https://pyfpdf.github.io/fpdf2/fpdf/fpdf.html#fpdf.FPDF.FPDF.use_font_face), to avoid confusions with `FPDF.font_style`
Expand Down
34 changes: 34 additions & 0 deletions docs/Barcodes.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,37 @@ pdf.set_font("Helvetica", size=24)
pdf.datamatrix("Hello world!", w=100)
pdf.output("datamatrix.pdf")
```

## Code128 ##

Here is an example on how to generate a [Code 128](https://en.wikipedia.org/wiki/Code_128) barcode
using the [`python-barcode`](https://github.com/WhyNotHugo/python-barcode) lib:

```
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
byte_stream_object = BytesIO()
Code128(str("100000902922"), writer=SVGWriter()).write(byte_stream_object)
pdf.image(byte_stream_object, x=x, y=y, w=w, h=h)
# Output a PDF named code128_barcode.pdf
pdf.output('code128_barcode.pdf')
```

Output Preview:
![](code128_barcode.png)

Binary file added docs/code128_barcode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 88b41b7

Please sign in to comment.