\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")
NuGet Download
Install-Package 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.8just released

Key in blue circle

Get your free 30-day Trial Key instantly.

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
Book your free Live Demo
Booking Badge

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required