This patch fixes the core Office-to-PDF problem in the NextGen PDF backend.
The previous /api/word-to-pdf, /api/excel-to-pdf, and /api/pptx-to-pdf
implementations extracted text with Python libraries and manually drew that
text into a new PDF. That discards much of the original document layout.
Office documents are now rendered by LibreOffice:
DOCX/DOC → LibreOffice → PDF XLSX/XLS → LibreOffice → PDF PPTX/PPT → LibreOffice → PDF
This is a document renderer, not a text reconstruction pipeline. It therefore preserves the original document's layout much more faithfully, including images, fonts available on the server, paragraph formatting, tables, margins, headers/footers, page breaks and spacing.
backend/office_converter.py— reusable conversion enginebackend/Dockerfile— installs LibreOffice + fonts on Renderbackend/requirements.txt— backend dependenciesrender.yaml— switches the Render service to Dockerapply_conversion_fix.py— safely patches the existingbackend/main.py
Copy these files into the root of your current NextGen PDF project, then run:
python apply_conversion_fix.pyThe script creates:
backend/main.py.before-office-fix
before changing backend/main.py.
Then verify:
python -m py_compile backend/main.py backend/office_converter.pyFor local Word/Excel/PowerPoint → PDF testing, install LibreOffice on the
machine and make sure libreoffice or soffice is on PATH.
The included render.yaml uses the Dockerfile so Render installs LibreOffice.
This is required; simply adding a Python package is not enough.
After deployment, test with the original Word assignment and compare the PDF page-by-page with Word.
Do not use the old text-reconstruction implementations for Office → PDF again.
All three Office conversion endpoints should use convert_office_to_pdf().