C # How to highlight text in different colors in PDF,

Source: Internet
Author: User

C # How to highlight text in different colors in PDF,

Highlighted text helps readers quickly and effectively obtain key information of articles. In a PDF file, different texts, keywords, sentences, and other texts in different colors are highlighted, so that readers can effectively distinguish the meanings of different highlighted texts during reading. In the following example, I use Free Spire. PDF for. NET for operations (https://www.e-iceblue.cn/Downloads/Free-Spire-Doc-NET.html), you can refer to the following steps:

The original file is as follows:

Step 1: Initialize and loadPDFDocument instance

PdfDocument pdf = new PdfDocument(@"C:\Users\Administrator\Desktop\C#.pdf");

Step 2: Call FindText () to find the specified text "C #"

PdfTextFind[] result1 = null;result1 = pdf.Pages[0].FindText("C#").Finds;

Step 3. traverse all search results and highlight the text in blue"C #"

foreach (PdfTextFind find in result1) {       find.ApplyHighLight(Color.Blue); }

Step 4: Call FindText () to find the specified text "Microsoft"

Optional textfind [] result2 = null; result2 = pdf. Pages [0]. FindText ("Microsoft"). Finds;

Step 5: traverse all search results and highlight the text in purple"Microsoft"

foreach (PdfTextFind find in result2){    find.ApplyHighLight(Color.Purple)}

Step 6: Save the document

pdf.SaveToFile("result.pdf", FileFormat.PDF);

After completing the preceding operations, Debug and run the project and generate a document (which can be viewed in the bin> Debug folder of the project), as shown in:

The above is a simple operation on C # text search and highlighting in PDF. I hope it will help you. Thank you for reading!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.