PDF Resource
The PDF resource generates a PDF file from HTML or Markdown content using one of three rendering backends. It can be used as a primary resource or as an inline resource inside before / after blocks.
Basic Usage
apiVersion: kdeps.io/v1
kind: Resource
metadata:
actionId: generateReport
name: Generate Report
run:
pdf:
content: "<h1>Hello, World!</h1><p>This is a PDF report.</p>"
contentType: html
backend: wkhtmltopdfConfiguration Options
| Option | Type | Description |
|---|---|---|
content | string | Required. The HTML or Markdown source to render. Supports expressions. |
contentType | string | html (default) or markdown. |
backend | string | wkhtmltopdf (default), pandoc, or weasyprint. |
outputFile | string | Explicit output path for the PDF. If omitted, a path under /tmp/kdeps-pdf/ is auto-generated. |
options | list | Extra CLI flags passed directly to the backend binary. |
timeoutDuration | string | Maximum time allowed for the backend to run (e.g. 120s, 2m). Default: 60s. |
Backends
wkhtmltopdf (default)
Renders HTML to PDF using the wkhtmltopdf CLI. When contentType: markdown, the Markdown is wrapped in a minimal HTML skeleton before rendering.
Install:
# macOS
brew install wkhtmltopdf
# Debian/Ubuntu
apt install wkhtmltopdfrun:
pdf:
content: "<h1>Report</h1><p>Generated by KDeps.</p>"
contentType: html
backend: wkhtmltopdf
options:
- "--page-size"
- "A4"
- "--margin-top"
- "10mm"pandoc
Converts HTML or Markdown to PDF via pandoc + a LaTeX engine (e.g. pdflatex or xelatex). Best choice for Markdown-heavy documents and academic/technical reports.
Install:
# macOS
brew install pandoc mactex
# Debian/Ubuntu
apt install pandoc texlive-xetexrun:
pdf:
content: |
# My Report
This is a **Markdown** report with _formatting_.
- Item one
- Item two
contentType: markdown
backend: pandoc
options:
- "--pdf-engine=xelatex"
- "--variable"
- "geometry:margin=1in"weasyprint
Renders HTML/CSS to PDF using the WeasyPrint Python library. Excellent CSS support; good for styled reports and invoices.
Install:
pip install weasyprintrun:
pdf:
content: |
<html>
<head><style>
body { font-family: Arial, sans-serif; }
h1 { color: #333; }
</style></head>
<body><h1>Styled Report</h1><p>Beautiful CSS-rendered PDF.</p></body>
</html>
contentType: html
backend: weasyprintAccessing the Output File
After the PDF resource runs, the result map is available via get('actionId'):
| Key | Type | Description |
|---|---|---|
success | bool | true if the PDF was generated successfully. |
outputFile | string | Absolute path to the generated PDF file. |
backend | string | Backend used (e.g. wkhtmltopdf). |
contentType | string | Content type used (html or markdown). |
sizeBytes | int | File size of the generated PDF in bytes. |
resources:
- metadata:
actionId: generateReport
run:
pdf:
content: "<h1>Report</h1>"
backend: wkhtmltopdf
- metadata:
actionId: sendReport
requires: [generateReport]
run:
apiResponse:
success: true
response:
pdfPath: "{{ get('generateReport').outputFile }}"
sizeBytes: "{{ get('generateReport').sizeBytes }}"PDF as an Inline Resource
PDF generation can run before or after the main resource action:
run:
before:
- pdf:
content: "<h1>Pre-flight doc</h1>"
backend: wkhtmltopdf
chat:
model: llama3
prompt: "{{ input() }}"
after:
- pdf:
content: "<h1>Summary</h1><p>{{ get('chat') }}</p>"
backend: wkhtmltopdf
outputFile: /tmp/summary.pdfUsing Expressions in content
The content field supports KDeps expressions:
run:
pdf:
content: |
<h1>Report for {{ get("name") }}</h1>
<p>Score: <strong>{{ get("score") }}</strong> / 100</p>
<p>Generated: {{ info("timestamp") }}</p>
contentType: html
backend: wkhtmltopdfExample: CV/JD Match Report
Full pipeline: scrape a job description, score the match, generate a PDF report.
# resources/scrapeJD.yaml
metadata:
actionId: scrapeJD
run:
scraper:
url: "{{ get('jd_url') }}"
# resources/scoreMatch.yaml
metadata:
actionId: scoreMatch
requires: [scrapeJD]
run:
chat:
model: gpt-4o
prompt: |
CV: {{ get('cv_text') }}
Job Description: {{ get('scrapeJD') }}
Rate the match from 0-100 and explain the top 3 strengths and gaps. Output JSON.
# resources/generateReport.yaml
metadata:
actionId: generateReport
requires: [scoreMatch]
run:
pdf:
content: |
<html>
<head><style>
body { font-family: Arial, sans-serif; max-width: 800px; margin: auto; padding: 2em; }
h1 { color: #1a1a2e; }
.score { font-size: 2em; font-weight: bold; color: #16213e; }
</style></head>
<body>
<h1>Match Report</h1>
<p class="score">Score: {{ get('scoreMatch').score }} / 100</p>
<h2>Strengths</h2>
<ul>{{ get('scoreMatch').strengths }}</ul>
<h2>Gaps</h2>
<ul>{{ get('scoreMatch').gaps }}</ul>
</body>
</html>
contentType: html
backend: wkhtmltopdf
outputFile: /tmp/match-report.pdfExample: Motivation Letter
Generate a personalized motivation letter as a PDF using an LLM:
# resources/writeLetter.yaml
metadata:
actionId: writeLetter
run:
chat:
model: gpt-4o
prompt: |
Write a professional motivation letter for this candidate applying to this role.
CV: {{ get('cv_text') }}
Job: {{ get('jd_text') }}
Format as clean HTML with <h1>, <p> tags only.
# resources/letterPDF.yaml
metadata:
actionId: letterPDF
requires: [writeLetter]
run:
pdf:
content: "{{ get('writeLetter') }}"
contentType: html
backend: weasyprint
outputFile: /tmp/motivation-letter.pdfBackend Comparison
| Feature | wkhtmltopdf | pandoc | weasyprint |
|---|---|---|---|
| HTML input | Yes | Yes | Yes |
| Markdown input | Basic (via skeleton) | Native | Basic (via skeleton) |
| CSS support | Good | Limited | Excellent |
| LaTeX required | No | Yes | No |
| JavaScript | Yes | No | No |
| Install size | Medium | Large | Small (pip) |
| Best for | HTML reports, invoices | Academic/tech docs | Styled reports |
Validator Rules
The pdf resource is validated before execution:
contentmust not be empty.contentTypemust behtmlormarkdown(if set).backendmust bewkhtmltopdf,pandoc, orweasyprint(if set).- A resource may only declare one primary executor (
pdf,chat,exec, etc.).
Next Steps
- Scraper Resource - Extract content from web pages and documents
- LLM Resource - Generate content with AI models
- Exec Resource - Run shell commands
- TTS Resource - Text-to-Speech synthesis
- API Response - Return data to the HTTP caller