none
How to Search Comment from PDF in C#? RRS feed

  • Question

  • I am able to read the comments in PDF. Now i have to search that Comment.

    How can i do that?

    Wednesday, December 5, 2018 7:33 AM

All replies

  • .NET does not support reading/writing PDFs. To do that you have to use a third party library like iTextSharp. Questions related to third party libraries should be posted in their forums. This forum is only for C#-specific questions.

    Michael Taylor http://www.michaeltaylorp3.net

    Wednesday, December 5, 2018 3:11 PM
    Moderator
  • You'll need a PDF library to work with PDF files. I think you might be interested in this: https://www.e-iceblue.com/Tutorials/Spire.PDF/Spire.PDF-Program-Guide/Annotation/Modify-and-Format-Annotation-in-PDF-in-C-VB.NET.html
    Thursday, December 6, 2018 2:38 AM
  • Hi krunnu,

    Thank you for posting here.

    For your question, if you want to search that Comment in c#, please refer to this code below.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Atalasoft.Pdf;
    using Spire.Pdf;
    using Spire.PdfViewer;
    using iTextSharp.text.pdf;
    using iTextSharp.text.pdf.parser;
    using System.IO;
    using iTextSharp.text;
    using Spire.Pdf.General.Find;
    using org.apache.pdfbox.pdmodel;
    using org.apache.pdfbox.util;
    
    namespace test1
    {
        class Program
        {
            static void Main(string[] args)
            {
                
                Spire.Pdf.PdfDocument pdf = new Spire.Pdf.PdfDocument();
                pdf.LoadFromFile(@"C: \xxx.pdf");
    
                PdfTextFind[] AllMatchedText = null;
    
                foreach (PdfPageBase page in pdf.Pages)
                {
                    AllMatchedText = page.FindText("Hello").Finds;
                    foreach (var item in AllMatchedText)
                    {
    
                        Console.WriteLine(item.LineText);            
                    }
                }
                Console.ReadKey();
            }
        }
    }
    

    PDF:

    Result:

    Best regards,

    Jack J Jun.


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Friday, December 7, 2018 9:05 AM
    Moderator