A Streamlit web application that converts Jupyter notebooks (.ipynb), Python scripts (.py), and Markdown files (.md) into high-quality PDF documents.
🚀 Try it now: Launch nb2pdf
- Multiple Input Formats: Support for Jupyter Notebooks, Python scripts, and Markdown files
- GitHub Gist Support: Fetch files directly from GitHub Gist URLs
- Cover Page: Add a customizable cover page with title, author, and date
- Table of Contents: Automatically generate a table of contents from headings
- Theme Selection: Choose between light and dark themes
- Page Size Options: Support for A4, Letter, and Legal page sizes
- Multi-Backend PDF Generation: Uses WeasyPrint with xhtml2pdf as fallback
- Live Preview: Preview the HTML output before generating PDF
- Always-Available HTML Download: Download HTML even if PDF backends are unavailable
Click Try nb2pdf now above, upload your file, and download your PDF.
Launch nb2pdf
That’s it — no setup, no installs.
-
Clone the repository:
git clone https://github.com/Sanjidh090/nb2pdf.git cd nb2pdf -
Install dependencies:
pip install -r requirements.txt
-
Install system dependencies for WeasyPrint (optional but recommended):
On Ubuntu/Debian:
sudo apt-get install libpango-1.0-0 libpangoft2-1.0-0 libcairo2 libglib2.0-0
On macOS:
brew install pango cairo
On Windows:
- WeasyPrint installation may require GTK. See WeasyPrint documentation.
-
Run the application:
streamlit run streamlit_app.py
-
Open your browser at
http://localhost:8501
- Fork this repository to your GitHub account
- Go to Streamlit Cloud
- Click "New app"
- Select your forked repository
- Set the main file path to
streamlit_app.py - Click "Deploy"
Note: For Streamlit Cloud deployment, you may need to create a packages.txt file with system dependencies:
libpango-1.0-0
libpangoft2-1.0-0
libglib2.0-0
libcairo2
- Use the "Upload File" tab
- Drag and drop or browse to select your file
- Configure options in the sidebar:
- Choose theme (light/dark)
- Set page size
- Add cover page (optional)
- Include table of contents (optional)
- Click "Generate PDF" to create the PDF
- Download the PDF or HTML file
- Use the "From URL" tab
- Enter a GitHub Gist URL or direct file URL:
https://gist.github.com/username/gist_idhttps://raw.githubusercontent.com/user/repo/branch/file.ipynb
- Click "Fetch File"
- Follow the same conversion steps as above
| Option | Description |
|---|---|
| Theme | Light or Dark mode for the output |
| Page Size | A4, Letter, or Legal |
| Cover Page | Add a title page with title, author, and date |
| Table of Contents | Auto-generate TOC from headings |
| Pygments Highlighting | Use Pygments for Python syntax highlighting |
nb2pdf supports multiple PDF generation backends with automatic fallback:
- WeasyPrint (recommended): High-quality PDF output with CSS support
- xhtml2pdf: Pure Python fallback, no system dependencies required
WeasyPrint (recommended):
pip install weasyprintxhtml2pdf (fallback):
pip install xhtml2pdfIf no PDF backends are available, the app will still allow you to download the HTML file.
nb2pdf/
├── streamlit_app.py # Main Streamlit application
├── nb2pdf/
│ ├── __init__.py # Package initialization
│ ├── convert.py # Conversion utilities
│ └── ui_helpers.py # UI helper functions
├── assets/
│ └── logo.svg # Application logo
├── .streamlit/
│ └── config.toml # Streamlit configuration
├── requirements.txt # Python dependencies
├── packages.txt # System dependencies (Streamlit Cloud)
└── README.md # This file
- LaTeX Rendering: Complex LaTeX equations may not render perfectly in PDF
- Large Files: Very large notebooks may take longer to process
- System Dependencies: WeasyPrint requires system libraries (cairo, pango)
- External Images: Images referenced by URL may not appear in PDF if inaccessible
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is open source and available under the MIT License.
- Streamlit - The amazing framework for building data apps
- nbconvert - For notebook conversion
- WeasyPrint - For PDF generation
- Pygments - For syntax highlighting
Made with ❤️ by the nb2pdf contributors