PC load letter
项目描述
pcloadletter
一个从HTML模板生成PDF文档的命令行工具
"PC LOAD LETTER" - WFT这意味着什么?!
安装
pip install pcloadletter
用法
pcloadletter允许您从命令行和/或.yml/.json文件中提供一些上下文数据,从HTML Jinja模板生成PDF文档。
usage: pcloadletter [-h] [-t TEMPLATE] [-o OUT] [-c CONTEXT_FILE] [extra_context ...]
Generate PDF file from a Jinja-rendered HTML template
positional arguments:
extra_context key=value pairs which are added to the template context (default: None)
optional arguments:
-h, --help show this help message and exit
-t TEMPLATE, --template TEMPLATE
The invoice template to render. (default: invoice.html)
-o OUT, --out OUT Destination file. (default: invoice.pdf)
-c CONTEXT_FILE, --context-file CONTEXT_FILE
A .yml or .json file containing context for the template. (default: None)
Examples:
pcloadletter --template templates/invoice.html --out invoice.pdf invoice_number=2021-001 invoice_date=`date +%Y-%m-%d`
pcloadletter --template report.html --context-file=report-data.yml addressee="Mr. M. Bolton"
例如,给定一个模板文件 hello.html
<!doctype html>
<html lang="en">
<head>
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<h1>Hello {{ target }}!</h1>
</body>
</html>
和一个样式表
.h1 {
font-style: italic;
}
我们可以这样渲染pdf;
pcloadletter --template hello.html target="world out there"
上下文可以从上下文文件 hello.yml
中提供;
target: world out there
pcloadletter --template hello.html --context-file=hello.yml
上述命令将在当前目录中生成一个名为 invoice.pdf
的文件。您可以使用
--out=~/Documents/report.pdf