You must Sign In to post a response.
  • Category: ASP.NET

    How to highlight a selected text on pdf using asp.net & C#?

    Hi,
    In my application has lot of pdfs. if i have searched a text then the matched pdf file name should display with link to that pdf first matched page. if click on the link it opens the pdf page with highlight the searched text.

    How to highlight (background color change) a selected text on a PDF file using asp.net with C# code? if u have any idea share with me plz. since two days i am struggle with this.
  • #743763
    Hi,
    For searching a pdf file in a directory below link will help you,
    http://stackoverflow.com/questions/9830069/c-sharp-searching-for-file-in-directories-recursively
    http://www.codeproject.com/Questions/322056/search-files-in-directory-Csharp
    http://www.codeproject.com/Articles/35044/File-Searcher-in-C

    For searching a string inside a pdf file browse below links,
    http://stackoverflow.com/questions/567951/how-to-programatically-search-a-pdf-document-in-c-sharp
    http://www.dotnetspider.com/resources/5046-Search-String-PDF-File.aspx
    http://stackoverflow.com/questions/567951/how-to-programatically-search-a-pdf-document-in-c-sharp

    Cheers,
    Vignesh Kannan

  • #743801
    Hi,

    Are you using any third party tools for showing the PDF files/For searching?

    Highlighting text of existing PDF can be done using iTextsharp in C#

    you can refer to this example exactly giving the code what you are looking for but this is using iTextSharp

    http://stackoverflow.com/questions/6523243/how-to-highlight-a-text-or-word-in-a-pdf-file-using-itextsharp

  • #765771
    download c# pdf highlight existing fields and try this high quality software on rasteredge, get the free trail and vip service on page http://www.rasteredge.com/how-to/csharp-imaging/pdf-annotate-text-highlight/

  • #765796
    You can go through blow link:
    http://www.e-iceblue.com/Tutorials/Spire.PDF/Spire.PDF-Program-Guide/Text/Find-and-Highlight-Selected-Text-in-PDF-in-C-VB.NET.html
    Download the free version from codeplex and give it a try: http://freepdf.codeplex.com
    Sample code:

    PdfDocument pdf = new PdfDocument(@"E:\···\PDF.pdf");
    PdfTextFind[] result = null;
    foreach (PdfPageBase page in pdf.Pages)
    {
    result = page.FindText("text").Finds;
    foreach (PdfTextFind find in result)
    {
    find.ApplyHighLight();
    }
    }
    pdf.SaveToFile("result.pdf");

  • #765802
    So you have couple of task
    1. search a word in pdf
    2. Highlight that word in pdf file
    There is not API exist in .net to support PDF files, To accomplish first task you need to take support of some third party API like PDF sharp/ItextSharp
    here is the sample that will works for you

    using iTextSharp.text.pdf;
    using iTextSharp.text.pdf.parser;
    // ...
    public static string ExtractTextFromPdf(string path)
    {
    using (PdfReader reader = new PdfReader(path))
    {
    StringBuilder text = new StringBuilder();
    for (int i = 1; i <= reader.NumberOfPages; i++)
    {
    text.Append(PdfTextExtractor.GetTextFromPage(reader, i));
    }
    return text.ToString();
    }
    }

    You need to import iTextsharp dll for it, may be following link will help you more
    http://www.squarepdf.net/parsing-pdf-files-using-itextsharp

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #766014
    You can implement this using itextsharp as shown below:
    http://stackoverflow.com/questions/33952183/highlight-words-in-a-pdf-using-itextsharp-not-displaying-highlighted-word-in-br
    Also, I saw a similar feature implemented by leadtools in the following thread:
    http://support.leadtools.com/SupportPortal/CS/forums/24558/showpost.aspx#40944


  • Sign In to post your comments