Pdf.js: How to get the selected text from pdfjs ?

Created on 30 Apr 2013  路  6Comments  路  Source: mozilla/pdf.js

I have using the PDFJS rightnow
i want to get the selected text from the PDFJS viewer and pass the text element to the HTML page(may be is one hidden element)
i try to use the javascript on the web, but these can not select the text from the viewer
What can i do for this?

Most helpful comment

@yurydelendik Nothing more than to explain in a it more educational manner for people like me who are web-noobs.

All 6 comments

@macarlos2005: first, could you please change the issue title to lowercase? Much nicer to read that way :)

Secondly, it is not entirely clear to me what you want exactly. Do you mean that you cannot select text in the viewer? If so, could you post a PDF file that causes selection problems?

The PDF.js viewer creates text layer, which is a hidden HTML DIV element. You can take this element and pass it to the HTML page. The text layer might not be present for scanned image. Closing as answered and out of scope.

If you render each page in the pdf with separate div and some css you will then be able to select the text directly in the browser. It is then easy tou use ordinary javascript to get the selected text.
This article explain rendering. Custom PDF Rendering in JavaScript with Mozilla鈥檚 PDF.Js

If you render each page in the pdf with separate div and some css you will then be able to select the text directly in the browser.

@petterivarsson how it's different from what demo viewer is doing? (or examples at examples/components)?

@yurydelendik Nothing more than to explain in a it more educational manner for people like me who are web-noobs.

We need more low-level API usage examples in order to make creative use cases. I like the recommended article.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hp011235 picture hp011235  路  4Comments

anggikolo11 picture anggikolo11  路  3Comments

liuzhen2008 picture liuzhen2008  路  4Comments

SehyunPark picture SehyunPark  路  3Comments

kleins05 picture kleins05  路  3Comments