ค้นหา PDF ผ่าน Python

การค้นหาเอกสาร PDF ขั้นสูงใช้ Aspose.PDF สำหรับ Python for .NET เพื่อแก้ไขเอกสาร PDF แบบโปรแกรม

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

หากต้องการค้นหาไฟล์ PDF เราจะใช้ Aspose.PDF for Python via .NET ซึ่งเป็น API ที่มีประสิทธิภาพและใช้งานง่าย เปิด PyPI ติดตั้ง และค้นหา aspose-pdf หรือเรียกใช้คำสั่งต่อไปนี้:

Console

pip install aspose-pdf

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


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

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

ค้นหาไฟล์ PDF - Python

import aspose.pdf as apdf

from os import path
path_infile = path.join(self.data_dir, infile)

document = apdf.Document(path_infile)

# Create TextAbsorber object to find all instances of the input search phrase
textFragmentAbsorber = apdf.text.TextFragmentAbsorber("PDF")

# Accept the absorber for all the pages
document.pages.accept(textFragmentAbsorber)

# Loop through the fragments
for textFragment in textFragmentAbsorber.text_fragments:
    print(f"Text : {textFragment.text}" )
    print(f"Position : {textFragment.position}")
    print(f"XIndent : {textFragment.position.x_indent}")
    print(f"YIndent : {textFragment.position.y_indent}")
    print(f"Font - Name : {textFragment.text_state.font.font_name}" )
    print(f"Font - IsAccessible : {textFragment.text_state.font.is_accessible} " )
    print(f"Font - IsEmbedded : {textFragment.text_state.font.is_embedded} " )
    print(f"Font - IsSubset : {textFragment.text_state.font.is_subset} ")
    print(f"Font Size : {textFragment.text_state.font_size}" )
    print(f"Foreground Color : {textFragment.text_state.foreground_color} " )