webodf / ViewerJS

ViewerJS: Document Reader in JavaScript
http://viewerjs.org
1.94k stars 421 forks source link

Add class for every div in .textLayer for every page #255

Closed Avartil closed 6 years ago

Avartil commented 6 years ago

Hello, I'm looking for a way to do one of this things:

add a unique ID for every div in text layer.

<div style="left=...., top=...," id="page1div1"> text </div>

or add a class for all pages to all divs in text layer

<div style="left=...., top=...," id="div1" class="page1"> text </div>

I'm using current PDF.js and viewer.html / viewer.js

I was able to add this inside of: function appendText(task, geom, styles) (inside pdf.js)

for (var i = 0; i < task._textDivs.length; i++) {
    textDiv.setAttribute('id', 'd'+i);
}

It works, but only for 1-page pdfs. If pdf have more that 1 page, first div on first page gonna have the same ID as first div on secound page etc.

I get:

<div style="left=...., top=...," id="div1"> text </div> <div style="left=...., top=...," id="div1"> text </div> etc...

I would like to know how to do that. Can you help me?