1

I've been at it for quite some time and all i could uncover was this pdf2dom parser and probably a reverse engineered version of this. Anyway, here are my questions. For any rendering engine its input should be a stream of data (in my case the pdf content) and its output should be a chosen format (in my case DOM, HTML & CSS).

  1. However, instead of using java or c++, is it possible that i get the stream of "pdf data" (which is something i have no idea about) from the server and store into a javascript variable and use javascript to render it and append it to the DOM?

  2. How does the raw "pdf data" appear (is there any particular format.. etc)?

All inputs are welcome.

NOTE : Should be IE compatible.

Ashwin Krishnamurthy
  • 3,750
  • 3
  • 27
  • 49

2 Answers2

6

It's been done already. The result is pdf.js. Note that it's working by rendering the PDF onto a canvas. The result can be guaranteed that way; some features of PDF wouldn't be possible outside the canvas currently.

Chris Morgan
  • 86,207
  • 24
  • 208
  • 215
  • Hey that's really nice, had no clue about this project. – Graham Dec 19 '11 at 10:21
  • Sorry. My bad. I did come across this, but canvas is not the option for me because i have to support ie 6,7,8 too X-D, hence i have to do the rendering myself. Ill update my question. +1 as this is next best thing. – Ashwin Krishnamurthy Dec 19 '11 at 10:24
  • 1
    @Astroth: you could try using it with [ExplorerCanvas](http://code.google.com/p/explorercanvas/). It wouldn't be perfect, but I think it would probably do a generally passable job. Just as good as you could manage without using the canvas, anyway, I imagine. – Chris Morgan Dec 19 '11 at 11:16
  • hmmm.. excanvas eh? yeah ill give that a shot. – Ashwin Krishnamurthy Dec 19 '11 at 11:21
2

PDF is generally a subset of PostScript + options for embedding flash, JavaScript and all sorts of other things.

Translating PDF trivially to HTML (/DOM), and have it render in a correct-ish manner is all but impossible. As an example, PDF uses JPEG images, but with subtle changes here and there, which means you have to convert them before use anywhere else. Try reading some presentations from the PDF.js-guys, and you'll find quite a long list of WTFs.

However, if you only have simple PDF's (plain text; no images, etc.) and don't care about preserving anything but the simplest of layout, you should be able to scrape out string data from the PDF's and put it into the DOM.

Personally, however, I believe that it would be simpler either to force users to have a plugin (flash/acrobat/...), or render the PDF's server-side and serve them as images to the browser.

Morten Siebuhr
  • 6,068
  • 4
  • 31
  • 43