PDF Generator
albert.resources.pdf_generator
PDFTemplate
Bases: BaseAlbertModel
The HTML template sources used to render a PDF.
Each source is an HTML file with Mustache placeholders: {{field}}
inserts a value, {{#list}}...{{/list}} repeats a block per item, and
{{{field}}} inserts without HTML escaping (needed for image URLs).
The valid placeholder names are exactly the keys of the data object
supplied at render time, using dotted paths for nested values. Label
payloads pass data={"labels": [...]}, so those templates wrap their
body in {{#labels}}...{{/labels}} and read each entity's fields under
{{info.<field>}}.
When header or footer is set, the pages render with that header or
footer template. Header and footer templates can show page numbers and
document metadata via elements with the classes pageNumber,
totalPages, date, and title (e.g.
<span class="pageNumber"></span>).
Show JSON schema:
{
"description": "The HTML template sources used to render a PDF.\n\nEach source is an HTML file with Mustache placeholders: ``{{field}}``\ninserts a value, ``{{#list}}...{{/list}}`` repeats a block per item, and\n``{{{field}}}`` inserts without HTML escaping (needed for image URLs).\nThe valid placeholder names are exactly the keys of the ``data`` object\nsupplied at render time, using dotted paths for nested values. Label\npayloads pass ``data={\"labels\": [...]}``, so those templates wrap their\nbody in ``{{#labels}}...{{/labels}}`` and read each entity's fields under\n``{{info.<field>}}``.\n\nWhen ``header`` or ``footer`` is set, the pages render with that header or\nfooter template. Header and footer templates can show page numbers and\ndocument metadata via elements with the classes ``pageNumber``,\n``totalPages``, ``date``, and ``title`` (e.g.\n``<span class=\"pageNumber\"></span>``).",
"properties": {
"body": {
"description": "URL or S3 path of the Mustache HTML template for the document body.",
"title": "Body",
"type": "string"
},
"header": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "URL or S3 path of the Mustache HTML template for the page header, optional.",
"title": "Header"
},
"footer": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "URL or S3 path of the Mustache HTML template for the page footer, optional.",
"title": "Footer"
}
},
"required": [
"body"
],
"title": "PDFTemplate",
"type": "object"
}
Fields:
PDFMargin
Bases: BaseAlbertModel
Page margins for a rendered PDF, as CSS lengths (e.g. "0mm", "0.5in").
Show JSON schema:
{
"description": "Page margins for a rendered PDF, as CSS lengths (e.g. ``\"0mm\"``, ``\"0.5in\"``).",
"properties": {
"top": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "Top margin.",
"title": "Top"
},
"bottom": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "Bottom margin.",
"title": "Bottom"
},
"left": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "Left margin.",
"title": "Left"
},
"right": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "Right margin.",
"title": "Right"
}
},
"title": "PDFMargin",
"type": "object"
}
Fields:
PDFOptions
Bases: BaseAlbertModel
Page rendering options for a generated PDF.
These are the only rendering settings the PDF generator reads; any other
keys are ignored. Set either format or an explicit width and
height pair (both must be set for the pair to apply).
Show JSON schema:
{
"$defs": {
"PDFMargin": {
"description": "Page margins for a rendered PDF, as CSS lengths (e.g. ``\"0mm\"``, ``\"0.5in\"``).",
"properties": {
"top": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "Top margin.",
"title": "Top"
},
"bottom": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "Bottom margin.",
"title": "Bottom"
},
"left": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "Left margin.",
"title": "Left"
},
"right": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "Right margin.",
"title": "Right"
}
},
"title": "PDFMargin",
"type": "object"
}
},
"description": "Page rendering options for a generated PDF.\n\nThese are the only rendering settings the PDF generator reads; any other\nkeys are ignored. Set either ``format`` or an explicit ``width`` and\n``height`` pair (both must be set for the pair to apply).",
"properties": {
"width": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "Page width as a CSS length (e.g. ``\"3in\"``). Applied together with ``height``.",
"title": "Width"
},
"height": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "Page height as a CSS length (e.g. ``\"1in\"``). Applied together with ``width``.",
"title": "Height"
},
"format": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "Named paper format (e.g. ``\"A4\"``, ``\"Letter\"``). Alternative to\n``width``/``height``.",
"title": "Format"
},
"margin": {
"anyOf": [
{
"$ref": "#/$defs/PDFMargin"
},
{
"type": "null"
}
],
"default": null,
"description": "Page margins, optional."
},
"landscape": {
"anyOf": [
{
"type": "boolean"
},
{
"type": "null"
}
],
"default": null,
"description": "When True, render in landscape orientation.",
"title": "Landscape"
},
"renderBackgroundImage": {
"anyOf": [
{
"type": "boolean"
},
{
"type": "null"
}
],
"default": null,
"description": "When True, print CSS background colors and images.",
"title": "Renderbackgroundimage"
},
"hideHeaderFromFirstPage": {
"anyOf": [
{
"type": "boolean"
},
{
"type": "null"
}
],
"default": null,
"description": "When True and a header template is set, the first page renders without\nthe header.",
"title": "Hideheaderfromfirstpage"
}
},
"title": "PDFOptions",
"type": "object"
}
Fields:
-
width(str | None) -
height(str | None) -
format(str | None) -
margin(PDFMargin | None) -
landscape(bool | None) -
render_background_image(bool | None) -
hide_header_from_first_page(bool | None)
width
width: str | None = None
Page width as a CSS length (e.g. "3in"). Applied together with height.
height
height: str | None = None
Page height as a CSS length (e.g. "1in"). Applied together with width.
format
format: str | None = None
Named paper format (e.g. "A4", "Letter"). Alternative to
width/height.
render_background_image
render_background_image: bool | None = None
When True, print CSS background colors and images.
hide_header_from_first_page
hide_header_from_first_page: bool | None = None
When True and a header template is set, the first page renders without the header.
PDFS3Storage
Bases: BaseAlbertModel
The storage destination for a generated PDF.
Show JSON schema:
{
"description": "The storage destination for a generated PDF.",
"properties": {
"Bucket": {
"description": "The S3 bucket the generated PDF is stored in.",
"title": "Bucket",
"type": "string"
},
"Key": {
"description": "The S3 object key the generated PDF is stored under.",
"title": "Key",
"type": "string"
},
"ACL": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "The S3 ACL applied to the generated PDF, optional.",
"title": "Acl"
},
"forceOverwrite": {
"anyOf": [
{
"type": "boolean"
},
{
"type": "null"
}
],
"default": null,
"description": "When True, regenerate the PDF even if a cached copy already exists.",
"title": "Forceoverwrite"
}
},
"required": [
"Bucket",
"Key"
],
"title": "PDFS3Storage",
"type": "object"
}
Fields:
force_overwrite
force_overwrite: bool | None = None
When True, regenerate the PDF even if a cached copy already exists.
PDFGenerationRequest
Bases: BaseAlbertModel
A request to render a PDF from HTML templates and data.
The template HTML is rendered with data using Mustache placeholders,
printed to PDF, and stored at the s3_storage destination.
Show JSON schema:
{
"$defs": {
"PDFMargin": {
"description": "Page margins for a rendered PDF, as CSS lengths (e.g. ``\"0mm\"``, ``\"0.5in\"``).",
"properties": {
"top": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "Top margin.",
"title": "Top"
},
"bottom": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "Bottom margin.",
"title": "Bottom"
},
"left": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "Left margin.",
"title": "Left"
},
"right": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "Right margin.",
"title": "Right"
}
},
"title": "PDFMargin",
"type": "object"
},
"PDFOptions": {
"description": "Page rendering options for a generated PDF.\n\nThese are the only rendering settings the PDF generator reads; any other\nkeys are ignored. Set either ``format`` or an explicit ``width`` and\n``height`` pair (both must be set for the pair to apply).",
"properties": {
"width": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "Page width as a CSS length (e.g. ``\"3in\"``). Applied together with ``height``.",
"title": "Width"
},
"height": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "Page height as a CSS length (e.g. ``\"1in\"``). Applied together with ``width``.",
"title": "Height"
},
"format": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "Named paper format (e.g. ``\"A4\"``, ``\"Letter\"``). Alternative to\n``width``/``height``.",
"title": "Format"
},
"margin": {
"anyOf": [
{
"$ref": "#/$defs/PDFMargin"
},
{
"type": "null"
}
],
"default": null,
"description": "Page margins, optional."
},
"landscape": {
"anyOf": [
{
"type": "boolean"
},
{
"type": "null"
}
],
"default": null,
"description": "When True, render in landscape orientation.",
"title": "Landscape"
},
"renderBackgroundImage": {
"anyOf": [
{
"type": "boolean"
},
{
"type": "null"
}
],
"default": null,
"description": "When True, print CSS background colors and images.",
"title": "Renderbackgroundimage"
},
"hideHeaderFromFirstPage": {
"anyOf": [
{
"type": "boolean"
},
{
"type": "null"
}
],
"default": null,
"description": "When True and a header template is set, the first page renders without\nthe header.",
"title": "Hideheaderfromfirstpage"
}
},
"title": "PDFOptions",
"type": "object"
},
"PDFS3Storage": {
"description": "The storage destination for a generated PDF.",
"properties": {
"Bucket": {
"description": "The S3 bucket the generated PDF is stored in.",
"title": "Bucket",
"type": "string"
},
"Key": {
"description": "The S3 object key the generated PDF is stored under.",
"title": "Key",
"type": "string"
},
"ACL": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "The S3 ACL applied to the generated PDF, optional.",
"title": "Acl"
},
"forceOverwrite": {
"anyOf": [
{
"type": "boolean"
},
{
"type": "null"
}
],
"default": null,
"description": "When True, regenerate the PDF even if a cached copy already exists.",
"title": "Forceoverwrite"
}
},
"required": [
"Bucket",
"Key"
],
"title": "PDFS3Storage",
"type": "object"
},
"PDFTemplate": {
"description": "The HTML template sources used to render a PDF.\n\nEach source is an HTML file with Mustache placeholders: ``{{field}}``\ninserts a value, ``{{#list}}...{{/list}}`` repeats a block per item, and\n``{{{field}}}`` inserts without HTML escaping (needed for image URLs).\nThe valid placeholder names are exactly the keys of the ``data`` object\nsupplied at render time, using dotted paths for nested values. Label\npayloads pass ``data={\"labels\": [...]}``, so those templates wrap their\nbody in ``{{#labels}}...{{/labels}}`` and read each entity's fields under\n``{{info.<field>}}``.\n\nWhen ``header`` or ``footer`` is set, the pages render with that header or\nfooter template. Header and footer templates can show page numbers and\ndocument metadata via elements with the classes ``pageNumber``,\n``totalPages``, ``date``, and ``title`` (e.g.\n``<span class=\"pageNumber\"></span>``).",
"properties": {
"body": {
"description": "URL or S3 path of the Mustache HTML template for the document body.",
"title": "Body",
"type": "string"
},
"header": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "URL or S3 path of the Mustache HTML template for the page header, optional.",
"title": "Header"
},
"footer": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "URL or S3 path of the Mustache HTML template for the page footer, optional.",
"title": "Footer"
}
},
"required": [
"body"
],
"title": "PDFTemplate",
"type": "object"
}
},
"description": "A request to render a PDF from HTML templates and data.\n\nThe ``template`` HTML is rendered with ``data`` using Mustache placeholders,\nprinted to PDF, and stored at the ``s3_storage`` destination.",
"properties": {
"template": {
"$ref": "#/$defs/PDFTemplate",
"description": "The HTML template sources to render."
},
"data": {
"additionalProperties": true,
"description": "The values substituted into the template's Mustache placeholders.",
"title": "Data",
"type": "object"
},
"s3Storage": {
"$ref": "#/$defs/PDFS3Storage",
"description": "Where the generated PDF is stored."
},
"options": {
"anyOf": [
{
"$ref": "#/$defs/PDFOptions"
},
{
"additionalProperties": true,
"type": "object"
},
{
"type": "null"
}
],
"default": null,
"description": "Page rendering options, optional. See [`PDFOptions`][albert.resources.pdf_generator.PDFOptions]\nfor the recognized settings.",
"title": "Options"
},
"albertId": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "An identifier to associate with the generated PDF, optional.",
"title": "Albertid"
}
},
"required": [
"template",
"s3Storage"
],
"title": "PDFGenerationRequest",
"type": "object"
}
Fields:
-
template(PDFTemplate) -
data(dict[str, Any]) -
s3_storage(PDFS3Storage) -
options(PDFOptions | dict[str, Any] | None) -
albert_id(str | None)
options
options: PDFOptions | dict[str, Any] | None = None
Page rendering options, optional. See PDFOptions
for the recognized settings.