michael orlitzky

Fixing PDF graphics in LyX

posted 2012-05-11

The Problem

PDF graphics1 in LyX look awful. Example:

Default LyX PDF to PNG Conversion

Note: this doesn't affect the final output, but the preview still looks like my butt.

This is because, by default, LyX must convert from PDF→EPS→PNG which runs through pdftops, ghostscript, and ImageMagick.

We can fix this by creating a direct path from PDF to PNG, and making that path not suck.

The Fix

  1. Choose Preferences from the LyX menu.
  2. Expand File Handling, and choose Converters.
  3. Scroll down to the PDF→EPS converter. We're going to use this as a template for our new conversion.
  4. Change the To format to PNG.
  5. Paste the command below into the Converter textbox.
  6. Click Add.
  7. Save and exit.

Magic Command

user $ gs -q -dBATCH -dNOPAUSE -sDEVICE=png16m -r720 -sOutputFile=%stdout $$i | convert -scale 12.5% - $$o

Essentially this just creates a high-resolution image from your PDF, and then scales it using ImageMagick's convert command. You can see the results below.

Fixed LyX PDF to PNG Conversion

  1. When you choose Insert→Graphics and then choose a PDF image.