[Bug: Breaking] `AttributeError: 'PdfDocument' object has no attribute 'render'` in Streamlit app
Describe the Bug
The Streamlit app (streamlit_app.py) crashes with AttributeError: 'PdfDocument' object has no attribute 'render' when loading PDF files. This is a compatibility break caused by pypdfium2 4.0+ removing the render() method from PdfDocument. The project declares pypdfium2>=5.10.1,<6 as a dependency, but the code uses the deprecated API that no longer exists in that version range.
Input Document
Any PDF file uploaded through the Streamlit app. The bug occurs during PDF rendering regardless of the document content.
Output Trace / Stack Trace
Click to expandAttributeError: 'PdfDocument' object has no attribute 'render'
C:\...\site-packages\surya\scripts\streamlit_app.py:287 in get_page_image
284 @st.cache_data()
285 def get_page_image(pdf_file, page_num, dpi=settings.IMAGE_DPI):
286 │ doc = open_pdf(pdf_file)
❱ 287 │ renderer = doc.render(
288 │ │ pypdfium2.PdfBitmap.to_pil,
289 │ │ page_indices=[page_num - 1],
290 │ │ scale=dpi / 72,⚙️ Environment
Please fill in all relevant details:
- Surya version: 0.22.1
- Python version: 3.10+
- PyTorch version: 2.7.0+
- Transformers version: 5.12.1+
- Operating System (incl. container info if relevant): Windows (also affects Linux/macOS)
✅ Expected Behavior
PDFs should render correctly in the Streamlit app. The get_page_image() function should use the pypdfium2 5.x API to convert PDF pages to PIL images.
Command or Code Used
Paste the exact bash command or Python code you used to run Marker:
Click to expandsurya_guiThen upload any PDF file in the Streamlit UI.
Additional Context
The render() method was moved from PdfDocument to PdfPage in pypdfium2 4.0. The correct API for pypdfium2 5.x is:
# Old (broken in pypdfium2 >= 4.0)
renderer = doc.render(pypdfium2.PdfBitmap.to_pil, page_indices=[...], scale=dpi/72)
png = list(renderer)[0]
# New (works with pypdfium2 5.x)
page = doc.get_page(page_num - 1)
bitmap = page.render(scale=dpi / 72)
png = bitmap.to_pil()Affected code location: surya/scripts/streamlit_app.py:287 in the get_page_image() function.
Source: datalab-to/surya