ค้นหาไฟล์ PDF ใน C#

การค้นหาเอกสาร PDF แบบดั้งเดิมและมีประสิทธิภาพสูงโดยใช้ Aspose.PDF ฝั่งเซิร์ฟเวอร์สำหรับ C# API โดยไม่ต้องใช้ซอฟต์แวร์ใด ๆ เช่น Microsoft หรือ Adobe PDF

วิธีการค้นหาไฟล์ PDF โดยใช้ C#

เพื่อที่จะค้นหาไฟล์ PDF เราจะใช้ Aspose.PDF for .NET API ซึ่งเป็นคุณลักษณะที่อุดมไปด้วยที่มีประสิทธิภาพและง่ายต่อการใช้ API การจัดการเอกสารสำหรับ net แพลตฟอร์มเปิดตัวจัดการแพคเกจ NuGet ค้นหาaspose.pdf และติดตั้งนอกจากนี้คุณยังอาจใช้คำสั่งต่อไปนี้จากคอนโซลการจัดการแพคเกจ

Package Manager Console

PM > Install-Package Aspose.PDF

ค้นหาไฟล์ PDF ผ่าน C#


คุณจำเป็นต้อง Aspose.PDF for .NET ที่จะลองรหัสในสภาพแวดล้อมของคุณ

1.โหลดไฟล์ PDF ที่มีอินสแตนซ์ของเอกสาร 1.สร้างวัตถุ TextFragmenTabSorber กับข้อความที่จะหาเป็นพารามิเตอร์ 1.รับทุกคอลเลกชันชิ้นส่วนข้อความที่แยกออกมา 1.ห่วงผ่านแต่ละส่วนจะได้รับข้อมูลทั้งหมดของ

ค้นหาไฟล์ PDF - C#


//Search Text from All the Pages of PDF Document
Document pdfDocument = new Document("SearchAndGetTextFromAll.pdf");

// Create TextAbsorber object to find all instances of the input search phrase
TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber("text");

// Accept the absorber for all the pages
pdfDocument.Pages.Accept(textFragmentAbsorber);

// Get the extracted text fragments
TextFragmentCollection textFragmentCollection = textFragmentAbsorber.TextFragments;

// Loop through the fragments
foreach (TextFragment textFragment in textFragmentCollection)
{

    Console.WriteLine("Text : {0} ", textFragment.Text);
    Console.WriteLine("Position : {0} ", textFragment.Position);
    Console.WriteLine("XIndent : {0} ", textFragment.Position.XIndent);
    Console.WriteLine("YIndent : {0} ", textFragment.Position.YIndent);
    Console.WriteLine("Font - Name : {0}", textFragment.TextState.Font.FontName);
    Console.WriteLine("Font - IsAccessible : {0} ", textFragment.TextState.Font.IsAccessible);
    Console.WriteLine("Font - IsEmbedded : {0} ", textFragment.TextState.Font.IsEmbedded);
    Console.WriteLine("Font - IsSubset : {0} ", textFragment.TextState.Font.IsSubset);
    Console.WriteLine("Font Size : {0} ", textFragment.TextState.FontSize);
    Console.WriteLine("Foreground Color : {0} ", textFragment.TextState.ForegroundColor);
}