Remove Highlight from PDF using C#

This short guide explains how to remove highlight from PDF using C#. It has details to set the IDE, a list of steps, and a sample code showing how to delete highlights in PDF using C#. Different options are demonstrated to erase a particular highlight or all highlights from a given PDF.

Steps to Remove Highlight on PDF using C#

  1. Set the IDE to use Aspose.PDF for .NET to remove highlights
  2. Create an enumerator for the selection of all or a selected color highlight removal
  3. Create a function that takes an input/output PDF, a flag to remove all or selected highlights, and a target color
  4. Open the source PDF file having highlighted text in it using the Document class
  5. Parse each page and filter highlights from the annotation collection of each page
  6. Parse through all the highlights and delete them based on the user-selected criteria
  7. Save the output PDF file after removing the highlights

These steps summarize how to erase highlight in PDF using C#. Load the source PDF file, access each page, and its respective annotations collection. Parse each highlight annotation, type cast it to HighlightAnnotation to access its colors when required, and finally delete the highlight annotation as per the given criteria.

Code to Remove PDF Highlight using C#

This code demonstrates how to remove PDF highlight using C#. If you simply want to remove all the highlights irrespective of the color, you don’t need to cast the highlight type annotation to HighlightAnnotation. You may overwrite the existing PDF file or create a new PDF file as per your requirements.

This article has taught us the process to remove highlights from a PDF. To convert a PS file to a PDF, refer to the article Convert a PS File to PDF using C#.