How C # Highlights text in a PDF in a different color

Source: Internet
Author: User

The highlighted text helps the reader quickly and efficiently get the critical information of the article. In the PDF file, the text highlighting of different text, keywords, sentences and so on, can make the reader effectively distinguish the meaning of different highlighted color text in the process of reading. In the following example, I use free spire.pdf for. NET to operate (https://www.e-iceblue.cn/Downloads/Free-Spire-Doc-NET.html), you can refer to the following steps:

The original file is as follows:

650) this.width=650; "src=" Https://s5.51cto.com/oss/201710/19/54e9f6e420d1ec21acaa6e975e768aae.png "title=" 1.png " alt= "54e9f6e420d1ec21acaa6e975e768aae.png"/>

Step One: Initialize and load a PDF Document Instance

Pdfdocument PDF = newpdfdocument (@ "c:\users\administrator\desktop\c#.pdf");

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

pdftextfind[] Result1 = null;result1= PDF. Pages[0]. FindText ("C #"). Finds;

step three; iterate through all the search results, highlighting the text in blue " C # "

foreach (Pdftextfind Find in Result1) {find. Applyhighlight (Color.Blue); }

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

pdftextfind[] result2 = null;result2= PDF. Pages[0]. FindText ("Microsoft"). Finds;

Step Five: Iterate through all search results, highlighting the text in purple " Microsoft "

foreach (Pdftextfind Find in result2) {find. Applyhighlight (Color.purple)}

Step Six: Save the document

Pdf. SaveToFile ("Result.pdf", fileformat.pdf);

When you are done, debug and run the project, generating the document (viewable in folder Bin>debug in the project) such as:

650) this.width=650; "src=" Https://s5.51cto.com/oss/201710/19/660f41d0013035cc7f13359f2fb7c6f3.png "title=" 1.png " alt= "660f41d0013035cc7f13359f2fb7c6f3.png"/>


the above is about C # in the PDF Chinese text Search and highlight the operation, I hope you have some help, thank you for reading!

This article is from the "Mochou" blog, make sure to keep this source http://miayo.blog.51cto.com/13270370/1974269

How C # Highlights text in a PDF in a different color

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.