XDoc.PDF
Features
Tech Specs
How-to C#
How-to VB.NET
Pricing
C# PDF: How to PDF Create PDF Export File and Page Process PDF Read PDF Write Form Process Document Protect Annotation & Drawing PDF Print WPF Viewer & Editor Work with Other SDKs Barcode Read Barcode Create OCR Twain
Highlight text
  |  
Home ›› XDoc.PDF ›› C# PDF: Highlight Text

C#.NET PDF SDK - Highlight PDF Text in C#.NET


Sample Codes for C#.NET Users to Highlight Selected PDF Text on PDF Page in C#.NET Class




Best PDF document reader SDK control that can highlight PDF text in Visual C# .NET framework application


A professional annotation application able to highlight PDF file in C#.NET WinForm project without adobe reader components


Support .NET WinForms, ASP.NET MVC in IIS, ASP.NET Ajax, Azure cloud service, DNN (DotNetNuke), SharePoint


An ASP.NET web-server compliant library able to highlight text in PDF file online in browser such as chrome, firefox, safari, etc


Able to remove highlighted text in PDF document in C#.NET


Support to change PDF highlight color in Visual C# .NET class


Able to save highlighted content to original PDF document


Various C# source codes provides multiple ways to highlight PDF text in .NET


Users will often face the situation that you may need to emphasize the most important information from all text on a PDF page. Highlight text is such a functionality which allow users to give prominence to key words or sentences. RasterEdge XDoc.PDF SDK is a multifunctional PDF document annotation tool, which can highlight text with a simple piece of C# programming demo code.


Since RasterEdge XDoc.PDF SDK is based on .NET framework 2.0, users are enabled to use it in any type of a 32-bit or 64-bit .NET application, including ASP.NET web service and Windows Forms for any .NET Framework version from 2.0 to 4.5.





C# add highlight text annotation to pdf document


Note: When you get the error "Could not load file or assembly 'RasterEdge.Imaging.Basic' or any other assembly or one of its dependencies. An attempt to load a program with an incorrect format", please check your configure as follows:

       

       If you are using x64 libraries/dlls, Right click the project -> Properties -> Build -> Platform target: x64.

       

       If using x86, the platform target should be x86.




String inputFilePath = Program.RootPath + "\\" + "2.pdf";
String outputFilePath = Program.RootPath + "\\" + "Annot_3.pdf";

//  open a PDF file
PDFDocument doc = new PDFDocument(inputFilePath);
//  get the 2nd page
PDFPage page = (PDFPage)doc.GetPage(1);

//  create the annotation
PDFAnnotHighlight annot = new PDFAnnotHighlight();

annot.StartPoint = new PointF(100F, 200F);
annot.EndPoint = new PointF(300F, 400F);

//  add annotation to the page
page.AddPDFAnnot(annot);

//  save to a new file
doc.Save(outputFilePath);




C# read highlight text annotation from pdf document





String inputFilePath = Program.RootPath + "\\" + "Annot_3.pdf";

PDFDocument doc = new PDFDocument(inputFilePath);
List<IPDFAnnot> annots = PDFAnnotHandler.GetAllAnnotations(doc);
foreach (IPDFAnnot annot in annots)
{
    if (annot is PDFAnnotHighlight)
    {
        PDFAnnotHighlight obj = (PDFAnnotHighlight)annot;
        Console.WriteLine("Color: " + obj.Color.ToString());
        Console.WriteLine("Line Boundaries: ");
        foreach (RectangleF line in obj.GetLineBoundaries())
        {
            Console.WriteLine("  " + line.ToString());
        }
    }
}




C# delete all annotations from pdf document





String inputFilePath = Program.RootPath + "\\" + "1_Annots.pdf";

PDFDocument doc = new PDFDocument(inputFilePath);
//  get all annotations in the 1st page
PDFPage page = (PDFPage)doc.GetPage(0);
List<IPDFAnnot> annots = PDFAnnotHandler.GetAllAnnotations(page);
//  remove all annotations in the 1st page
PDFAnnotHandler.DeleteAnnotation(doc, annots);




.NET Class Namespace Required



Add necessary references:


  RasterEdge.Imaging.Basic.dll


  RasterEdge.Imaging.Basic.Codec.dll


  RasterEdge.Imaging.Drawing.dll


  RasterEdge.Imaging.Font.dll


  RasterEdge.Imaging.Processing.dll


  RasterEdge.XImage.Raster.dll


  RasterEdge.XImage.Raster.Core.dll


  RasterEdge.XDoc.PDF.dll


Use corresponding namespaces;


  using RasterEdge.Imaging.Basic;


  using RasterEdge.XDoc.PDF;





public void SearchTextAndHighlight(String matchString, RESearchOption option)

Description:
     Highlight specified string text that match the search option from PDF file.

Parameters:



public void SearchTextAndHighlight(String matchString, RESearchOption option, int pageIndex)

Description:
     Highlight specified string text that match the search option from specified PDF page.

Parameters:



public void SearchTextAndHighlight(String matchString, RESearchOption option, int pageOffset, int pageCount)

Description:
     Highlight specified string text that match the search option from specified PDF page.

Parameters: