Skip to content

pdf

pdf

Renderer implementation outputting PDF file.

WEasyPrintNotAvailableError

Bases: Exception

Error raised on Mac OS when attempting to generate PDF report.

Source code in cssfinder/reports/pdf.py
class WEasyPrintNotAvailableError(Exception):
    """Error raised on Mac OS when attempting to generate PDF report."""

    def __init__(self) -> None:
        super().__init__(WEASYPRINT_NOT_AVAILABLE)

weasyprint

Dummy class for Mac OS where weasyprint fails to import.

Source code in cssfinder/reports/pdf.py
class weasyprint:  # type: ignore[no-redef] # noqa: N801
    """Dummy class for Mac OS where weasyprint fails to import."""

    def HTML(*_a: Any, **__kw: Any) -> Any:  # noqa: N802
        """Raise exception on Mac OS."""
        raise WEasyPrintNotAvailableError

HTML

HTML(*_a: Any, **__kw: Any) -> Any

Raise exception on Mac OS.

Source code in cssfinder/reports/pdf.py
def HTML(*_a: Any, **__kw: Any) -> Any:  # noqa: N802
    """Raise exception on Mac OS."""
    raise WEasyPrintNotAvailableError

PDFRenderer

Bases: HTMLRenderer

Renderer implementation outputting PDF files content.

Source code in cssfinder/reports/pdf.py
class PDFRenderer(HTMLRenderer):
    """Renderer implementation outputting PDF files content."""

    def render(self) -> Report:
        """Generate report content."""
        report = super().render()
        return Report(
            weasyprint.HTML(string=report.content.decode("utf-8")).write_pdf(),
            ReportType.PDF,
            self.ctx.task.task_output_directory / "report.pdf",
        )

render

render() -> Report

Generate report content.

Source code in cssfinder/reports/pdf.py
def render(self) -> Report:
    """Generate report content."""
    report = super().render()
    return Report(
        weasyprint.HTML(string=report.content.decode("utf-8")).write_pdf(),
        ReportType.PDF,
        self.ctx.task.task_output_directory / "report.pdf",
    )