Generate PDF Job
Queue a PDF generation job and retrieve its status and result.
Each job request contains the structured data, HTML (or Markdown), and CSS needed to
render one document. The optional filename fields are descriptive metadata only; the
content fields carry the actual inline HTML and CSS.
To send image files with the template, use the multipart
/pdf/generate/bundle endpoint described in Bundled images and scaling. It uses this same
request object plus named binary image uploads, with no base64 URLs required.
Authentication
Influxion uses OAuth2 Bearer tokens issued by its /token endpoint. First obtain a token:
POST /token HTTP/1.1
Content-Type: application/json
{
"client_id": "<CLIENT_ID>",
"client_secret": "<CLIENT_SECRET>",
"scope": "api://d88ae758-e67d-492d-bcc6-63f560ee1f04/.default"
}
Note
The scope is optional. A default scope will be assigned if not provided, and it will allow access to all API endpoints.
Response:
{
"access_token": "<YOUR_JWT>",
"token_type": "bearer"
}
All subsequent API calls must include the Authorization header with value Bearer <YOUR_JWT>.
Create a job
Request:
POST /pdf/generate HTTP/1.1
Authorization: Bearer <YOUR_JWT>
Content-Type: application/json
{
"data": { /* structured data for the Jinja2 template */ },
"document_id": "my-doc-123",
"pdf_standard": "pdf/a-1b",
"sign_key_id": "sign-key-id",
"html_template": {
"filename": null,
"content": "<html>...{{ data }}...</html>"
},
"css_template": {
"filename": null,
"content": "body { font-family: 'Futura PT', 'DejaVu Sans', sans-serif; }"
}
}
Response:
{
"job_id": 1,
"document_id": "my-doc-123"
}
Check job status
GET /pdf/1 HTTP/1.1
Authorization: Bearer <YOUR_JWT>
Response:
{
"id": 1,
"status": "Received",
"created_at": "2023-01-01T12:00:00Z",
"started_at": null,
"completed_at": null,
"pdf_expires_at": null,
"size": null,
"error": null
}
The status can be Received, InProgress, Done, or Error.
Download PDF
GET /pdf/1/download HTTP/1.1
Authorization: Bearer <YOUR_JWT>
Response: Binary PDF (Content-Type: application/pdf).
Input types: HTML and Markdown
/pdf/generate accepts two kinds of input, selected with the optional
input_type field:
|
Document field |
CSS |
|---|---|---|
|
|
|
|
|
|
Requests without input_type behave exactly as before. Sending the field for
the other input type (for example html_template together with
"input_type": "markdown") is rejected with 422. The job, status,
download, signing and PDF standard handling is the same for both.
Markdown to PDF
Minimal request:
{
"input_type": "markdown",
"markdown_template": { "filename": "notes.md", "content": "# Title\n\nSome *text*." }
}
All Markdown options:
{
"input_type": "markdown",
"markdown_template": { "filename": "notes.md", "content": "# Title\n\nSome *text*." },
"css_template": { "filename": "style.css", "content": "h1 { color: #0b5cad; }" },
"include_default_css": true,
"title": null,
"language": "en",
"data": {},
"document_id": "my-doc-123",
"pdf_standard": "pdf/ua-1",
"sign_key_id": null
}
Syntax: CommonMark-style Markdown plus tables, fenced code blocks with syntax highlighting, footnotes, definition lists, attribute lists (
{: .class }) and[TOC]. Raw HTML is passed through.Title and language:
titlesets the document title and defaults to the first level-one heading.languagesets thelangattribute, which PDF/UA requires.Templating: if
datais non-empty, the Markdown is first rendered as a Jinja2 template withdataavailable (for example{{ data.customer }}). Withoutdatathe Markdown is converted untouched, so code samples containing{{are safe.
Styling Markdown documents
Markdown documents are styled by a bundled stylesheet: A4 pages with page numbers in the footer, Metropolis (with DejaVu Sans as fallback) at 10.5 pt, bordered tables, shaded code blocks and Pygments syntax highlighting. See Fonts for the available font families.
css_template is appended after the bundled stylesheet, so you only need to
write what differs:
@page { margin: 3cm; @bottom-center { content: none; } }
html { font-family: 'Sentinel', 'DejaVu Serif', serif; }
h1 { color: #0b5cad; border-bottom: none; }
Set include_default_css to false to use only your own CSS. Then
css_template is required.
The Markdown is wrapped in <main class="markdown-body"> and code blocks in
<div class="codehilite">, which can be used as CSS selectors. Attribute lists
add classes to individual elements: a line {: .note } directly after a paragraph gives it class="note".
A ready-made client is available in Examples.
Short-lived PDF storage
Completed PDFs are written to the runtime directory configured by
INFLUXION_PDF_RUNTIME_DIR. The default is /run/influxion/pdfs. The file
name is generated by Influxion and includes a random token so it cannot be
guessed from the job ID alone.
The database stores job metadata such as status, document_id, generated file
size, the runtime PDF filename, and pdf_expires_at. The PDF bytes are not
stored in the database, and the submitted HTML/CSS are used only for that
generation request.
Completed PDFs remain downloadable for INFLUXION_PDF_RETENTION_SECONDS
seconds, with a default of 300 seconds. After that timestamp, or if the
runtime file is no longer present, the download endpoint returns 410 Gone.
The application also clears leftover runtime PDF files during startup, so
completed downloads should be treated as temporary handoff files.
Using Celery background workers (Optional)
When setting up Influxion, one can connect it to a RabbitMQ and use Celery for background PDF generation:
pip install -e .
export INFLUXION_USE_CELERY=1
export INFLUXION_CELERY_BROKER_URL=amqp://guest@localhost//
export INFLUXION_CELERY_RESULT_BACKEND=rpc://
celery -A influxion.celery_app worker --loglevel=info
This enables asynchronous PDF generation, allowing the API to respond immediately and several jobs to be processed concurrently.