Tx · LaTeX & TikZ

How to Convert a PDF Image to PNG for TikZ

Updated 13 October 2026

At a glance

  1. 1. Choose your goal

    For LaTeX output, you can usually include the PDF directly; convert it only if you specifically need a PNG.

  2. 2. Rasterize the page

    Use pdftoppm with a selected page and resolution to create a PNG file.

  3. 3. Include the image

    Load graphicx and place the PNG with includegraphics, either directly or inside a TikZ node.

  4. 4. Check the result

    Compile and verify the crop, dimensions, and image sharpness at its final printed or on-screen size.

TikZ is a drawing system, not a PDF-to-PNG converter. For most LaTeX documents, you do not need to convert the PDF at all: you can include it as a vector image and place it inside a TikZ picture. If another program requires a PNG, rasterize the PDF page first, then include the resulting file.

Keep the PDF when you can

A PDF graphic usually stays sharp when you zoom or print because it can preserve vector paths and text. A PNG is a raster image made of pixels, so enlarging it can make edges look jagged. With pdfLaTeX, LuaLaTeX, or XeLaTeX, the graphicx package can generally include PDF files directly.

For example, replace diagram.png with diagram.pdf in the code below to include the PDF without conversion. The same example also shows how to put an image inside a TikZ node.

\documentclass{article}
\usepackage{graphicx}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
  \node[inner sep=0] {\includegraphics[width=8cm]{diagram.pdf}};
\end{tikzpicture}

\end{document}

This example needs the graphicx and tikz packages. If you do not need TikZ to position or annotate the image, use \includegraphics by itself; wrapping an image in a TikZ picture is optional. A traditional LaTeX-to-DVI workflow may not support direct PDF inclusion, so check your compiler if the PDF format is rejected.

Convert a PDF page to PNG

A common command-line option is Poppler’s pdftoppm. To convert only the first page at 300 dots per inch (dpi), run:

pdftoppm -f 1 -l 1 -singlefile -png -r 300 input.pdf output

This creates output.png. The options select the first page, produce one file without a page-number suffix, choose PNG format, and set the resolution to 300 dpi. Replace input.pdf with your file’s path. For a multipage document, omit -f, -l, and -singlefile; pdftoppm will create a separate numbered PNG for each page.

If the PDF has extra page margins and you want to use its CropBox rather than its full page boundary, add -cropbox:

pdftoppm -f 1 -l 1 -singlefile -png -r 300 -cropbox input.pdf output

The resolution controls the raster image’s pixel dimensions. As a rough guide, a 6-inch-wide graphic rendered at 300 dpi is about 1,800 pixels wide. Choose the resolution based on the image’s final size and the detail it contains; increasing it creates a larger file, but cannot restore detail that was not present in the source.

Include the PNG in a TikZ picture

Once the conversion has produced output.png, use its filename in \includegraphics:

\documentclass{article}
\usepackage{graphicx}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
  \node[inner sep=0] {\includegraphics[width=8cm]{output.png}};
\end{tikzpicture}

\end{document}

Keep the PNG in the same folder as the .tex file, or provide a relative path such as images/output.png. You can also put the image in a node with a name and draw TikZ shapes around it; the PNG itself remains an image rather than becoming TikZ paths.

If the PDF was made with TikZ

If you mean that you want to turn your own TikZ drawing into a PNG, compile the drawing to PDF first, then rasterize that PDF with pdftoppm. The standalone class is useful for generating a tightly cropped PDF:

\documentclass[tikz,border=2pt]{standalone}

\begin{document}
\begin{tikzpicture}
  \draw[thick] (0,0) circle (1cm);
  \draw[->] (-1.5,0) -- (1.5,0);
\end{tikzpicture}
\end{document}

Compile this file to drawing.pdf, then run pdftoppm -f 1 -l 1 -singlefile -png -r 300 drawing.pdf drawing. This produces drawing.png. This is a two-stage workflow: LaTeX creates the PDF, and Poppler converts the PDF page to pixels.

Common mistakes

  • Expecting TikZ to do the conversion: TikZ can place and draw over images, but use a separate converter to rasterize a PDF.
  • Converting unnecessarily: If your final output is a PDF, including the original PDF often preserves better quality and avoids a larger raster file.
  • Using too low a resolution: A PNG that looks fine on screen may appear soft when printed or enlarged. Render it at a resolution suitable for its final size.
  • Including the wrong page or crop: For a multipage PDF, select the intended page. Use -cropbox if the default page boundary includes unwanted margins.
  • Using a filename LaTeX cannot find: Check the spelling, extension, capitalization, and relative path. PNG and PDF file extensions are not interchangeable if the named file does not exist.

References

  1. The graphics bundle — CTAN
  2. PGF — Create PostScript and PDF graphics in TeX — CTAN

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.