Crate krilla_rxing

Crate krilla_rxing 

Source
Expand description

krilla-rxing extends the PDF creation library krilla with support for drawing barcodes based on the rxing library. This library aims to make barcode creation easy while optimising the PDF strokes s.t. the output file is as small as possible.

§CLI

If all you need is a tool that creates a PDF for you, take a look at qrcode2pdf. Contrary to the name of the crate, it comes with a tool for all barcode formats supported by this library.

To create a PDF containing a QR Code, you can run

qrcode2pdf -o barcode.pdf https://codeberg.org/msrd0/krilla-rxing/src/branch/main/cli

§Library

If you want to embed barcodes into your existing PDF-writing code, there are two APIs you can use. The simplest way is to call draw_qr_code on krilla’s Surface:

use krilla_rxing::SurfaceExt as _;

const PDF_UNITS_PER_MM: f32 = 72.0 / 25.4;

// draw a 10 x 10 cm QR Code at the top left of the surface
surface
	.draw_qr_code(
		"https://codeberg.org/msrd0/krilla-rxing",
		Point::from_xy(0.0, 0.0),
		100.0 * PDF_UNITS_PER_MM
	)
	.expect("Failed to draw QR Code");

Some other barcode are not necessarily square, and you might want to know the height of the barcode. In these cases, you need to create the barcode and then draw it using the draw_barcode function:

use krilla_rxing::{Barcode, SurfaceExt as _};

const PDF_UNITS_PER_MM: f32 = 72.0 / 25.4;

// draw a 10 x 10 cm PDF417 barcode at the top left of the surface
let barcode_width = 100.0 * PDF_UNITS_PER_MM;
let barcode =
	Barcode::new_pdf417("https://codeberg.org/msrd0/krilla-rxing", barcode_width)
		.expect("Failed to create PDF417 barcode");
let barcode_height = barcode.height();
surface.draw_barcode(&barcode, Point::from_xy(0.0, 0.0));

Structs§

Barcode

Traits§

SurfaceExt
Barcode writing extensions for krilla::surface::Surface.

Type Aliases§

Result