autobasedoc - convenience reportlab tool
Project description
AutoBaseDoc
Automated PDF document generation on top of ReportLab with Matplotlib integration, reusable page templates, and helpers for tables, headers, footers, and table-of-contents handling.
Installation
pip install autobasedoc
Development setup:
git clone https://github.com/NuCOS/autobasedoc.git
cd autobasedoc
pip install -e .
pip install -e ".[test]"
Requirements:
- Python 3.7+
- ReportLab
- Matplotlib
svglib,pdfrw,img2pdf
Quick Start
import os
from autobasedoc import autorpt as ar
outname = os.path.join(os.getcwd(), "MinimalExample.pdf")
doc = ar.AutoDocTemplate(
outname,
onFirstPage=ar.onFirstPage,
onLaterPages=ar.onLaterPages,
onLaterSPages=ar.onLaterSPages,
leftMargin=0.5 * ar.cm,
rightMargin=0.5 * ar.cm,
topMargin=0.5 * ar.cm,
bottomMargin=0.5 * ar.cm,
)
styles = ar.Styles()
styles.registerStyles()
content = []
content.append(ar.Paragraph("Minimal Example Title", styles.title))
content.append(ar.PageBreak())
content.append(ar.Paragraph("Table Of Contents", styles.h1))
content.append(ar.doTableOfContents())
doc.multiBuild(content)
Matplotlib Integration
Use autoPdfImg when a plotting function should return a single ReportLab flowable:
from autobasedoc import autoplot as ap
@ap.autoPdfImg
def create_chart(canvaswidth=5):
fig, ax = ap.plt.subplots(figsize=(canvaswidth, canvaswidth))
ax.plot([1, 2, 3, 4], [1, 4, 2, 3])
ax.set_title("Sample Chart")
return fig
content.append(create_chart())
Use autoPdfImage when the plot and legend should be placed independently in the document:
@ap.autoPdfImage
def create_chart_with_legend(canvaswidth=5):
fig, ax = ap.plt.subplots(figsize=(canvaswidth, canvaswidth))
ax.plot([1, 2, 3, 4], [1, 4, 2, 3], label="series")
handles, labels = ax.get_legend_handles_labels()
legend_fig = ap.plt.figure(figsize=(canvaswidth, 0.4))
legend = legend_fig.legend(handles, labels, loc="center", frameon=False)
return fig, legend_fig, legend
plot_img, legend_img = create_chart_with_legend()
content.extend([legend_img, plot_img])
Table Layouts
For plain ReportLab tables, the standard ar.Table works well. For AutoBaseDoc-specific layout helpers, use StyledTable and finish with layoutStyledTable():
from autobasedoc.styledtable import StyledTable
styled = StyledTable(gridded=True)
styled.setTableData([
["Product", "Q1", "Q2"],
["Widget A", "100", "120"],
["Widget B", "80", "95"],
])
styled.addTableStyleCommand(("ALIGN", (0, 0), (-1, -1), "CENTER"))
table = styled.layoutStyledTable(colWidths=[4, 3, 3], rowHeights=[1.0, 0.8, 0.8])
content.append(table)
Examples and Documentation
- Example script:
tests/example.py - Larger document example:
tests/example_document.py - Sphinx docs source:
sphinx_doc/ - API docs: Read the generated Sphinx reference or inspect module docstrings
Testing
Install test dependencies and run the suite:
pip install -e ".[test]"
MPLBACKEND=Agg pytest -q
Coverage run:
MPLBACKEND=Agg pytest --cov=autobasedoc --cov-report=term-missing
Release Notes
Version 1.1.11 includes the current packaging cleanup, documentation fixes, and rowHeights forwarding support for styled table layout helpers.
License
This project is licensed under the BSD-3-Clause License. See LICENSE.md.
Links
- Homepage: https://github.com/NuCOS/autobasedoc
- Package: https://pypi.org/project/autobasedoc/
- Documentation: http://autobasedoc.readthedocs.io/
- Issues: https://github.com/NuCOS/autobasedoc/issues
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file autobasedoc-1.1.11.tar.gz.
File metadata
- Download URL: autobasedoc-1.1.11.tar.gz
- Upload date:
- Size: 3.4 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6ae2242c17986b075c246954107d8f64b96b5c48645698623a8a54ce99d20d12
|
|
| MD5 |
299c2b50c33665ebbb346ba90d5a0bbf
|
|
| BLAKE2b-256 |
411c8cad56ff4945f8c4653c0101a9eaacae18358ef4a9b406cef5210f138260
|
File details
Details for the file autobasedoc-1.1.11-py3-none-any.whl.
File metadata
- Download URL: autobasedoc-1.1.11-py3-none-any.whl
- Upload date:
- Size: 3.4 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8552a61469893d013384a57f2cd736f45e1bf84ff128b3af2c7b43823dec6e2c
|
|
| MD5 |
4f8069b6379683c7e53c7887b9d22770
|
|
| BLAKE2b-256 |
7f7227225bb73283fe99ac7e5c65be1e8e0ca62eb7975a11bd076cdcef679989
|