I used to be able to create png images of diagrams made with tikz code by using the preview package and printing the dvi output from dvips to a png file using ghostscript. The latest version of tikz seems to have broken this ability in some way.
If I use the following latex code:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows,snakes,backgrounds,patterns,matrix,shapes,fit,calc,shadows,plotmarks}
\usepackage[graphics,tightpage,active]{preview}
\PreviewEnvironment{tikzpicture}
\begin{document}
\begin{tikzpicture}
\draw (0,0) rectangle (1,1);
\end{tikzpicture}
\end{document}
I then run Latex to get the dvi file, and dvips to convert to postscript. I then run ghostscript to produce the png with the following command:
gswin32c.exe -sDEVICE=png16m -dTextAlphaBits=4 -r300 -dGraphicsAlphaBits=4 -dSAFER -q -dNOPAUSE -sOutputFile="tikz_preview_png_problem.png" -f "tikz_preview_png_problem.ps"
Previous to tikz 2.1 this worked fine, but now produces the following output:
Error: /undefined in pgfo
Operand stack:
Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-
- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- fa
lse 1 %stopped_push 1878 1 3 %oparray_pop 1877 1 3 %oparray_
pop 1861 1 3 %oparray_pop 1755 1 3 %oparray_pop --nostringval-
- %errorexec_pop .runexec2 --nostringval-- --nostringval-- --nostringv
al-- 2 %stopped_push --nostringval--
Dictionary stack:
--dict:1161/1684(ro)(G)-- --dict:0/20(G)-- --dict:74/200(L)-- --dict:95
/300(L)--
Current allocation mode is local
Last OS error: No such file or directory
Current file position is 9094
GPL Ghostscript 8.71: Unrecoverable error, exit code 1
Is there any way to get around this, it's a pain in the bum as I liked to be able to produce high res png of my vector graphics for use in non-latex docs or websites etc. I'm using Miktex on windows with Texniccenter as my editor in case it is relevant.
pdflatex
instead? It works fine and also allows you to convert to PNG. Have a look at thestandalone
class which is helpful here. The upcoming version will have an option to convert the output to a PNG automatically.standalone
class uses thepreview
package internally, so it just reduces the code overhead, but won't save you from the ghostscript error.tikzpicture
fortabular
or even a PSTrickspspicture
everything rolls along smoothly.