What is a good PDF to HTML converter for Ruby on Rails?

marcgg picture marcgg · Dec 14, 2009 · Viewed 15.7k times · Source

I'm trying to convert programatically PDF to HTML. So far I've been using pdftohtml but our users are not happy with the results.

Here's what I need :

  • I'm using Ruby on Rails, but any tool working on Unix would work as I can call it from the command line. But of course a nice gem or plugin would be perfect.

  • I'd prefer it to be open source

  • It needs to be able handle images

  • It would be nice if there was an option to discard images if needed

  • It needs to be stable

  • It needs to return html with a layout close to the original pdf (I've tried pdftohtml and the result is not that good in a lot of cases)

Answer

bta picture bta · Jan 6, 2010

Here are a couple more alternatives to pdftohtml/xpdf:

  • Adobe has a free online PDF to HTML or text conversion service. It might take a minute or two to get the document back, but I would suspect that this option would give you the best results.
  • There is a pdf-reader ruby gem that will give you access to the internals of the PDF file. This would involve some development/extension on your part, but you could use this to parse the PDF file and generate nice-looking HTML. This might be easier than it sounds if you know what type of files your users are converting ahead of times (such as if they are working with standardized forms).
  • You may have more options if you use ghostscript (gem found here) to convert the PDF to another format first. The gem can generate images (png, jpg, etc) from a PDF file but you might have the best luck converting it into a PostScript file since there seem to be a zillion "PostScript-to-[insert format here]" converters.