Code Scrambler
BlogBlogHire meHire meCVCV
Sign InGet a Quote
NavigationGet a Quote

Apps

TikZpenCashCraftSubSync
BlogHire meCV

Account

Sign In
Code Scrambler Productions

I'm Zsombor, an independent software developer and founder of Code Scrambler Productions. Games, full-stack web apps, mobile apps and backend systems, built end to end.

Available for remote work

Remote · Flexible · Asynchronous · Project-based. Looking for a developer for a role, a project or a contract? Let's talk.

Hire MeRemote from Hungary, roughly 5–20 hrs/week, async-friendly.

Built with Next.js, Firebase, and a bias toward useful software.

Explore

  • Home
  • Work
  • About
  • Apps
  • Librarian
  • Blog

Tools

  • CashCraft
  • CashCraft Rates
  • SubSync
  • TikZPen
  • Bug Reports

Work With Me

  • CV
  • Contact
  • Hire Me
  • For Business

Legal

  • Privacy Policy
  • Delete CashCraft Data
  • Terms of Service
© 2026 Code Scrambler Productions·Budapest, Hungary

tikzpen v260911aB · cashcraft v260422a

Blog

How to Export TikZ to PNG, SVG and PDF (Command Line and Online)

Turn a TikZ figure into a cropped PDF, a PNG for slides or the web, or a clean SVG, using standalone, pdflatex, pdftocairo and dvisvgm.

October 12, 20261 min read1 viewZsombor Rózsa
Contents
  • Step 1: wrap the figure in standalone
  • Step 2: compile to PDF
  • PNG
  • SVG
  • Transparent background
  • Common problems

You drew something in TikZ and now need it as an image for a slide deck, a README or a website. The reliable path is: compile to a tightly cropped PDF first, then convert that PDF to whatever you need.

TikZ source
% libraries: arrows.meta, positioning
\begin{tikzpicture}[font=\sffamily\small, >={Stealth},
  f/.style={draw, rounded corners, fill=blue!8, minimum height=8mm, minimum width=2.1cm, align=center},
  o/.style={draw, rounded corners, fill=green!12, minimum height=7mm, minimum width=3cm}]
  \node[f] (tex) at (0,0) {figure.tex};
  \node[f] (pdf) at (4.6,0) {figure.pdf};
  \node[o] (png) at (9.6,1.3) {PNG};
  \node[o] (svg) at (9.6,0) {SVG};
  \node[o] (inc) at (9.6,-1.3) {PDF in a document};
  \draw[->] (tex) -- node[above] {pdflatex} (pdf);
  \draw[->] (pdf.east) -- ++(0.6,0) |- node[above, pos=0.78] {pdftocairo} (png.west);
  \draw[->] (pdf.east) -- node[above, pos=0.55] {dvisvgm} (svg.west);
  \draw[->] (pdf.east) -- ++(0.6,0) |- node[above, pos=0.78] {\textbackslash includegraphics} (inc.west);
\end{tikzpicture}

Step 1: wrap the figure in standalone#

\documentclass[tikz,border=4pt]{standalone}
\begin{document}
\begin{tikzpicture}
  \draw[thick, ->] (0,0) -- (3,0) node[right] {$x$};
  \draw[thick, ->] (0,0) -- (0,2) node[above] {$y$};
\end{tikzpicture}
\end{document}

That compiles to this, cropped to the drawing plus a 4pt border, with no white page to trim:

TikZ source
\begin{tikzpicture}
  \draw[thick, ->] (0,0) -- (3,0) node[right] {$x$};
  \draw[thick, ->] (0,0) -- (0,2) node[above] {$y$};
\end{tikzpicture}

Step 2: compile to PDF#

pdflatex figure.tex

This gives figure.pdf, a vector file you can already use in LaTeX documents with \includegraphics.

PNG#

pdftocairo (part of Poppler) is quick and anti-aliases well:

pdftocairo -png -r 300 -singlefile figure.pdf figure

-r 300 is 300 dpi; raise it for sharper slides. -singlefile avoids the -1 suffix on the output name. ImageMagick also works (magick -density 300 figure.pdf figure.png) but may need Ghostscript and a permissive policy file.

Resolution matters mostly for thin lines, which is why a plot that looks fine on screen can look weak on a projector:

TikZ source
\begin{tikzpicture}[x=1.4cm, y=0.5cm]
  \draw[line width=0.1pt] (0,-2) -- (4,-2) node[right, font=\footnotesize] {0.1 pt: hairline, can vanish when scaled down};
  \draw[line width=0.4pt] (0,-4) -- (4,-4) node[right, font=\footnotesize] {0.4 pt (TikZ default)};
  \draw[line width=1pt]   (0,-6) -- (4,-6) node[right, font=\footnotesize] {1 pt: safe for slides};
\end{tikzpicture}

SVG#

pdftocairo -svg figure.pdf figure.svg

or, with the TeX Live tool:

dvisvgm --pdf figure.pdf

dvisvgm produces compact SVG and converts fonts to paths by default, which is handy if the viewer lacks your fonts.

Transparent background#

PDFs have no background, so PNGs from pdftocairo are transparent by default. If you see white, it came from the viewer, not the file.

Common problems#

  • Text looks too small or large in the image. Change the document font size in the class options (\documentclass[tikz,border=4pt,12pt]{standalone}), not the PNG resolution.
  • Cut-off labels. Increase border= or give wide nodes a text width.
  • Missing library errors. Add the \usetikzlibrary{...} line your figure needs to the preamble.

If you would rather not run a TeX toolchain at all, TikZpen, a free browser editor I built, exports TikZ, SVG and PNG. New to TikZ itself? Start with drawing shapes, arrows and curved paths.

tikzlatextutorial
MarkdownRSSXLinkedInBluesky
…
Zsombor Rózsa
Zsombor Rózsa

I’m Zsombor, an independent software developer and founder of Code Scrambler Productions.

← PreviousThe Definitive Guide to Autodesk Fusion on CachyOS (KDE Plasma 6 + Wayland)Next →How do you grade a forged painting? Scoring a hand-painted copy without comparing pixels

Related

TikZ Tutorial: Draw Shapes, Arrows and Curved Paths in LaTeX

A practical TikZ tutorial for beginners: set up a standalone figure, then draw lines, rectangles, circles, arrows, nodes and Bézier curves with copy-paste code and the result next to it.

October 12, 2026 · 2 min read
Rebuilding a visual TikZ editor around a TikZ-shaped document model

Why I rebuilt TikZpen from scratch: a data model shaped like TikZ, one renderer shared by the canvas and the export, and a compile-based check that proves the exported code matches the drawing.

October 12, 2026 · 2 min read

Comments

Want to join the conversation?

Log in to comment

Contents

  • Step 1: wrap the figure in standalone
  • Step 2: compile to PDF
  • PNG
  • SVG
  • Transparent background
  • Common problems