Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Added] Doc on generating Code128 Barcode #746

Merged
merged 3 commits into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.