Embedding Bitmaps and Images
from ironpdf import *
import base64

# Instantiate Renderer
renderer = ChromePdfRenderer()

# Example 1: From an Image File or Bytes
with open(".\icons\iron.png", "rb") as f:
    pngBinaryData = f.read()
    imgDataUri = "data:image/png;base64," + base64.b64encode(pngBinaryData).decode("utf-8")
    imgHtml = f"<img src='{imgDataUri}'>"

pdf = renderer.RenderHtmlAsPdf(imgHtml)
pdf.SaveAs("embedded_example_1.pdf")
pip install ironpdf
Embedding Bitmaps and Images

Embedding Bitmaps and Images

IronPDF for Python can convert raw image byte content into PDFs.

After reading the byte stream from the data source (such as a database, a network connection, or a file), decode it into a character string and build an HTML string that includes it as a base64-encoded src attribute for an img element:

Afterward, call the RenderHtmlAsPdf method with the HTML string as the argument!

The power of IronPDF lies in its use of HTML as a design language. Get your media into something that represents valid HTML, and let IronPDF take care of the rest for you.

Learn to create PDFs with IronPDF for Python today!
View on GitHub

Ready to Get Started?

Version:2026.11just released