14

I wrote a whole latex file. Due to journal's restrictions, I am forced to submit a word file. Since I have pretty complex tables: I don't want to rebuild in Word and copying tables with snipping tool (Windows) from displayed PDF results in a pretty poor resulution, I wondered whether it is possible to print tables as PNG? Is there a more intelligent way to achieve better results?

Some toy table taken from https://en.wikibooks.org/wiki/LaTeX/Tables as MWE:

\documentclass{article} 
\begin{document}    
\begin{tabular}{l*{6}{c}r}
Team              & P & W & D & L & F  & A & Pts \\
\hline
Manchester United & 6 & 4 & 0 & 2 & 10 & 5 & 12  \\
Celtic            & 6 & 3 & 0 & 3 &  8 & 9 &  9  \\
Benfica           & 6 & 2 & 1 & 3 &  7 & 8 &  7  \\
FC Copenhagen     & 6 & 2 & 1 & 3 &  5 & 8 &  7  \\
\end{tabular}
\end{document}
7
  • 1
    Quick and dirty: make a screenshot Jul 28, 2017 at 12:47
  • 3
    Doesn't Word allow you to embed a SVG picture? I know LibreOffice admits it. Jul 28, 2017 at 14:04
  • 2
    There are plenty of ways to convert a PDF (be it LaTeX generated or not) to SVG. If Word allows you to insert a SVG file, you should consider taking this route. I did it with both LibreOffice Writer and LibreOffice Impress in the past and I was able to even retain the text content as searchable text. Jul 28, 2017 at 17:49
  • 2
    PS: woah, it seems that you can either use EMF or SVG (the latter only from Word 2016 onwards): superuser.com/q/397644/278831 You can then retain all the advantages of vector-quality output! Jul 28, 2017 at 17:50
  • 3
    You can also open a PDF document directly with Word 2016 onwards. Has saved me hours of work in similar situations.
    – Mace
    Jul 28, 2017 at 18:54

6 Answers 6

21

For the sake of completeness, I'd like to add that the standalone class can export the document to PNG format (using ImageMagick's convert under the hood), provided that the engine is executed with the --shell-escape option:

\documentclass[convert]{standalone} 
\begin{document}    
\begin{tabular}{l*{6}{c}r}
Team              & P & W & D & L & F  & A & Pts \\
\hline
Manchester United & 6 & 4 & 0 & 2 & 10 & 5 & 12  \\
Celtic            & 6 & 3 & 0 & 3 &  8 & 9 &  9  \\
Benfica           & 6 & 2 & 1 & 3 &  7 & 8 &  7  \\
FC Copenhagen     & 6 & 2 & 1 & 3 &  5 & 8 &  7  \\
\end{tabular}
\end{document}

When invoked without any options, the used preset will be: PNG format, a density of 300 dpi, no explicit size and the output file name is given by \jobname + .png extension. The standalone class has other options, so I recommend taking a look at the documentation. :)

2
  • 1
    This worked quickly and easily for me using OverLeaf!!
    – Wayne
    Oct 3, 2020 at 16:07
  • 2
    Sorry, but it did not work here... the table is still text (vector)... it is not raster PNG.
    – LEo
    Jan 20, 2021 at 20:15
12

Others have provided good answers but I have one that is simpler, at least for me.

  1. Compile the Tex file to a PDF
  2. Open the PDF with Inkscape (or another vector graphics program like Adobe Illustrator)
  3. Size the page to your needs and export a PNG.

Here is my exported PDF at 300 dpi. I like this method because it's easy to re-export your figures as any file format that you need. I think this solution is fairly elegant as it can allow you to save the vectorized graphics if you chose to save it as a PDF file.

enter image description here

8

Another way is to use the dvipng program which comes with miktex and texlive. Assuming your file is called mytable.tex you can use the following:

latex mytable.tex
dvipng -D 300 -bg Transparent -T tight -o mytable.tex.png mytable.tex.dvi

The first line will generate a .dvi file which is used to generate a .png file with a resolution of 300 dpi in the second line.

You can read more about dvipng here: https://linux.die.net/man/1/dvipng

I prefer to use the standalone document class when creating images with latex, since it crops any white space around the content.

5

Definitely possible, I found some good reads:

Your recipe goes like this:

  1. Download image magic - I used the portable version ImageMagick-7.0.6-3-portable-Q16-x64 for your example. Unpack it.
  2. Compile your pdf.
  3. Copy your pdf to the image magic folder. Lets call it tabular.pdf
  4. On Windows: you press Ctrl+Rand then type cmd- this will open a command-line window for for you.
  5. Change to the correct directory by typing cd **"**IMAGMAGICKPATH**"**. The IMAGMAGICKPATH should be the path were you unpacked your portable IMAGEMAGICK or wherever you installed IMAGEMAGICK. In my case I used cd "C:\Users\nhck\Downloads\ImageMagick-7.0.6-3-portable-Q16-x64".
  6. No, to convert, type: convert -density 300 -quality 100 tabular.pdf tabular.png

Pay attention about the paths here. In this example I was in the Imagemagick folder and had copied tabular.pdf there as well. The output was saved there as well.

edit: Maybe a comment on convert: You can find the handbook for convert here: http://www.imagemagick.org/script/convert.php In the example I set the densityoption to 300 - representing a resolution of 300dpi. This should be sufficient for print. If you plan to resize (enlarge the image) you should go for a higher resolution here. The qualityoption addresses image compression: The lower this value the lower the output file size and the image quality. In your case quality is most important and file size typically doesn't matter, so I set it to 100 - which is the upper limit.

2
  • 1
    Thanks for quick response! I downloaded image magic. However, my slightly stupid question is: where can I allocate command line in this program?
    – Jens
    Jul 28, 2017 at 8:58
  • 2
    I've tried to extend the answer for you. Maybe this video also helps:youtu.be/MBBWVgE0ewk
    – nhck
    Jul 28, 2017 at 9:12
3

Another way to convert to .png format using Texmaker , first compile the LaTeX file using Texmaker, go to view pdf , then write click on that you will have an option to convert to .png format.

1

I figured out a simple way to do this with some online tools (no need for Inkscape or anything of the sort). So for me, the LaTeX PDF I'm working with is 7 pages long. I first downloaded the PDF from Overleaf (the LaTeX editor I'm using) and I go to avepdf.com and upload my whole PDF to the Extract PDF Pages tool. I select page 5, and AvePDF spits back a PDF file containing only one page: namely, the page that contains the table I want.

By the time I have my one-page PDF containing my table, I'm 90% of the way there. You can now use an online tool to directly crop your one-page PDF file to generate a PDF file containing just the table (AvePDF has a tool for this) and then you could use another online tool to convert that cropped PDF to a PNG file (for convenience I again just used the one on the AvePDF website).

Here's the PNG file I ended up with starting from my PDF file containing the table:

enter image description here

And for your table, I got this:

enter image description here

You must log in to answer this question.

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