[Tex/LaTex] Convert pdf image to png. TiKZ

pngtikz-pgf

I'm making a small automata with TiKZ and I need to convert it to a png without having all the empty space around. Right now I get a whole page but I only want the automata.

I have followed the instructions from this link but I couldn't make it work.
Compile a LaTeX document into a PNG image that's as short as possible

My original code:

  \documentclass{article}

  \usepackage{tikz}
  \usetikzlibrary{automata,positioning}

  \begin{document}
  \begin{tikzpicture}[shorten >=1pt,node distance=6cm,on grid,auto]

  \node[state,initial] (q_0)   {$q_0$}; 
  \node[state,accepting](q_3) [right=of q_0] {$q_3$};

  \path[->] 
  (q_0) edge              node {bb+(a+ba)(ab)*(a+bb)} (q_3);

  \end{tikzpicture}
  \end{document}

Best Answer

You can use the standalone class with tikz option.

  \documentclass[tikz]{standalone}

  \usetikzlibrary{automata,positioning}

  \begin{document}
  \begin{tikzpicture}[shorten >=1pt,node distance=6cm,on grid,auto]

  \node[state,initial] (q_0)   {$q_0$}; 
  \node[state,accepting](q_3) [right=of q_0] {$q_3$};

  \path[->] 
  (q_0) edge              node {bb+(a+ba)(ab)*(a+bb)} (q_3);

  \end{tikzpicture}
  \end{document}