Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions apps/backend/app/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
from __future__ import annotations

import asyncio
import logging
import os
import sys
from pathlib import Path
from typing import Awaitable, NoReturn, Optional

logger = logging.getLogger(__name__)

from playwright.async_api import (
Browser,
Error as PlaywrightError,
Expand Down Expand Up @@ -133,9 +136,12 @@ async def _render_page_to_pdf(
pdf_format: str,
pdf_margins: dict,
) -> bytes:
await page.goto(url, wait_until="networkidle")
await page.wait_for_selector(selector)
await page.evaluate("document.fonts.ready")
await page.goto(url, wait_until="domcontentloaded", timeout=15000)
await page.wait_for_selector(selector, timeout=10000)
try:
await page.evaluate("document.fonts.ready", timeout=10000)
except Exception as e:
logger.warning(f"Font loading failed for PDF generation (non-critical): {e}")
return await page.pdf(
format=pdf_format,
print_background=True,
Expand Down