How to merge pdf files and offer download

Hi,

Thank you the support for multiple file upload.

How do you combine those uploaded (pdf) files into one and offer a download button?

TIA!

I tried one solution using pypdf2: https://share.streamlit.io/gerardrbentley/streamlit-random/main/pdf_merge_and_split.py

If you need more advanced features check out reportlab

Happy Streamliting, Cheers :balloon:

1 Like

Thank you, exactly what I was looking for.

Where’s the code at?

Thanks!

Got to merge the uploaded documents by:

def merge_pdf (pdfFiles):
    merger = PdfFileMerger()
    
    for file in pdfFiles: 
        merger.append(file, 'rb')
        
    _byteIo = BytesIO()
    merger.write(_byteIo)    
    _byteIo.seek(0)
    
    return _byteIo
st.download_button("Download PDF", data=merged, file_name="merged.pdf",mime='application/octet-stream')

Unless there are other ways?

Thank you!

https://github.com/gerardrbentley/streamlit-random/blob/main/pdf_merge_and_split.py

For any streamlit cloud app you should be able to use the hamburger menu on the top right then “View app source”

Cheers

2 Likes

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.