[Python] My fpdf2 PDF is blank when I try to download it from the browser after passing it to...

Discussão em 'Python' iniciado por Stack, Julho 8, 2025.

  1. Stack

    Stack Membro Participativo

    I cannot for the life of me figure out why this PDF won't display. I'm using fpdf2 to create a pdf that looks good when saving it from the python script. However, something must be going wrong when passing the data to the front end.

    Here is the pdf representation that I'm ending up with:

    "%PDF-1.3
    1 0 obj
    <<
    /Count 1
    /Kids [3 0 R]
    /MediaBox [0 0 595.28 841.89]
    /Type /Pages
    >>
    endobj
    2 0 obj
    <<
    /OpenAction [3 0 R /FitH null]
    /PageLayout /OneColumn
    /Pages 1 0 R
    /Type /Catalog
    >>
    endobj
    3 0 obj
    <<
    /Contents 4 0 R
    /Parent 1 0 R
    /Resources 6 0 R
    /Type /Page
    >>
    endobj
    4 0 obj
    <<
    /Filter /FlateDecode
    /Length 72
    >>
    stream
    x�3R��2�35W(�r
    Q�w3T04�30PISp
    �Z(�[����(hx����+���(j*�d��V
    endstream
    endobj
    5 0 obj
    <<
    /BaseFont /Helvetica-Bold
    /Encoding /WinAnsiEncoding
    /Subtype /Type1
    /Type /Font
    >>
    endobj
    6 0 obj
    <<
    /Font <</F1 5 0 R>>
    /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
    >>
    endobj
    7 0 obj
    <<
    /CreationDate (D:20250708064952Z)
    >>
    endobj
    xref
    0 8
    0000000000 65535 f
    0000000009 00000 n
    0000000096 00000 n
    0000000199 00000 n
    0000000279 00000 n
    0000000422 00000 n
    0000000524 00000 n
    0000000611 00000 n
    trailer
    <<
    /Size 8
    /Root 2 0 R
    /Info 7 0 R
    /ID [<119889D12E2230568C66D2CFBCFCE0FB><119889D12E2230568C66D2CFBCFCE0FB>]
    >>
    startxref
    666
    %%EOF
    "


    I can verify that this is the data getting downloaded when I change the type to text/plain. When the type is set to application/pdf, I end up with a blank pdf. I can also tell that part of it is working properly because adding more pages to the pdf results in a download with the proper amount of pages.

    Running out of ideas, so I'd really appreciate if anyone had any insight. Thanks in advance!

    I've tried converting to different types, using a Blob() vs a File(), changing headers to include "Content-Disposition": "attachment; filename=myfilename.pdf" and more.

    Some of these ideas came from previous posts, but none of them quite did the trick.

    Continue reading...

Compartilhe esta Página