Javascript based horizontal Scrolling of a multi-page PDF?

1.3k views Asked by At

I'm wondering how I can accomplish horizontal scrolling of the pages of a PDF using JavaScript. Is it better to:

  1. Convert the pages of the PDF into HTML files and then click left-right between iframes where src="...each page.html"?
  2. Convert the pages of the PDF into some other HTML element besides iframe (e.g., DIV?) and then click left-right between elements containing the contents of each page.

I'd like to ensure that the PDF's text is searchable so I don't want to make its pages into images. I'm also skeptical of using iframes because of the formatting challenges of having multiple iframes in a single webpage. I've already tested this approach after converting the PDF to HTML using "PDFtoHTML" linux-based software and find that in general this is a suboptimal solution.

It seems like option 2 is the way to go but wouldn't know how to programmatically parse a PDF into multiple DIVs. Besides JavaScript, I'm familiar with PHP and Linux but not other languages if that would be helpful in thinking of solutions.

2

There are 2 answers

0
Joshua On

PDF plugin intercepts mouse events so there is no way to control it directly from the browser / JavaScript.

Your other method, converting to html, is feasible.

1
millimoose On

Converting a PDF page to a HTML file is more or less the exact same thing as "parsing it into a <div>". If you already found a tool that can do it for you ("PDFtoHTML"), just use that, and strip away everything except what's inside the <body> of the .html it outputs.