Changed app.py:
•
process_pft_pdf() now uses the uploaded file stream directly instead of copying the PDF into bytes.
•
Output now uses SpooledTemporaryFile, so larger generated PDFs spill to disk instead of staying fully in RAM.
•
Explicitly closes PdfReader objects after writing.
•
Removed @app.teardown_request gc.collect(), which was running too early and could break send_file.
•
Added response.call_on_close() cleanup so the generated PDF stream is closed only after Flask/Werkzeug finishes sending it.
Changed Dockerfile:
•
Added Gunicorn --max-requests 50 --max-requests-jitter 10 as a production guardrail against PDF-library or allocator memory growth.