Render text as image
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.PdfOptions.RenderTextAsImage = 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:
using (Viewer viewer = new Viewer("one-page-text.pdf"))
{
HtmlViewOptions viewOptions =
HtmlViewOptions.ForEmbeddedResources("default-options.html");
viewer.View(viewOptions);
}
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.PdfOptions.RenderTextAsImage = true
and output file name text-as-images.html
:
using (Viewer viewer = new Viewer("one-page-text.pdf"))
{
HtmlViewOptions viewOptions =
HtmlViewOptions.ForEmbeddedResources("text-as-images.html");
viewOptions.PdfOptions.RenderTextAsImage = true;
viewer.View(viewOptions);
}
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.