PDF Generator
albert.collections.pdf_generator.PDFGeneratorCollection
Bases: BaseCollection
Manage PDF, barcode, and QR code generation in the Albert platform.
Renders Mustache HTML templates with data into stored PDFs, and generates
barcode and QR code images from text. This is the rendering engine behind
printable label templates; see
LabelTemplateCollection
for the higher-level label workflow.
This collection is accessed as client.pdf_generator.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
AlbertSession
|
The authenticated Albert session used for API calls. |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
base_path |
str
|
The base API route for PDF generator requests. |
Methods:
| Name | Description |
|---|---|
generate_pdf |
Render a PDF from an HTML template and data, returning a download URL. |
generate_barcode |
Generate a barcode image from text. |
generate_qr_code |
Generate a QR code image from text. |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
AlbertSession
|
The authenticated Albert session used for API calls. |
required |
Source code in src/albert/collections/pdf_generator.py
generate_pdf
generate_pdf(
*,
template: PDFTemplate,
data: dict[str, Any],
s3_storage: PDFS3Storage,
options: PDFOptions | dict[str, Any] | None = None,
albert_id: str | None = None,
) -> str
Render a PDF from an HTML template and data.
The template HTML is rendered with data using Mustache
placeholders, printed to PDF, and stored at the s3_storage
destination. A short-lived download URL for the PDF is returned.
The inputs typically come from a
LabelPrintPayload
produced by
get_print_payload.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
template
|
PDFTemplate
|
The HTML template sources to render. |
required |
data
|
dict[str, Any]
|
The values substituted into the template's Mustache placeholders. |
required |
s3_storage
|
PDFS3Storage
|
Where the generated PDF is stored. |
required |
options
|
PDFOptions or dict[str, Any]
|
Page rendering options. See |
None
|
albert_id
|
str
|
An optional identifier to associate with the generated PDF. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
A short-lived URL for downloading the generated PDF. |
Source code in src/albert/collections/pdf_generator.py
generate_barcode
Generate a barcode image from text.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The text to encode in the barcode. |
required |
text_size
|
int
|
The size of the human-readable text rendered below the barcode. |
None
|
as_signed_url
|
bool
|
When True, return a short-lived URL for the stored barcode image
instead of an inline |
False
|
Returns:
| Type | Description |
|---|---|
str
|
The barcode image as a base64 |
Source code in src/albert/collections/pdf_generator.py
generate_qr_code
Generate a QR code image from text.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The text to encode in the QR code. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The QR code image as a base64 |