how to highlight a text or word in a pdf file using iTextsharp?

前端 未结 5 1747
陌清茗
陌清茗 2020-11-28 13:13

I need to search a word in a existing pdf file and i want to highlight the text or word

and save the pdf file

I have an idea using PdfAnnotation.CreateMarku

5条回答
  •  甜味超标
    2020-11-28 13:48

    I've found how to do this, just in case someone needs to get words or sentences with locations (coordinates) from a PDF document you'll find this example Project HERE , I used VB.NET 2010 for this. Remember to add a reference to your iTextSharp DLL in this Project.

    I added my own TextExtraction Strategy Class, based on Class LocationTextExtractionStrategy. I focused on TextChunks, because they already have these coordinates.

    There are some known limitations like:

    • No multiple line searches (phrases), just char/s or word's or a one line sentence are allowed.
    • It Won't work with rotated text.
    • I didn't test on PDFs with landscape page orientation but i assume some modifications may be required for this.
    • In case you need to draw this HighLight/rectangles over a watermark you'll need to add/modify some code, but just code in the Form, this is not related to the text/locations extraction proccess.

提交回复
热议问题