Export to pdf

Summary

how to export streamlit page as it is to PDF

Steps to reproduce

Expected behavior:

export the streamlit page as it is with all the styles and elements
Actual behavior:

N /A

Additional information

If needed, add any other context about the problem here.

Print → Save as PDF

hey i tried it with print as PDF but it cuts the page and i cant use the exported PDF this way…

is there way to tell to PDF when to “break” page?

Hi @nikmere you can try to use css “hack”. This works quite well for page breakes in chrome (I wanted to breake pages after horizontal rule)

st.markdown(
    """
    <style type="text/css" media="print">
      hr
      {
        page-break-after: always;
        page-break-inside: avoid;
      }
    </style>
""",
    unsafe_allow_html=True,
)

it didnt solve the problem…it still breaks the pdf

Hi @nikmere could you share your repo? Without any code it is hard to guess what is happening and braeking :slight_smile:

For above solution you obiously need to add horizontal lines in your code for example using st.markdown("---")

Thank you @TomJohn, this “hack” worked for me.

I had some hr elements in my page already since I used st.divider() in some places, so I ended up creating a new div class with the same logic you shared. Sharing here in case anyone else want’s an “invisible” implementation.

st.markdown(
    """
    <style type="text/css" media="print">
    div.page-break
    {
        page-break-after: always;
        page-break-inside: avoid;
    }
    </style>
    <div class="page-break">
        <!-- Content goes here -->
    </div>
""",
    unsafe_allow_html=True,
)
1 Like