如何在 C# 中搜索 pdf 中的文本(執行匹配) (How to search text (Exect match) in pdf in C#)


問題描述

如何在 C# 中搜索 pdf 中的文本(執行匹配) (How to search text (Exect match) in pdf in C#)

I am stucking in my application. I want to search text (Exact match) and there location and highlight the text in pdf through axacropdf control in c#. How can I do this. I have googled many topics but no helps. How can I achieve this target. Have you have any code or dll for this. Pls bring me some code. 

Thanks

‑‑‑‑‑

參考解法

方法 1:

using Bytescout.PDFExtractor;

       try
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                FileName = openFileDialog1.FileName;

                string FName = FileName;
                int a = FileName.LastIndexOf('\\');
                txtFileName.Text = FileName.Substring(a + 1);

                axAcroPDF1.LoadFile(FileName);

                FileInfo fi = new FileInfo(FileName);
                string PDFFileName = fi.Name.ToString();
                double filesize = (fi.Length / 1024F / 1024F);
                string size = filesize.ToString("0.00 MB");
                string CreationDate = fi.CreationTime.ToString();
                string LastAccessDate = fi.LastAccessTime.ToString();
                string ModifiedDate = fi.LastWriteTime.ToString();

                lblVersion.Text = "File Name         : " + PDFFileName + "\nSize                  : " + size + "\nCreation Date   : " + CreationDate + "\nModified Date   : " + ModifiedDate;

                TextExtractor extractor = new TextExtractor();
                extractor.RegistrationName = "Demo";
                extractor.RegistrationKey = "Demo";
                extractor.LoadDocumentFromFile(FileName);

                int pageCount = extractor.GetPageCount();

                RectangleF location;

                for (int s = 0; s <= Keywords.Length ‑ 1; s++)
                {



                    if (Keywords[s] != "")
                    {
                        TreeNode tNode = new TreeNode();

                        tNode = treeView1.Nodes.Add(Keywords[s]);


                        for (int i = 0; i < pageCount; i++)
                        {
                            if (extractor.Find(i, Keywords[s], false, out location))
                            {
                                do
                                {
                                    int j = i;
                                    tNode.Nodes.Add((j+1).ToString() + "     " + location.ToString());

                                    float X = location.X;
                                    float Y = location.Y;
                                    float Width = location.Width;  
                                    float Height = location.Height;




                                    float Left = location.Left;
                                    float Right = location.Right;
                                    float Top = location.Top;
                                    float Bottom = location.Bottom;


                                    //axAcroPDF1.setCurrentHighlight(Convert.ToInt32(X), Convert.ToInt32(Y), Convert.ToInt32(Width), Convert.ToInt32(Height));



                                }
                                while (extractor.FindNext(out location));
                            }
                        }
                    }
                    else
                    {

                    }
                }      
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message.ToString(), "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }

(by Dinesh KumarDinesh Kumar)

參考文件

  1. How to search text (Exect match) in pdf in C# (CC BY‑SA 3.0/4.0)

#.net-3.5 #adobe-reader #axacropdf #visual-studio-2008 #C#






相關問題

如何在 C# 中搜索 pdf 中的文本(執行匹配) (How to search text (Exect match) in pdf in C#)

String.IsNullOrEmpty() (String.IsNullOrEmpty())

是否有可以綁定的可為空的日期選擇器? (Is there a nullable datepicker that I can bind to?)

具有自動命名屬性的通用組合框 (Generic ComboBox with automatically named properties)

在數據庫未定義的外鍵關係上配置實體框架 (Configuring Entity Framework on a Database Undefined Foreign Key Relationships)

我可以在 4.0 應用程序中引用 .NET 3.5 .DLL 嗎? (Can I reference a .NET 3.5 .DLL in a 4.0 app?)

如何在 ASP.NET、VB.NET 中解決這個會話問題? (How to tackle this session problem in ASP.NET,VB.NET?)

在 ADO.NET 數據服務中添加對查找表的引用 (Adding a reference to a lookup table in ADO.NET Data Services)

如何優化 Linq to Xml 查詢反對屬性? (How do I optimize a Linq to Xml query againist attributes?)

VS2005 和 LINQ (VS2005 and LINQ)

時區信息錯誤? (TimeZoneInfo error?)

與標準 C++ 相比,C++/CLI(以前稱為“託管 C++”)有哪些優勢? (What are the advantages of C++/CLI (formerly "Managed C++") over standard C++?)







留言討論