6

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?

4
  • 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
    Jan 27, 2016 at 9:12
  • 1
    Thank 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
    Jan 27, 2016 at 9:23
  • 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
    Jan 27, 2016 at 9:26
  • 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
    Jan 27, 2016 at 10:58

4 Answers 4

4

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.

5
  • Thank you. For now Imagemagick is giving me troubles so once I have that working I will give it a bash.
    – Jonny
    Jan 27, 2016 at 11:20
  • 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
    Jan 27, 2016 at 11:24
  • ?!?! :) are you being what ?
    – Hastur
    Jan 27, 2016 at 11:26
  • 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
    Jan 27, 2016 at 11:29
  • 1
    My 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
    Feb 4, 2016 at 20:37
4

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.

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

0

Remove automatic decompression of images from Word by adjusting image compression settings. Word has default compression settings that may reduce the image quality to reduce file size. To modify these settings:

  1. Insert the image into Word using the "Insert Picture" function.
  2. Right-click on the inserted image and select "Format Picture" or "Size and Position."
  3. In the Format Picture or Size and Position pane, choose the "Compress" option.
  4. Uncheck the "Apply only to this picture" box and select the desired resolution or target output quality.

To adjust the image compression settings in Microsoft Word and ensure it saves images at the best quality, you can modify the default settings so that Word no longer applies compression to images when you insert them, preserving their original quality.

  1. Open Microsoft Word and click on the "File" tab in the top-left corner.
  2. Select "Options" from the menu. This will open the Word Options dialog box.
  3. In the Word Options dialog box, click on the "Advanced" tab on the left side.
  4. Scroll down to the "Image Size and Quality" section.
  5. Under the "Image Size and Quality" section, you will find the "Default resolution" option.
  6. By default, it is set to "High fidelity." However, you can select the "Do not compress images in file" option to disable compression altogether.
  7. Click on the "OK" button to save the changes.

However, keep in mind that this may result in larger file sizes, so consider the impact on the overall document size and any file size restrictions for submission.

Reference: https://chat.openai.com/share/26d14c16-2cbd-4e48-a50b-523eb7c91732

*** This works the best ***

1

You must log in to answer this question.

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