What is a good PDF to HTML converter for Ruby on Rails? [closed]
Asked Answered
E

9

14

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)

Entrench answered 14/12, 2009 at 11:40 Comment(2)
Is there a specific reason you need html output, and not something else? As one of the answers says, pdf and html are significantly different document models. If we know the underlying requirement, we might be able to suggest better alternatives...Intricacy
The current logic is to get the pdf and display it as HTML. There are some solutions already developed in my company, but the final rendering is not that good so they want to improve itEntrench
R
12

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.
Rubber answered 6/1, 2010 at 22:19 Comment(1)
Regarding the PDF documents that didn't convert to HTML well, I would recommend testing a few with Adobe's online conversion service. If they still come out sub-par, I wouldn't spend too much time researching alternatives since I would imagine that Adobe's own converters would be the best out there.Rubber
T
7

For PDF to HTML conversion, pdf2htmlEX seems like a pretty good tool (looking at all the examples/samples):

https://github.com/coolwanglu/pdf2htmlEX

Tefillin answered 2/10, 2013 at 20:57 Comment(3)
In my limited testing it produces shockingly good results.Leeanneleeboard
This is gr8 tool, but how to merge with rails?Mckeever
@Mckeever a good place to start is the project wiki: github.com/coolwanglu/pdf2htmlEX/wiki/Quick-Start . I think you can easily plug it into a rails app using the system call.Tefillin
C
3

If all else fails, you could turn each page into an image (using image magick or similar) and display the images, a la http://books.google.com or http://safari.oreilly.com. It'd be a bandwidth hog, but you would get fidelity to the original.

Casern answered 6/1, 2010 at 17:27 Comment(3)
That's an interesting solution, I'll look into thatEntrench
This is how I did it when I needed to convert PDFs very nicely to other formats.Pavilion
This solution isn't very good if you need to actually parse text from the PDF file.Solomon
K
2

I spent a while working on a research project that involved taking PDFs as input. What you're asking for is just a really difficult task, and no software will do it perfectly. Whereas HTML has some structure, like <p>, PDF is purely presentational. An HTML document will say, "this is a paragraph. This is an image." and the presentation is interpreted from that. A PDF document will essentially say: "this character should be rendered at position X,Y. this next chracter will be rendered at position..." etc. So even constructing paragraphs out of that can be hard.

I was working in Java, so I don't think the specific program I used will be of much use to you. Also, I recall that some PDF generators splice an image into smaller images and display them next to each other--that was a huge pain.

Is there any possible way that you can be working with a different format, or lower your expectations? You could do the image thing that Wayne suggests, but then it's not really HTML (and it's not accessible--is that a concern for you?). That might just have to be something you live with.

Kennithkennon answered 10/1, 2010 at 17:48 Comment(0)
H
0

Try use poppler or xpdf. But it's need some magic and binding.

Horny answered 6/1, 2010 at 17:48 Comment(1)
poppler can render pdf to something other. one of the target can be acceptable for You.Horny
S
0

you can try http://www.pdf-to-html-word.com/pdf-to-html which works really good. I paid for it after checking its functionality. You have a free ride to test it. Or else use Acrobat Pro and Save as HTML with CSS. That works too. But it's a pain in the a** to do with a bunch of files.

Shashaban answered 11/1, 2010 at 20:31 Comment(0)
U
0

Can try this. I've taken a first cut at wrapping Ruby around the pdftohtml utility. Gem available here: http://gemcutter.org/gems/pdftohtmlr

Uhf answered 11/2, 2010 at 18:49 Comment(0)
J
0

After using pdftohtml for some time and being dissatisfied with the display results of the html version, I'm considering using either google apps document API or the scribd API (my favorite right now)

http://www.scribd.com/developers/api

In the end, I'll probably use pdftohtml to simply extract the text content of the pdf file and the scribd api to display the original file on the user page

Junkojunkyard answered 12/2, 2010 at 5:53 Comment(0)
S
0

I've just released a ruby gem to convert documents with open office headless (via poyconverter or jodconverter). it also integrates other few librairies (pdftools and netpbm) to extract text dans images from pdf files.

You can find it here https://github.com/itkin/proselytism.git

Feel free to add your own converters and report me some issues

Steapsin answered 6/3, 2013 at 8:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.