\n\"\"\"\n \n# Instantiate Renderer\nrenderer = ChromePdfRenderer()\n \n# Enable JavaScript in our RenderingOptions\nrenderer.RenderingOptions.EnableJavaScript = True\nrenderer.RenderingOptions.WaitFor.RenderDelay(100)\n \npdf_javascript = renderer.RenderHtmlAsPdf(html_with_javascript)\n \n# Export to a file or Stream\npdf_javascript.SaveAs(\"javascript-in-html.pdf\")","about":{"@id":"https://ironpdf.com/python/examples/javascript-html-to-pdf/#product"},"targetProduct":{"@id":"https://ironpdf.com/python/examples/javascript-html-to-pdf/#product"},"keywords":"javascript in html to pdf,convert html with javascript to pdf,ironpdf python,html to pdf using ironpdf,render javascript in pdf,ironpdf javascript support","datePublished":"2023-08-23","dateModified":"2026-05-27"}]}
IRONSOFTWAREHOME
JavaScript in HTML To PDF
from ironpdf import *

html_with_javascript = """
<h1>This is HTML</h1>
<script>
    document.write('<h1>This is JavaScript</h1>');
</script>
"""
 
# Instantiate Renderer
renderer = ChromePdfRenderer()
 
# Enable JavaScript in our RenderingOptions
renderer.RenderingOptions.EnableJavaScript = True
renderer.RenderingOptions.WaitFor.RenderDelay(100)
 
pdf_javascript = renderer.RenderHtmlAsPdf(html_with_javascript)
 
# Export to a file or Stream
pdf_javascript.SaveAs("javascript-in-html.pdf")
pip install ironpdf
JavaScript in HTML To PDF

JavaScript in HTML To PDF

IronPDF for Python can render HTML that contains JavaScript, executing scripts before the PDF is captured so that dynamically generated content appears in the output.

Getting Started

Set RenderingOptions.EnableJavaScript = True on a ChromePdfRenderer instance and optionally call RenderingOptions.WaitFor.RenderDelay(ms) to give scripts enough time to finish before the page is captured. Then render your HTML string or URL as normal.

Understanding the Code

  • EnableJavaScript: When set to True, IronPDF allows <script> blocks and external scripts to execute during rendering. This is False by default for security and performance.
  • WaitFor.RenderDelay(100): Pauses for the specified number of milliseconds after the page has loaded before capturing it as a PDF. Increase this value if scripts take longer to produce their output.
  • RenderHtmlAsPdf(html): Renders the provided HTML string - including the output of any JavaScript - as a PDF document.

Dynamic Content

This feature is essential for pages that use document.write, DOM manipulation at load time, or any JavaScript-driven templating. IronPDF uses the same Chrome rendering engine as a standard web browser, so scripts that work in Chrome will behave the same way in the PDF output.

Learn to convert HTML to PDF with IronPDF for Python!

Ready to Get Started?

Version:2026.10just released

Key in blue circle

Get your free 30-day Trial Key instantly

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF for Python
Book your free Live Demo
Booking Badge

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get a Quote, No Obligation
Your details will always be kept confidential.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Trusted by Millions of Engineers Worldwide
Get your free 30-day Trial Key instantly.
No credit card or account creation required
Python Module Download for PDF
Install with pip

Version: 2026.10

  1. Download and install Python 3.7+.
  2. Install pip from pypi.org if it isn't installed already.
  3. Execute the above command in the terminal.
Python PDF Module
Download Module

Version: 2026.10

Manually install into your project

  1. Download the package
  2. Run this command from the terminal
    pip install ironpdf-2026.10-py37-none-win_amd64.whi

Licenses from $999