Best way to insert high quality figures in MS Word

4

3

I need a way to insert hight quality PDF figures into Word without them distorting.

The figures are mostly scientific graphs generated through Python and Matplotlib. The main problem is the text labels in the graphs not rendering properly.

I know you can insert PDF's as objects and EPS files as images, but these figures then display very poorly in Word.

My current workflow is thus to export the figures as PNG files at 300DPI using Inkscape. However, the figure quality is still not satisfactory, and when I increase the DPI there is no apparent increase in quality.

Does someone know of a good way to insert high quality graphs into Word?

Jonny

Posted 2016-01-27T08:03:25.150

Reputation: 201

Each plot generated in pdf can be generated again in a different format if you have access to the script. With Imagemagick you can specify the dimension in pixel and obtain a png with the definition desired (e.g. 4961x7016 for A4 600 DPI). I strongly suggest you to give a look to Latex (maybe with a GUI as texmaker) instead.

– Hastur – 2016-01-27T09:12:37.523

1Thank you. I am very familiar with Latex, but I'm not allowed to use it (sigh). With Inkscape I can also specify the exact output, but the problem is still that in Word the figure does not render properly, even at 300dpi. And increasing dpi does not seem to make it better. – Jonny – 2016-01-27T09:23:15.573

Imagemagick: Try to play around convert -density 600 file.pdf -resize 4961x7016 mypic.png. Then resize, cut or whatever. Look the link before to have the A4 pixel size, or search on internet for letter format. You can change 600 and 4961x... in your best match. Give it a look here too

– Hastur – 2016-01-27T09:26:22.830

Thank you, but I think the point that I am trying to make is that Word is distorting the figures, so the pre-processing is not the problem. I the meantime I will try Imagemagick. I just installed it. – Jonny – 2016-01-27T10:58:43.263

Answers

3

The neverending battle of Word vs PDF or Eps

With raster images you have to find your compromise between definition and size. If you know that the document will be printed at 600 DPI you can decide to import images with that definition. But if tomorrow you will have an higher definition printer you should start again. If you increase the DPI your document will increase the size and you will require more resources to your system.

If you can work with a vector image you will not incur in problems related to the image definition, but you can find problems related to the font installed, or you can have a bigger file in case, for example, you plot 1 billion data...

When you have to import inside word a file you can:

  • Go to the source: you can substitute or add the format (and eventually the size) required directly in the script that generated the plot. Read from the matplotlib site [1]. It's better if you can save in a Vector Graphics format [1b].

    plt.savefig(pp, format='pdf') 
    plt.savefig(pp, format='png')
    plt.savefig(pp, format='svg')
    

    or even

    fig.savefig('test.pdf')
    fig.savefig('test.png')
    
  • Use imagemagick [2] or Inkscape [2b] or gimp [2b] to convert a pdf in a png (or in other raster formats, tiff,jpg...) or in a svg (or in others vector graphic format).

    This depends if it is a PDF with vector graphic[3] inside or not.
    In the first case you should find some rare rendering or font problems but no definition problems.
    In the latter case you have to choose a density and the dimensions for the final image.
    Read something more for example on this answer [4].
    You will finish to write something similar to:

    convert file.pdf file.svg                                  # If pdf with vector
    convert -density 600 file.pdf -resize 4961x7016 mypic.png  # With fixed grid
    

Note
If the PDF file was created with a Raster images with a specific definition, e.g. 300 DPI, you will not have so much success with any program increasing the DPI to 400 or 600... :-)
As thumb rule (it usually works) you can assume that in a raster pdf there is the string /image.
So under Linux for example you can run grep and count the occurrences of that string:

grep  -c -i "/image" *pdf
MyRasterPdf.pdf:3    # > 0  if raster pdf
MyVectorPdf.pdf:0    # = 0  if vector pdf

Last but not least, consider LaTex, maybe with a GUI as texmaker.

Hastur

Posted 2016-01-27T08:03:25.150

Reputation: 15 043

Thank you. For now Imagemagick is giving me troubles so once I have that working I will give it a bash. – Jonny – 2016-01-27T11:20:55.353

OK, it seems to be working. I think I am also being very anal about the quality of the output. I'm sure it will be good enough, even though the fonts are looking slightly distorted. I will wait to see if the Prof complains (-; – Jonny – 2016-01-27T11:24:30.983

?!?! :) are you being what ? – Hastur – 2016-01-27T11:26:44.723

Haha nevermind. But the output is looking much better now. It's perfect really. A note for people trying to use this in the future, I think you need ghostscript installed for convert from Imagemagick to work properly. – Jonny – 2016-01-27T11:29:34.993

1My workflow for importing matplotlib graphs in Word has been saving as SVG, opening in Inkscape, saving as EMF, and opening in Word. This way, the graphs are kept as vector images, so they are sharp and still scalable in Word. – Armon – 2016-02-04T20:37:39.983

2

In Word 2016, my workflow for importing matplotlib graphics has been:

import matplotlib.pyplot as plt

Export editable text so that I can adjust figures and text in Illustrator, by default matplotlib exports “Type 3 fonts” which Adobe Illustrator doesn’t understand, so you need to export Type 2/TrueType fonts.

plt.rcParams['pdf.fonttype'] = 42
plt.rcParams['ps.fonttype'] = 42 

save figure

plt.savefig('my_figure.pdf',bbox_inches='tight',transparent = True)

Open in Illustrator and adjust as needed

Export image as .emf

Insert my_figure.emf into Word

Kristin Q

Posted 2016-01-27T08:03:25.150

Reputation: 21

1

As of May 2018, Microsoft Word in the Office 365 edition has made two changes which alters the answer to this question:

This means that the best way to handle high quality graphics is to create a figure in Matplotlib which has the correct size (using plt.figure(figsize=(width_in_inches, height_in_inches)), then to export the figure with plt.savefig('filename.svg'). You can insert this file directly into Word and it will be correctly rendered, even when converting to PDF.

This video shows the whole process and compares formats.

chthonicdaemon

Posted 2016-01-27T08:03:25.150

Reputation: 163