CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-xhtml2pdf

PDF generator using HTML and CSS

Overview
Eval results
Files

command-line.mddocs/

Command Line Interface

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.

Capabilities

Main Command Interface

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.
    """

Usage and Help

def usage():
    """
    Print command line usage information.
    
    Displays comprehensive help text including all available options,
    parameter descriptions, and usage examples.
    """

Logging Control

def showLogging(*, debug=False):
    """
    Enable logging output with optional debug level.
    
    Args:
        debug (bool): Enable debug-level logging output
    """

Utility Functions

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
    """

Command Line Usage

Basic Conversion

# 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

Advanced Options

# 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

HTTP Configuration

# Disable SSL certificate checking
xhtml2pdf --http_nosslcheck https://example.com output.pdf

# With custom timeout
xhtml2pdf --http_timeout 30 https://example.com output.pdf

Available Options

  • --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 seconds

Install with Tessl CLI

npx tessl i tessl/pypi-xhtml2pdf

docs

command-line.md

context-management.md

css-processing.md

document-processing.md

file-handling.md

index.md

pdf-features.md

utilities.md

wsgi-integration.md

tile.json