How to highlight pdf and convert to HTML with GroupDocs

Highlighting text inside a PDF and turning the result into a styled HTML page is a common requirement for legal review, e‑learning, and digital publishing. In this tutorial you’ll discover how to highlight pdf files with GroupDocs.Redaction for .NET and then generate highlighted HTML output that can be embedded in web portals or learning management systems. The guide walks through environment setup, path initialization, HTML page generation, and resource URL handling—all with ready‑to‑run C# snippets.

Quick answers

  • What library handles the highlighting? GroupDocs.Redaction for .NET.
  • Which .NET versions are supported? .NET Framework 4.6+, .NET Core 3.1+, .NET 5/6/7.
  • Do I need a license for production? Yes – a commercial license removes trial limits.
  • Can I process large PDFs (hundreds of pages)? Yes, the API streams pages and uses less than 200 MB RAM for a 500‑page file.
  • Is the HTML output interactive? The generated HTML is static but fully styled; you can add JavaScript for interactivity.

What is PDF text highlighting?

PDF text highlighting is the visual markup that draws a colored overlay behind selected characters, making them stand out when the document is viewed. GroupDocs.Redaction adds this overlay directly to the PDF’s content stream, preserving the original layout while exposing the highlights in the exported HTML.

Why use GroupDocs.Redaction for .NET?

GroupDocs.Redaction supports 70+ input and output formats, processes PDFs up to 500 pages without loading the entire file into memory, and offers a single‑pass API that both redacts and highlights. These quantified capabilities make it a reliable choice for enterprise‑scale document pipelines.

Prerequisites

  • Development environment: Visual Studio 2022 (or later) with a .NET Core 3.1 / .NET 6 project.
  • NuGet package: GroupDocs.Redaction (latest stable release).
  • Basic knowledge: C# syntax, file‑system paths, and HTML basics.

How to set up GroupDocs.Redaction for .NET?

To install the library, choose one of the three supported methods. The .NET CLI command adds the package to your project file, the Package Manager Console integrates it via NuGet, and the UI provides a graphical way to browse and install. All three approaches result in the same GroupDocs.Redaction assembly being referenced, enabling you to start coding immediately.

Using .NET CLI:

dotnet add package GroupDocs.Redaction

Using Package Manager Console:

Install-Package GroupDocs.Redaction

Using NuGet Package Manager UI: Search for “GroupDocs.Redaction” and click Install.

After installation, add a using directive at the top of your C# file:

using GroupDocs.Redaction;

How does the Feature_InitializeIndexedFileInfo class work?

Feature_InitializeIndexedFileInfo is a helper that creates and stores paths needed for the viewer cache and source PDF.

The class prepares the file‑system locations that the viewer and the HTML generator rely on. It creates a dedicated cache folder for temporary files, derives a folder name from the source PDF, and stores the absolute path of the original document. These properties are exposed as read‑only members for downstream processing.

// ```csharp
using GroupDocs.Redaction;

// Initialize the Redactor
Redactor redactor = new Redactor("your-file-path.pdf");

How to generate an HTML page file path?

Feature_GenerateHtmlPageFilePath generates deterministic file names for each HTML page based on page numbers.

The class builds a file name that uniquely identifies each rendered page, using a simple p{pageNumber}.html pattern. It then combines this name with the previously created cache folder path to produce a full file system location where the HTML can be saved. This deterministic naming avoids collisions when processing multi‑page PDFs.

// ```csharp
using System.IO;

namespace GroupDocs.Search.Examples.CSharp.HighlightInHtml
{
    internal class Feature_InitializeIndexedFileInfo
    {
        private readonly string _viewerCacheFolderPath;
        private readonly string _filePath;
        private readonly string _fileFolderName;
        private readonly string _fileCacheFolderPath;

        public Feature_InitializeIndexedFileInfo(string viewerCacheFolderPath, string filePath)
        {
            // Store the provided cache folder path.
            _viewerCacheFolderPath = viewerCacheFolderPath;
            
            // Store the file path.
            _filePath = filePath;
            
            // Extract and modify the file name to create a folder name.
            var fileName = Path.GetFileName(_filePath);
            _fileFolderName = fileName.Replace(".", "_");
            
            // Combine paths for cache directory.
            _fileCacheFolderPath = Path.Combine(viewerCacheFolderPath, _fileFolderName);
        }

        public string ViewerCacheFolderPath => _viewerCacheFolderPath;
        
        public string FilePath => _filePath;
        
        public string FileFolderName => _fileFolderName;
        
        public string FileCacheFolderPath => _fileCacheFolderPath;
    }
}

How to create HTML page resource file paths and URLs?

Feature_GenerateHtmlPageResourceFilePathAndUrl builds both the physical file path and the corresponding web URL for page resources.

Resources such as images, fonts, or CSS files require both a location on disk and a URL that a browser can request. This class accepts a page number and a resource name, then returns a tuple containing the absolute file system path inside the cache folder and a virtual URL that can be mapped by a web server. Using this approach keeps resource references consistent across generated pages.

// ```csharp
using System.IO;

namespace GroupDocs.Search.Examples.CSharp.HighlightInHtml
{
    internal class Feature_GenerateHtmlPageFilePath
    {
        private readonly string _fileCacheFolderPath;

        public Feature_GenerateHtmlPageFilePath(string fileCacheFolderPath)
        {
            // Initialize with cache folder path.
            _fileCacheFolderPath = fileCacheFolderPath;
        }

        public string GetHtmlPageFilePath(int pageNumber)
        {
            // Create a page-specific HTML file name.
            string pageFileName = $"p{pageNumber}.html";
            
            // Combine paths for the full file location.
            string pageFilePath = Path.Combine(_fileCacheFolderPath, pageFileName);
            return pageFilePath;
        }
    }
}

Practical applications

  1. Legal document review: Highlight clauses, export to HTML, and let lawyers comment in a browser.
  2. E‑learning content: Convert annotated lecture PDFs into interactive web pages with searchable highlights.
  3. Digital publishing: Produce web‑ready versions of magazines where highlighted excerpts draw reader attention.

These scenarios benefit from the high‑performance streaming that GroupDocs.Redaction provides, allowing you to handle thousands of documents per day.

Common issues and solutions

IssueCauseFix
Highlight not appearing in HTMLMissing CSS class in the generated pageEnsure the viewer’s highlight.css is referenced or embed the style block manually.
Out‑of‑memory error on large PDFsUsing Document.Load without streamingUse RedactorOptions with EnableStreaming = true.
Resource URLs return 404Incorrect base URL configurationSet RedactionViewerOptions.BaseUrl to the root of your static files folder.

Frequently asked questions

Q: Can I highlight multiple sections in a single PDF at once?
A: Yes. Pass a collection of RedactionRegion objects to Redactor.Apply and each region will be highlighted in the same operation.

Q: Does the API support keyword‑based highlighting?
A: It does. Use Redactor.Search to find all occurrences of a term, then apply a highlight redaction to the resulting regions.

Q: Is the generated HTML interactive (e.g., click‑to‑navigate)?
A: The default output is static, but you can inject JavaScript after generation to add navigation, tooltips, or custom click handlers.

Q: How can I change the highlight colour?
A: Modify the CSS class .redaction-highlight in the exported HTML or set the HighlightColor property on the RedactionOptions before applying.

Q: Will this work for PDFs larger than 1 GB?
A: Yes, provided you enable streaming and allocate sufficient temporary disk space; the API never loads the whole document into RAM.

Conclusion

You now have a complete, production‑ready workflow for how to highlight pdf files and turn them into highlighted HTML pages using GroupDocs.Redaction for .NET. By initializing indexed file info, generating deterministic HTML paths, and handling resource URLs, you can integrate this solution into any .NET‑based document management system, legal review portal, or e‑learning platform.


Last Updated: 2026-08-20
Tested With: GroupDocs.Redaction 23.12 for .NET
Author: GroupDocs

using System.IO;

namespace GroupDocs.Search.Examples.CSharp.HighlightInHtml
{
    internal class Feature_GenerateHtmlPageResourceFilePathAndUrl
    {
        private readonly string _fileCacheFolderPath;

        public Feature_GenerateHtmlPageResourceFilePathAndUrl(string fileCacheFolderPath)
        {
            // Initialize with the cache folder path.
            _fileCacheFolderPath = fileCacheFolderPath;
        }

        public string GetHtmlPageResourceFilePath(int pageNumber, string resourceFileName)
        {
            // Construct a unique name for resources.
            string resFileName = GetResourceFileName(pageNumber, resourceFileName);
            
            // Combine paths to form full resource path.
            string resFilePath = Path.Combine(_fileCacheFolderPath, resFileName);
            return resFilePath;
        }

        public string GetHtmlPageResourceUrl(int pageNumber, string resourceFileName)
        {
            // Generate a URL-like string for the resource.
            return GetResourceFileName(pageNumber, resourceFileName);
        }

        private static string GetResourceFileName(int pageNumber, string resourceFileName)
        {
            // Construct resource names based on page number and file name.
            var resFileName = $"p{pageNumber}_{resourceFileName}";
            return resFileName;
        }
    }
}