Files
TimeTracker/docs/PDF_GENERATION_TROUBLESHOOTING.md
Dries Peeters d230a41e8a feat: enhance web interface layout and fix logo import circular dependency
- Improve web interface layout for better user-friendliness and mobile responsiveness
  * Update CSS variables for consistent spacing and component sizing
  * Enhance card layouts with improved padding, borders, and shadows
  * Optimize button and form element dimensions for better touch targets
  * Add hover effects and animations for improved user interaction
  * Implement responsive grid system with mobile-first approach

- Refactor mobile JavaScript to prevent duplicate initialization
  * Consolidate mobile enhancements into dedicated utility classes
  * Add initialization guards to prevent double loading
  * Implement MobileUtils and MobileNavigation classes
  * Remove duplicate event listeners and mobile enhancements

- Fix circular import issue in logo handling
  * Replace problematic 'from app import app' with Flask's current_app
  * Add error handling for cases where current_app is unavailable
  * Improve logo path resolution with fallback mechanisms
  * Fix settings model to use proper Flask context

- Clean up template code and remove duplication
  * Remove duplicate mobile enhancements from base template
  * Clean up dashboard template JavaScript
  * Centralize all mobile functionality in mobile.js
  * Add proper error handling and debugging

- Update CSS variables and spacing system
  * Introduce --section-spacing and --card-spacing variables
  * Add mobile-specific spacing variables
  * Improve border-radius and shadow consistency
  * Enhance typography and visual hierarchy

This commit resolves the double loading issue and logo import errors while
significantly improving the overall user experience and mobile responsiveness
of the web interface.
2025-08-30 10:09:06 +02:00

5.7 KiB

PDF Generation Troubleshooting Guide

Common Error: gobject-2.0-0 Library Missing

Error Message

Error generating PDF: cannot load library 'gobject-2.0-0': gobject-2.0-0: cannot open shared object file: No such file or directory. Additionally, ctypes.util.find_library() did not manage to locate a library called 'gobject-2.0-0'

What This Means

WeasyPrint requires several system libraries for rendering HTML/CSS to PDF. The gobject-2.0-0 library is part of the GLib/GObject system that WeasyPrint uses for rendering.

Solutions

Update your Dockerfile to include the required system libraries:

# Install system dependencies
RUN apt-get update && apt-get install -y \
    curl \
    tzdata \
    # WeasyPrint dependencies
    libgdk-pixbuf2.0-0 \
    libpango-1.0-0 \
    libcairo2 \
    libpangocairo-1.0-0 \
    libffi-dev \
    shared-mime-info \
    # Additional fonts and rendering support
    fonts-liberation \
    fonts-dejavu-core \
    && rm -rf /var/lib/apt/lists/*

Then rebuild your Docker container:

docker-compose down
docker-compose build --no-cache
docker-compose up

Option 2: Use ReportLab Fallback (Already Configured)

The system automatically falls back to ReportLab when WeasyPrint fails. ReportLab generates basic but functional PDFs without external dependencies.

Pros:

  • No system dependencies required
  • Always works
  • Faster generation

Cons:

  • Less styling control
  • No CSS support
  • Basic layout only

Option 3: Alternative PDF Libraries

Consider these alternatives if both WeasyPrint and ReportLab fail:

# Install alternative PDF libraries
pip install pdfkit  # Requires wkhtmltopdf
pip install xhtml2pdf  # Pure Python, limited features

Testing PDF Generation

Run the test script to diagnose issues:

# Inside the container
python /app/docker/test-pdf-generation.py

# Or from host
docker exec -it your-container-name python /app/docker/test-pdf-generation.py

Expected Output

Successful WeasyPrint Test:

=== PDF Generation Test ===
Checking system libraries:
✓ gobject-2.0-0: /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
✓ pango-1.0-0: /usr/lib/x86_64-linux-gnu/libpango-1.0.so.0
✓ cairo: /usr/lib/x86_64-linux-gnu/libcairo.so.2
✓ gdk_pixbuf-2.0: /usr/lib/x86_64-linux-gnu/libgdk_pixbuf-2.0.so.0

=== Python Libraries ===
✓ WeasyPrint is available

=== Summary ===
✓ WeasyPrint is working - High-quality PDFs available

WeasyPrint Failed, ReportLab Available:

=== Summary ===
⚠ WeasyPrint failed but ReportLab is available - Basic PDFs available

=== Recommendations ===
1. Install system dependencies: libgdk-pixbuf2.0-0, libpango-1.0-0, libcairo2
2. Rebuild Docker container with updated Dockerfile
3. Or use ReportLab fallback (already configured)

System Library Details

Required Libraries:

  • libgdk-pixbuf2.0-0: Image loading and manipulation
  • libpango-1.0-0: Text layout and rendering
  • libcairo2: 2D graphics rendering
  • libpangocairo-1.0-0: Pango-Cairo integration
  • libffi-dev: Foreign function interface
  • shared-mime-info: MIME type detection

Font Support:

  • fonts-liberation: Open-source font alternatives
  • fonts-dejavu-core: Additional font support

Docker Container Issues

Common Problems:

  1. Base Image: python:3.11-slim is minimal and may lack libraries
  2. Architecture: ARM vs x86_64 can have different library names
  3. Package Names: Package names may vary between distributions

Solutions:

  1. Use Debian-based image: python:3.11-slim is Debian-based
  2. Install build tools: Add build-essential if compiling from source
  3. Check package names: Verify package names with apt-cache search

Performance Considerations

WeasyPrint:

  • Memory: Higher memory usage during generation
  • Speed: Slower for complex layouts
  • Quality: Professional-grade output

ReportLab:

  • Memory: Lower memory usage
  • Speed: Faster generation
  • Quality: Basic but functional

Troubleshooting Steps

  1. Check Current Status:

    docker exec -it your-container-name python /app/docker/test-pdf-generation.py
    
  2. Verify System Libraries:

    docker exec -it your-container-name ldconfig -p | grep -E "(gobject|pango|cairo)"
    
  3. Check Package Installation:

    docker exec -it your-container-name dpkg -l | grep -E "(libgdk|libpango|libcairo)"
    
  4. Rebuild Container:

    docker-compose down
    docker-compose build --no-cache
    docker-compose up
    
  5. Test PDF Generation:

    • Try generating a PDF from an invoice
    • Check for fallback to ReportLab
    • Verify PDF output quality

Fallback Configuration

The system automatically detects WeasyPrint failures and switches to ReportLab:

try:
    from app.utils.pdf_generator import InvoicePDFGenerator
    # Use WeasyPrint
except Exception as e:
    try:
        from app.utils.pdf_generator_fallback import InvoicePDFGeneratorFallback
        # Use ReportLab fallback
    except Exception as fallback_error:
        # Both failed

Support and Maintenance

Regular Tasks:

  • Monitor PDF generation logs
  • Test both generators periodically
  • Update system dependencies as needed

When to Rebuild:

  • After system updates
  • When adding new PDF features
  • If performance degrades

Conclusion

The PDF generation system is designed with fallbacks to ensure reliability:

  1. Primary: WeasyPrint for high-quality PDFs
  2. Fallback: ReportLab for basic PDFs
  3. Automatic: Seamless switching between generators

Most users will get working PDFs immediately, with the option to upgrade to high-quality output by fixing system dependencies.