Disable text selection when rendering PDF to HTML
Leave feedback
When rendering PDF documents to HTML with GroupDocs.Viewer you can disable text selection by rendering text as an image. When rendering text as an image the output HTML will look close to the source PDF document. To disable text selection set viewOptions.getPdfOptions().setRenderTextAsImage(true).
Example
To let’s take one-page-text.pdf, convert it to HTML with default options and check output HTML document source. To convert PDF to HTML we’ll be running the following code:
As a result, Viewer will produce a single HTML document default-options.html. If we open this document in a browser we’ll be able to select the text as is shown on the screenshot below:
As you can see we can select the text because it is actually a text inside span element.
Let’s now run the following code and check the output, the differences here are the new line viewOptions.getPdfOptions().setRenderTextAsImage(true) and output file name text-as-images.html:
We’ll get text-as-images.html on the output that will look similar to the previous result, but as you can see the text is replaced with an image that makes it impossible to select the text and copy it.
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.