Thursday 17 May 2018

Inserting pdf images in a Word doc by converting to png/jpg

I wanted to insert some pdf-format images in a Word document, but they always look fuzzy when I do this.

My colleague James suggested I convert the pdf files to a lossless image format like tiff or jpeg or png.

I was able to do this on Linux, using the ImageMagick command:
% convert -density 250 figure.pdf -quality 100 figure.png
where figure.pdf was my input pdf file, and figure.png was the output png file.

If you need to have a certain colourspace (e.g. RGB) and resolution (e.g. 300 dpi), you can use:
% convert -colorspace RGB -units PixelsPerInch -density 300 figure.pdf -quality 100 figure.png
where -density 300 specifies 300 dpi, PixelsPerInch means dpi.
Or for a jpg:
convert -colorspace RGB -units PixelsPerInch -density 300 figure.pdf -quality 100 figure.jpg

To check the colourspace and dpi of an image you can type:
% identify -verbose figure.jpg | more
You'll see something like this, showing it is 300 dpi and in RGB colourspace:
Image: Supplementary_Figure_1_wasExt1_5May2018.jpg
  Format: JPEG (Joint Photographic Experts Group JFIF format)
  Class: DirectClass
  Geometry: 2550x2305+0+0
  Resolution: 300x300
  Print size: 8.5x7.68333
  Units: PixelsPerInch
  Type: TrueColor
  Endianess: Undefined
  Colorspace: RGB


Problem: does your jpg look grainy?
Note that when you do this, a pdf file that looks high resolution is converted to a jpg file that looks a bit grainy. In this case it might be a helpful to convert the pdf first to a tif or gif (e.g. by doing 'Save as' in Acrobat reader and choosing 'tif' or 'gif', or by converting the pdf to a tif/gif using ImageMagick convert command), and then converting the tif/gif to a jpg using the ImageMagick convert command.

Thanks to my Dad and colleague James Cotton for helpful advice!