0

I'd like to show a pdf file online and provide a translations when words are clicked in pdf. Pdf is coming from user and doesn't have any markup from me. If a translated pdf is available I'd like to show fragments of the translation pdf when sentences/words in original pdf are clicked. If translation is not in a pdf file, I'd show it just as a text overlay. Which possibilities do I have?
I can imagine following solutions:

  1. no modification to original pdf, on click on sentence an overlay appears. Probably not possible with Adobe Pdf Reader, is there any server-side reader available, where I can do such operations (handle clicks, get clicked text, sdd overlay)?
  2. convert pdf to html - which converter can I use on server side? (PHP preferred)
  3. create a custom pdf reader for browser - too complicated
  4. ??

any suggestions?

jeff
  • 1,169
  • 1
  • 19
  • 44

1 Answers1

1

I would consider the following scenarios:

  1. Use PDF.js to display PDF in browser (it works pretty well, for example, DropBox already uses it to show PDF previews). And adjust its Viewer HTML and javascript code to handle text selections (see this example). Disadvantage: it may not work well on mobile devices.
  2. Convert PDF to HTML representation using one of mature pdf to html converters (commercial or non-commercial) with server-side code. And then just work with it as it were HTML code.
  3. Convert PDF into images (single image per single page) with server-side code. Then parse PDF to find position of every text object and generate HTML code to use the rendered image and finally generate HTML code where rendered image as at the bottom layer and the top layer contains text elements which are handled by your javascript code to display translations etc.
Eugene
  • 2,820
  • 19
  • 24