9

I'm trying to convert a table to png format using Imagemagick

\documentclass[12pt,a4paper,border=8pt,convert=true]{standalone}

\usepackage{booktabs}
\usepackage{caption}
\usepackage{siunitx}
\sisetup{binary-units = true,
         table-format=7.0}

\begin{document}

    \minipage{1.08\textwidth}
    \addtolength{\tabcolsep}{-1.0pt}
    \begin{tabular}{lS[table-format=6.0]
            S[table-format=6.0]
            S[table-format=6.0]
            SSS}
        \toprule
        Device & 2011 & 2012 & 2013 & 2014 & 2015 & 2016 \\
        \midrule
        Non-smarthphones & 22686 & 55813 & 108750 & 196262 & 357797 & 615679 \\
        Smarthphones & 104759 & 365550 & 933373 & 1915173 & 3257030 & 5221497 \\
        Laptops e Netbooks & 373831 & 612217 & 917486 & 1340062 & 1963950 & 2617770\\
        Tablets & 17393 & 63181 & 141153 & 300519 & 554326 & 1083895\\
        Home gateways & 55064 & 108073 & 180562 & 267545 & 376494 & 514777 \\
        M2M & 23009 & 47144 & 92150 & 172719 & 302279 & 508022 \\
        Altri devices & 525 & 1460 & 5429 & 22966 & 84204 & 242681\\
        \bottomrule
    \end{tabular}
    \captionof*{table}{Traffico mobile globale al mese per dispositivo in \si{\tera\byte}}
    \endminipage

\end{document}

Here it is the table create using standalone package. I read the documentation and it says to use ImageMagick. The problem is when I compile it doesn't find the exacutable imgconvert.exe. So I put this exacutable into folder where there is tex file. Now when I compile I got another error:

imgconvert.exe: `%s' (%d) "gswin32c.exe" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE 
-dNOPROMPT -dMaxBitmap=500000000 -dEPSCrop -dAlignToPixels=0 -dGridFitTT=2 
"-sDEVICE=pngalpha" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r300x300" 
"-sOutputFile=C:/Users/MAZZAR~1/AppData/Local/Temp/magick-31681PKeFVHE065o" 
"-fC:/Users/MAZZAR~1/AppData/Local/Temp/magick-3168A-Fab6j3iIUc" 
"-fC:/Users/MAZZAR~1/AppData/Local/Temp/magick-3168QXzuvG_UAP07" 
@ error/utility.c/SystemCommand/1890. imgconvert.exe: Postscript delegate failed 
`table.pdf': No such file or directory @ error/pdf.c/ReadPDFImage/678.
imgconvert.exe: no images defined `table.png' @ error/convert.c/ConvertImageCommand/3066.
3
  • 1
    convert is also the MS tool for FAT to NTFS conversion of harddrives, therefore the recommendation is to rename Image Magick's convert.exe to imgconvert.exe. In order not to be blamed for any data loss due to my standalone package (even if this is very unlikly) I put the default executable name to imgeconvert. This can be change using the convert={convertexe={convert.exe}} class option. This all is also described in detail in the standalone manual. Jan 18, 2013 at 15:28
  • I don't recognise the error you get, but I didn't tested standalone much under MS Windows. I developed it under Linux and there it works well. I fixed some quoting issues with Windows, one actually very recently. Maybe there is a similar issue here. I will try to debug this at my Windows machine soon. Jan 18, 2013 at 15:30
  • Also, bugs with standalone should be reported to the package bug tracker. (There is one for each of my packages.) Bug reports should not be posted here, see Questions which are bug reports on Meta for the discussion about it. Jan 18, 2013 at 15:33

5 Answers 5

17

First, about the trouble with the executable name:

convert is also the MS tool for FAT to NTFS conversion of hard disk drives, therefore the recommendation is to rename Image Magick's convert.exe to imgconvert.exe. In order not to be blamed for any data loss due to my standalone package (even if this is very unlikely) I put the default executable name to imgconvert. This can be change using the convert={convertexe={convert.exe}} class option. This all is also described in detail in the standalone manual.

I would recommend Windows users to either rename or copy the convert.exe file to imgconvert.exe or change the standalone.cfg file to include:

 \standaloneconfig{convert={convertexe={convert.exe},false}}

Now to the error message you get:

I tried this under Windows and found out that it depends on the version of Image Magick. With v6.6.9 I get the same error. Here it doesn't matter if it is called from standalone or manually from the command line. However with v6.8.1 I just downloaded today from here it works without any issues (after selecting the right executable name as mentioned above). It seems there is an issue with PDF using v6.6.9 and maybe other versions after it before v6.8.1.

Therefore the fix for your problem is to update Image Magick. If this doesn't fix your issue, or if you already have v6.8.1 installed, then please post the used version number here. Also try to convert it manually using the command line convert.exe -density 300 file.pdf -quality 90 file.png. If this also throws the same error it isn't an issue with standalone but only with ImageMagick.

2
  • 2
    Please, is imgeconvert a misspell of imgconvert or not?
    – yo'
    Apr 9, 2014 at 10:31
  • 1
    @yo': Sorry, yes I misspelled that one. I fixed it now. Feb 15, 2018 at 11:34
4

The error message tells you that "gswin32c.exe" cannot be found. Install Ghostscript and the problem should be resolved.

1
3

For some reasons, I too get the same error and was never able to use standalone directly for conversion (I am on windows). It is because the name of the executable is simply convert.exe whereas the standalone searches for imgconvert.exe. :-( I just took a copy of convert.exe and renamed it as imgconvert.exe and put it back in the installation folder of imagemagick. Then your code works fine.

If it is not working for you, then the most possible reason (as is evident from your error report) is the imgconvert.exe is not in the system's path as a result of which it is not found. Try to add it to your system path or reinstall imagemagick (while doing that it will ask you whether you want to add it to the path).

Here is another method to get png files. But for this also convert.exe (here only convert.exe) must be in system's path. Otherwise this won't work!

(Compile with pdflatex):

\documentclass{article}
\usepackage{filecontents}
\begin{filecontents*}{mytable.tex}
  \documentclass[12pt,a4paper,border=8pt,convert=true]{standalone}

\usepackage{booktabs}
\usepackage{caption}
\usepackage{siunitx}
\sisetup{binary-units = true,
         table-format=7.0}

\begin{document}

    \minipage{1.08\textwidth}
    \addtolength{\tabcolsep}{-1.0pt}
    \begin{tabular}{lS[table-format=6.0]
            S[table-format=6.0]
            S[table-format=6.0]
            SSS}
        \toprule
        Device & 2011 & 2012 & 2013 & 2014 & 2015 & 2016 \\
        \midrule
        Non-smarthphones & 22686 & 55813 & 108750 & 196262 & 357797 & 615679 \\
        Smarthphones & 104759 & 365550 & 933373 & 1915173 & 3257030 & 5221497 \\
        Laptops e Netbooks & 373831 & 612217 & 917486 & 1340062 & 1963950 & 2617770\\
        Tablets & 17393 & 63181 & 141153 & 300519 & 554326 & 1083895\\
        Home gateways & 55064 & 108073 & 180562 & 267545 & 376494 & 514777 \\
        M2M & 23009 & 47144 & 92150 & 172719 & 302279 & 508022 \\
        Altri devices & 525 & 1460 & 5429 & 22966 & 84204 & 242681\\
        \bottomrule
    \end{tabular}
    \captionof*{table}{Traffico mobile globale al mese per dispositivo in \si{\tera\byte}}
    \endminipage
\end{document}  
\end{filecontents*}
% compile with pdflatex
\immediate\write18{pdflatex --shell-escape mytable}
% convert to PNG
\makeatletter
\immediate\write18{convert -density 500 -alpha on mytable.pdf mytable-\@percentchar02d.png}
\makeatother
%
\begin{document}
Check the folder for your \verb|mytable-00.png| file.
\end{document}

Your code is in between \begin{filecontents*} and \end{filecontents*}. You must have imagemagick installed and the executable should be in the system path for this to work.

8
  • I pasted your code and runned it. It works but no file png has been created. I put in the same folder of tex file imgconvert.exe. This is the result in the log: LaTeX Warning: Overwriting file ./mytable.tex'. \openout15 = mytable.tex'. LaTeX Warning: Tab has been converted to Blank Space. runsystem(pdflatex --shell-escape mytable)...disabled (restricted). runsystem(convert -density 500 -alpha on mytable.pdf mytable-%02d.png)...disabl ed (restricted).
    – Mazzy
    Jan 15, 2013 at 13:15
  • I download imagemagick and installed it. After I renamed the exacutable to imgconvert.exe and put in the same folder of main tex file. When I execute no error appear but I got this warning that don't let me have png file. I checked the rights and I think I have access correctly
    – Mazzy
    Jan 15, 2013 at 13:28
  • I have to include shell-escape to pdflatex?
    – Mazzy
    Jan 15, 2013 at 13:31
  • Yes I got that big list...but It still doesn't work
    – Mazzy
    Jan 15, 2013 at 13:34
  • @Mazzy Check if imagemagick is in system's path. See the edit.
    – user11232
    Jan 15, 2013 at 15:12
0

The following is a minimal example of how to compile a .tex file into a PNG file using TeX Live on Windows 10. First of all, save the following tex code in a file called mini.tex:

\documentclass[11pt, border=10pt]{standalone}
\begin{document}
Blah blah blah
\end{document}

mini.tex can be compiled into a PDF and then converted to a PNG image file with Tex Live on Windows 10 using the following powershell commands:

pdflatex mini.tex
$env:GS_LIB="C:/texlive/2022/tlpkg/tlgs/Resource/Init;C:/texlive/2022/tlpkg/tlgs/lib;C:/texlive/2022/tlpkg/tlgs/kanji"
C:/texlive/2022/tlpkg/tlgs/bin/gswin32c.exe -dSAFER -dBATCH -dNOPAUSE -sDEVICE=png16m -r300 -sOutputFile="mini.png" mini.pdf
  • The $env:GS_LIB=... command above only needs to be used once per terminal session, in order to set the GS_LIB environment variable, so that gswin32c knows where to find the files gs_init.ps, cidfmap, and kfwin32.ps respectively
  • The path names in this command as well as the full path of gswin32c.exe may need to modified depending on the location of these files in a given installation of Tex Live
  • Alternatively (IE instead of setting the GS_LIB environment variable) these paths can be included in the gswin32c.exe command (without needing to first set any environment variables) by specifying the -I flag individually before each path (source)
  • The double quotes around mini.png appear to be necessary to prevent gswin32c returning the error Error: /undefinedfilename in (.png)
  • Building mini.tex into mini.pdf and then converting this into mini.png with the commands shown above successfully produces the the following image:

mini.png

0

I came across the same issue today.

Changing convert in the \documentclass setting to magick can solve it.

Change the tex file from

\documentclass[12pt,a4paper,border=8pt,convert=true]{standalone}
...
\begin{document}
\end{document}

to

\documentclass[12pt,a4paper,border=8pt,magick=true]{standalone}
...
\begin{document}
\end{document}
1
  • 2
    Please add the full answer. If it is ever promoted to the top answer, then it's easier for people to work from a complete answer instead of scraping together from multiple answers.
    – thymaro
    Mar 13 at 8:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .