Exporting data science work often presents frustrating formatting obstacles, especially when you need to convert an ipynb to pdf preserve images, charts, and mathematical notations cleanly. Standard export routines frequently strip inline Matplotlib plots, corrupt Plotly diagrams, or trigger cryptic LaTeX compilation errors. Whether you are submitting academic coursework, presenting machine learning findings to stakeholders, or archiving research documentation, this guide details every reliable method to convert your Jupyter Notebooks to publication-quality PDFs with every graphic intact.
ipynb to pdf Preserve Images: Why Images Break When Converting IPYNB to PDF
Images break during Jupyter Notebook export because default PDF generation pipelines rely on LaTeX, which struggles to parse base64-encoded strings, dynamic JavaScript outputs, and modern HTML canvas elements. When your conversion engine encounters an unhandled media format or misconfigured relative directory, it either skips the visual asset entirely or crashes the build process.
The Relative Path vs. Base64 Dilemma
Jupyter Notebooks store inline graphical outputs—such as those produced by Matplotlib or Seaborn—as base64-encoded binary text inside the .ipynb JSON schema under the outputs cell key. When standard converters translate notebook cells into standard TeX files, they must decode these streams into temporary raster files on your disk. If permissions fail, or if you linked external markdown figures using relative paths like ../images/chart.png, traditional tools lose track of the file references. In contrast, modern browser rendering engines interpret base64 strings and local DOM resources natively without intermediate disk writing. (Source: Project Jupyter Documentation)
LaTeX and nbconvert Parsing Failures
Running the traditional jupyter nbconvert --to pdf command invokes a LaTeX distribution installed on your operating system (such as TeX Live or MiKTeX). If your notebook contains unicode characters, wide DataFrames, raw HTML tables, or dynamic SVG graphics, the underlying TeX engine—typically XeLaTeX or pdfLaTeX—fails to compile. Common errors include xelatex not found, LaTeX Error: File not found, or Dimension too large. These errors halt export completely, preventing you from generating the document unless you spend hours debugging TeX packages.
Interactive JavaScript Libraries
Modern data visualization libraries like Plotly, Bokeh, Altair, and Folium build visualizations using client-side JavaScript. Because TeX engines do not possess a JavaScript runtime or a Document Object Model (DOM), they cannot execute the underlying code that paints these visual elements. To preserve these graphics, you must evaluate them within an actual headless browser engine or rasterize them into static images before triggering the export process.
Key takeaway: Visuals break because classic LaTeX export lacks a browser engine; switching to DOM-aware conversion tools eliminates missing images instantly.
Method 1: Zero-Install Browser Print Technique (Best for Preserving All Visuals)
The fastest way to convert an IPYNB to PDF while keeping every image intact is to render the notebook in your browser and use the operating system print engine. Browsers possess native graphics engines that render base64 plots, CSS styles, SVGs, and WebGL canvases exactly as displayed on screen.
- Open your notebook inside JupyterLab, classic Jupyter Notebook, or VS Code.
- Ensure you run all cells so that your charts, maps, and figures display in the active workspace.
- Navigate to the top menu and select File > Save and Export Notebook As… > HTML (or File > Download as > HTML (.html)).
- Open the exported HTML file in Google Chrome, Mozilla Firefox, or Microsoft Edge.
- Press
Ctrl + P(Windows/Linux) orCmd + P(macOS) to launch your browser print dialogue. - Set the destination to Save as PDF.
- Under More settings, check the box labeled Background graphics and select None for margins to prevent unwanted border clipping.
- Click Save and select your destination folder.
CSS Print Media Adjustments
Occasionally, browser print dialogues split code cells or charts awkwardly across page breaks. You can insert a markdown cell at the top of your notebook with a custom CSS snippet to control page breaks and ensure high-resolution rasterization:
<style>
@media print {
div.jp-Cell-outputWrapper, div.output_wrapper { page-break-inside: avoid; }
div.jp-CodeCell, div.cell { page-break-inside: avoid; }
img { max-width: 100% !important; height: auto !important; }
}
</style>
Adding this small rule prevents the browser from slicing a visual visualization horizontally across two separate PDF pages, guaranteeing a polished submission.
Key takeaway: Exporting to HTML and using your browser’s native print engine bypasses TeX entirely and guarantees 100% visual fidelity for all chart types.
Method 2: Command-Line WebPDF via Headless Chromium
If you prefer automated terminal workflows or need continuous integration builds, use nbconvert’s webpdf exporter instead of standard LaTeX PDF generation. The webpdf exporter spins up a headless Chromium instance via Playwright, renders your notebook’s complete DOM structure, and saves it directly as a vector-ready PDF.
Installing and Configuring WebPDF
To use this capability, install the required packages using your Python package manager:
pip install nbconvert[webpdf]playwright install chromium
Once installed, execute the following command in your terminal:
jupyter nbconvert --to webpdf --allow-chromium-download notebook.ipynb
This approach gives you three distinct advantages over traditional LaTeX exports:
- Zero LaTeX Dependency: You do not need to install gigabytes of TeX distributions on your system.
- Complete Image Preservation: WebPDF processes base64 strings, SVGs, external web links, and CSS styles without dropping assets.
- Accurate Syntax Highlighting: The Pygments styling and syntax themes from your notebook transfer directly to the printed pages.
Automating Batch Conversions
If you manage multiple notebooks across a research repository or student course folder, convert them in bulk using a simple terminal loop:
for file in *.ipynb; do jupyter nbconvert --to webpdf "$file"; done
This command converts every notebook in your working directory to a clean PDF while ensuring every generated diagram stays anchored to its respective code output cell.
Key takeaway: The webpdf exporter provides the ideal balance between scriptable automation and pixel-perfect visual fidelity.
Method 3: Secure, Client-Side Online Converters (No Uploads Required)
When working with proprietary data, non-disclosure agreements, or regulated healthcare records, traditional cloud converter websites present critical privacy risks. Standard online tools upload your notebook file to their backend servers, exposing internal code, API credentials, and sensitive analytical results.
How In-Browser Conversion Protects Your Privacy
Modern browser-based conversion tools run client-side using JavaScript or WebAssembly. When you drop an .ipynb file into a client-side converter, your machine parses the JSON structure locally, builds an in-memory document tree, and uses a client-side renderer to construct the PDF. Your proprietary code and embedded visual outputs never traverse a network or touch an external server.
Evaluating Online Conversion Options
When selecting an online tool to convert an ipynb to pdf preserve images, verify the tool satisfies these criteria:
- Client-Side Processing: Check network activity in your browser’s Developer Tools (F12) to ensure the site makes zero outbound POST requests carrying your notebook data.
- Full Cell Output Support: Ensure the utility parses text outputs, ANSI terminal colors, tabular DataFrames, and inline charts without truncating long lines.
- No Account Gatekeeping: A fast workflow requires immediate conversion without signups, email verifications, or artificial file size limits.
Key takeaway: Prioritize client-side web tools that process notebooks entirely within your local browser sandbox to keep proprietary research secure.
Comparison of Popular IPYNB to PDF Conversion Methods
Different conversion methods offer distinct trade-offs between setup complexity, styling fidelity, and rendering consistency. The table below details how the primary approaches compare across core operational metrics.
| Conversion Method | Preserves Base64 & SVGs | Supports Interactive Plots (Plotly) | Requires LaTeX Setup | Privacy / Local Execution | Setup Complexity |
|---|---|---|---|---|---|
| Browser Print (via HTML) | Yes (100%) | Yes (Native DOM) | No | 100% Local | Very Low (No setup) |
| nbconvert WebPDF | Yes (100%) | Yes (Headless DOM) | No | 100% Local | Moderate (Requires Playwright) |
| nbconvert standard PDF | Partial (Rasters only) | No (Fails silently) | Yes (Full TeX suite) | 100% Local | High (Frequent errors) |
| Client-Side Web Converters | Yes (100%) | Yes (DOM-based) | No | 100% Local (In-Browser) | Zero (Instant) |
| VS Code Built-in Export | Yes (High) | Partial (Depends on engine) | Optional | 100% Local | Low (Extension-based) |
Key takeaway: DOM-based approaches (Browser Print, WebPDF, and local-browser converters) outperform LaTeX pipelines on every metric involving embedded imagery.
Environment-Specific Export Workflows: VS Code, Colab, and Kaggle
Different development environments encapsulate notebook kernels and image rendering pipelines differently. Here is how to maintain image integrity across the three most common notebook environments.
1. Visual Studio Code (VS Code)
VS Code offers excellent native support for Jupyter Notebooks. To export your notebook to a PDF with intact graphics:
- Open your notebook in VS Code and ensure all outputs are visible.
- Click the Export icon (ellipsis icon or the dedicated export button on the top notebook toolbar).
- Select HTML.
- Open the resulting HTML in your default browser and run the print dialogue to save as PDF.
- Alternative: If you install the recommended Jupyter Slide Show and Print extensions, select Export as PDF directly. Ensure you have Chromium installed if VS Code prompts for headless dependencies.
2. Google Colaboratory (Colab)
Google Colab instances run inside Google Cloud containers where users do not have administrative access to desktop print drivers. To export clean PDFs from Colab with images intact:
- Approach A (Recommended): Go to File > Download > Download .ipynb. Open the notebook locally or drop it into a client-side converter to produce the PDF.
- Approach B (In-Notebook Command): Run the following script in a notebook cell to convert directly within your Colab instance using headless tools:
!apt-get update > /dev/null
!apt-get install -y chromium-chromedriver > /dev/null
!pip install nbconvert[webpdf] > /dev/null
!playwright install chromium
!jupyter nbconvert –to webpdf /content/your_notebook.ipynb
3. Kaggle Notebooks
Similar to Colab, Kaggle’s cloud environment limits direct local printing. The most reliable procedure is to click Save Version to ensure all cells run and cache their outputs. Once the notebook finishes committing, go to the notebook viewer, right-click the rendered report, and choose your browser’s Print command, saving the output directly as a vector PDF.
. For more on this, see Google AI.
Key takeaway: In cloud environments like Colab and Kaggle, download the notebook or HTML file and render locally to avoid container-level TeX dependency headaches.
Configuring Notebook Visuals for Crisp Vector PDF Output
Preventing missing images is only half the battle; ensuring your visual elements look sharp, readable, and appropriately sized in your final PDF is equally critical. Low-resolution visual outputs look blurry or pixelated when scaled on physical paper or desktop monitors.
Matplotlib and Seaborn DPI Settings
By default, Matplotlib renders figures at 72 or 100 dots per inch (DPI), which looks acceptable on web pages but pixelated in high-resolution documents. To force Matplotlib to generate print-ready assets, configure your plotting parameters at the beginning of your notebook:
. For more on this, see convert ipynb to pdf online.
import matplotlib.pyplot as plt
%matplotlib inline
%config InlineBackend.figure_format = ‘retina’# Global plot styling parameters
plt.rcParams[‘figure.dpi’] = 300
plt.rcParams[‘savefig.dpi’] = 300
plt.rcParams[‘savefig.bbox’] = ‘tight’
Using 'retina' or high DPI values doubles pixel density, ensuring that trend lines, scatter points, axis ticks, and annotations stay crisp when embedded inside your PDF.
Rasterizing Plotly and Altair Visuals
If you rely on interactive visualization packages but must distribute static documents, configure your code to include static raster backups alongside the interactive widgets. In Plotly, specify the default renderer as a static image format:
import plotly.io as pio
pio.renderers.default = “notebook_connected+png”
This instruction directs Plotly to store both the interactive JavaScript element and a high-resolution PNG snapshot inside the cell metadata, ensuring that static conversion tools capture your visualizations without issue.
| Plotting Library | Recommended Export Setting | Target DPI | Output Format Advantage |
|---|---|---|---|
| Matplotlib | InlineBackend.figure_format = 'retina' |
300 | Sharp lines, readable small fonts |
| Seaborn | sns.set_context("paper", font_scale=1.2) |
300 | Optimized label proportions for print |
| Plotly | pio.renderers.default = "png" |
300 | Bypasses JavaScript DOM requirements |
| Altair / Vega | alt.renderers.enable('mimetype') |
Vector / 300 | Maintains crisp SVG scaling |
Key takeaway: Set figure DPI to 300 and use high-density backends before generating outputs to prevent pixelated charts in your final PDF.
Common Pitfalls and Troubleshooting
Even seasoned data analysts encounter unexpected quirks when generating PDF reports from notebooks. Here is how to resolve the most common export failures quickly.
1. Truncated Code Cells and Horizontal Overflow
Unlike regular text, long lines of Python code, SQL queries, or wide DataFrames do not wrap automatically in standard PDF compilation. If your code extends past the right margin:
- Format code using an automated PEP 8 formatter like Black to constrain line lengths to 79 or 88 characters.
- Limit visible DataFrame column outputs using
pd.set_option('display.max_columns', 10). - If using browser print, set paper orientation to Landscape to accommodate wide tables.
2. Dark Mode Inversion Artifacts
If you use dark mode themes in JupyterLab or VS Code, your browser print engine might attempt to print inverted background colors, draining black ink and rendering dark gray plots unreadable. Always toggle your notebook interface to a clean, light theme (such as JupyterLab Light or Default Light) before triggering an export or printing step.
3. Missing Mathematical Formulas and LaTeX Equations
If MathJax formulas like $$E = mc^2$$ fail to render in your PDF export, you likely generated the PDF before the client browser completed rendering the MathJax script. When printing manually via HTML, wait two to three seconds after loading the page until all LaTeX equation blocks snap into formatted typesetting before pressing Ctrl + P.
Key takeaway: Format wide lines, switch to a light theme, and let MathJax finish rendering before initiating your PDF print command.
Frequently Asked Questions
How do I convert an IPYNB to PDF without installing LaTeX?
You can convert an IPYNB to PDF without LaTeX by exporting your notebook to HTML and using your browser’s built-in Print to PDF feature. Alternatively, install nbconvert[webpdf] and use the --to webpdf flag, which uses a headless Chromium browser rather than a TeX distribution.
Why does jupyter nbconvert throw a ‘xelatex not found’ error?
This error occurs because the standard --to pdf parameter expects a full LaTeX distribution installed on your system path. If you do not have TeX Live, MacTeX, or MiKTeX installed, the conversion aborts. Resolve this by switching to the --to webpdf command or converting through an HTML intermediary. (Source: Project Jupyter Documentation)
Are online IPYNB to PDF converters safe for sensitive data?
Traditional online converters that upload your notebook to their backend servers pose security risks for proprietary code and datasets. However, client-side online converters execute their rendering logic locally inside your browser sandbox via JavaScript. Because your data never leaves your computer, client-side tools are safe for sensitive projects.
How do I prevent my plots from looking blurry in the final PDF?
Prevent blurry plots by setting your inline plotting backend resolution before running your code. Include %config InlineBackend.figure_format = 'retina' and plt.rcParams['figure.dpi'] = 300 in your initial setup cell. This forces your visualization packages to generate images at print-ready resolution.
Why are my interactive Plotly charts blank in my PDF?
Plotly charts rely on client-side JavaScript to render graphics. Standard TeX-based PDF engines cannot execute JavaScript, leaving the output cells blank. To fix this, change your Plotly renderer to a static image format using pio.renderers.default = 'notebook_connected+png' or export using an HTML-to-PDF browser workflow.
Can I convert multiple Jupyter Notebooks to PDF at once?
Yes. You can batch convert notebooks via your terminal using the command for f in *.ipynb; do jupyter nbconvert --to webpdf "$f"; done. If you prefer a visual interface, several local-in-browser conversion utilities permit multi-file batch uploads that process each notebook sequentially on your machine.
Conclusion and Actionable Next Steps
Converting an IPYNB file to PDF without losing your figures, tables, and styling does not require wrestling with complex LaTeX dependencies. By adopting modern DOM-based rendering strategies, you can produce professional, publication-grade analytical reports every time.
To guarantee consistent export results across your data science projects, apply these core steps:
. For more on this, see OpenAI.
- Add high-DPI configuration snippets to your notebook templates (
dpi=300andfigure_format='retina'). - Switch from the legacy
nbconvert --to pdfcommand to the modern--to webpdfpipeline or the zero-install HTML-to-browser-print technique. - Ensure interactive visualizations like Plotly or Altair include static image fallbacks.
- Rely on client-side, in-browser conversion utilities when processing proprietary enterprise code.
Start by testing the HTML browser-print workflow on your current notebook today; you will eliminate missing images and broken formatting in seconds.