PDF generator using HTML and CSS
Complete command-line interface for batch processing and integration with shell scripts and automated workflows. Provides direct access to xhtml2pdf conversion capabilities from the command line.
Primary command-line entry points for HTML-to-PDF conversion.
def command():
"""
Main command line entry point mapped to CLI commands.
Available as both 'pisa' and 'xhtml2pdf' commands after installation.
Processes sys.argv and performs conversion based on command-line arguments.
"""
def execute():
"""
Execute command line conversion with argument parsing.
Handles all command-line options, file processing, and error reporting.
Called internally by command() after argument validation.
"""def usage():
"""
Print command line usage information.
Displays comprehensive help text including all available options,
parameter descriptions, and usage examples.
"""def showLogging(*, debug=False):
"""
Enable logging output with optional debug level.
Args:
debug (bool): Enable debug-level logging output
"""Additional utility functions for file handling and PDF viewing.
def startViewer(filename):
"""
Open PDF file with system default viewer.
Args:
filename (str): Path to PDF file to open
Note:
Works on Windows (startfile) and macOS (open command).
On other systems, may require manual PDF viewer configuration.
"""
def makeDataURI(data=None, mimetype=None, filename=None):
"""
Create data URI from binary data.
Args:
data (bytes): Binary data to encode
mimetype (str): MIME type for data (optional if filename provided)
filename (str): Filename for MIME type detection (optional if mimetype provided)
Returns:
str: data URI string (data:mimetype;base64,encodeddata)
Raises:
RuntimeError: If neither mimetype nor filename is provided
"""
def makeDataURIFromFile(filename):
"""
Create data URI from file contents.
Args:
filename (str): Path to file to encode
Returns:
str: data URI string containing file content
"""# Convert HTML file to PDF
xhtml2pdf input.html output.pdf
# Convert from stdin to stdout
echo "<html><body><h1>Hello</h1></body></html>" | xhtml2pdf - -
# Convert URL to PDF
xhtml2pdf "https://example.com" output.pdf# With custom CSS and base path
xhtml2pdf --css custom.css --base /path/to/resources input.html output.pdf
# Enable debug output
xhtml2pdf --debug input.html output.pdf
# Force XML parsing mode
xhtml2pdf --xml input.xhtml output.pdf
# Specify character encoding
xhtml2pdf --encoding utf-8 input.html output.pdf# Disable SSL certificate checking
xhtml2pdf --http_nosslcheck https://example.com output.pdf
# With custom timeout
xhtml2pdf --http_timeout 30 https://example.com output.pdf--base, -b: Specify base path for relative resources--css, -c: Path to custom default CSS file--css-dump: Output default CSS definitions to stdout--debug, -d: Enable debug output--encoding: Character encoding for input--help, -h: Show help message--quiet, -q: Suppress all output messages--start-viewer, -s: Open PDF in default viewer (Windows/macOS)--version: Show version information--warn, -w: Show warning messages--xml, --xhtml, -x: Force XML/XHTML parsing mode--html: Force HTML parsing mode (default)--http_nosslcheck: Disable SSL certificate verification--http_key_file: SSL client key file--http_cert_file: SSL client certificate file--http_source_address: Source address for HTTP connections--http_timeout: HTTP connection timeout in secondsInstall with Tessl CLI
npx tessl i tessl/pypi-xhtml2pdf