Skip to content

Michael-OvO/ipynb2pdf

Repository files navigation

Jupyter to PDF Converter

A beautiful web application for converting Jupyter notebooks (.ipynb) to professionally formatted PDFs with full LaTeX support.

Features

  • Beautiful PDFs - Clean, professional formatting with elegant typography
  • Full LaTeX Support - Complete mathematical equation and notation rendering
  • Syntax Highlighting - Beautiful code highlighting with proper formatting
  • Customizable Settings - Control page layout, fonts, code themes, and content inclusion
  • Preset Templates - Pre-configured settings for academic papers, lab reports, and minimal outputs
  • Modern UI - Built with Next.js, React, and Tailwind CSS
  • Drag & Drop - Easy file upload with drag-and-drop support
  • Fast Conversion - Efficient server-side processing with rate limiting

Prerequisites

Before running this application, ensure you have the following installed:

Required Software

  1. Node.js (v18 or higher)

  2. Python 3 (v3.8 or higher)

  3. Pandoc (required for notebook conversion)

    macOS:

    brew install pandoc

    Ubuntu/Debian:

    sudo apt-get install pandoc

    Windows:

  4. LaTeX Distribution (required for PDF generation)

    Choose one based on your operating system:

    macOS:

    # Using Homebrew
    brew install --cask mactex-no-gui
    
    # Or download MacTeX from: https://www.tug.org/mactex/

    Ubuntu/Debian:

    sudo apt-get update
    sudo apt-get install texlive-xetex texlive-fonts-recommended texlive-plain-generic

    Windows:

Installation

  1. Clone the repository (or navigate to the project directory)

    cd ipynb2pdf
  2. Install Node.js dependencies

    npm install
  3. Install Python dependencies

    pip install -r requirements.txt

    Or using a virtual environment (recommended):

    python3 -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
    pip install -r requirements.txt
  4. Verify installations

    # Check if Pandoc is available
    pandoc --version
    
    # Check if pdflatex is available
    pdflatex --version

Usage

Development Mode

  1. Start the development server

    npm run dev
  2. Open your browser

  3. Upload a notebook

    • Drag and drop a .ipynb file onto the upload area
    • Or click to browse and select a file
    • The PDF will automatically download once conversion is complete

Production Mode

  1. Build the application

    npm run build
  2. Start the production server

    npm start
  3. Access the application

Project Structure

ipynb2pdf/
├── app/
│   ├── api/
│   │   └── convert/
│   │       └── route.ts          # API endpoint for conversion
│   ├── globals.css               # Global styles
│   ├── layout.tsx                # Root layout
│   └── page.tsx                  # Home page
├── components/
│   └── NotebookUploader.tsx      # Upload component
├── python/
│   ├── templates/
│   │   └── custom.tplx           # Custom LaTeX template
│   └── convert.py                # Python conversion script
├── temp/                         # Temporary files (auto-generated)
│   ├── uploads/                  # Uploaded notebooks
│   └── outputs/                  # Generated PDFs
├── requirements.txt              # Python dependencies
└── package.json                  # Node.js dependencies

How It Works

  1. Frontend: User uploads a .ipynb file through the React/Next.js interface
  2. API Route: Next.js API route receives the file and validates it
  3. Python Script: Calls the Python conversion script with nbconvert
  4. LaTeX Processing: nbconvert uses LaTeX to generate a beautifully formatted PDF
  5. Download: The PDF is returned to the user and automatically downloads

Troubleshooting

"Python or required packages not found"

  • Ensure Python 3 is installed and accessible via python3 command
  • Install Python dependencies: pip install -r requirements.txt

"PDF conversion failed" or "Pandoc wasn't found"

  • Verify Pandoc is installed: pandoc --version
  • Verify LaTeX is installed: pdflatex --version
  • Check that all Python packages are installed correctly
  • Ensure the notebook file is valid JSON
  • If using a virtual environment, make sure it's activated

"File size too large"

  • Maximum file size is 10MB
  • Consider splitting large notebooks into smaller files

Conversion timeout

  • Large or complex notebooks may take time to process
  • Simplify the notebook or reduce the number of cells

Configuration

Adjusting File Size Limit

Edit app/api/convert/route.ts:

const MAX_FILE_SIZE = 10 * 1024 * 1024; // Change to desired size in bytes

Customizing PDF Output

Edit the LaTeX template in python/templates/custom.tplx to customize:

  • Page margins and geometry
  • Font styles and sizes
  • Code highlighting colors
  • Header and footer styles

Customization Options

The application provides extensive customization through the settings panel:

Page Settings

  • Page size (A4, Letter, Legal, A3)
  • Orientation (Portrait, Landscape)
  • Margins (Narrow, Normal, Wide)

Typography

  • Body font (Serif, Sans-Serif, Computer Modern)
  • Code font (Fira Code, Source Code Pro, Courier)
  • Font size (10pt, 11pt, 12pt)

Code Appearance

  • Syntax highlighting themes (GitHub, Monokai, Solarized, Dracula, Nord)
  • Line numbers toggle
  • Input/Output prompt display

Document Structure

  • Table of contents generation
  • Page numbers and positioning
  • Section numbering

Content Filtering

  • Include/exclude code cells
  • Include/exclude cell outputs
  • Include/exclude markdown cells

Tech Stack

  • Frontend: Next.js 16, React 19, TypeScript
  • Styling: Tailwind CSS 4
  • File Upload: react-dropzone
  • Backend: Next.js API Routes with rate limiting
  • PDF Conversion: Python nbconvert with custom LaTeX processing
  • LaTeX: XeLaTeX with custom templates for professional formatting

Contributing

Contributions are welcome! Please feel free to submit issues or pull requests.

License

MIT License - feel free to use this project for any purpose.

Support

If you encounter any issues:

  1. Check the troubleshooting section above
  2. Ensure all prerequisites are properly installed
  3. Verify your notebook file is valid JSON
  4. Check the console/terminal for error messages

Built using Next.js and nbconvert