Closed2
pypdfでAmazonのPDF領収書から請求金額を取得

PDFからご請求金額の取得
- Amazon.co.jpの領収書フォーマットは複数あるため、下記はその一部のみ対応
- フォルダ内のPDFから請求金額を抽出しprint出力
import os
import re
from pypdf import PdfReader
# 領収書が格納されているフォルダパスを指定
folder_path = r'xxxx'
# フォルダ内のPDFファイル名を取得
files = [f for f in os.listdir(folder_path) if f.endswith('.pdf')]
for file in files:
print(f"Processing file: {file}")
file_path = os.path.join(folder_path, file)
reader = PdfReader(os.path.join(folder_path, file))
read_text = ''
for page in reader.pages:
read_text += page.extract_text()
# パターンマッチで金額を取得
amount_match = re.search(r'ご請求額:¥(.*?)注文番号', read_text)
if amount_match:
amount = amount_match.group(1)
print(amount)
print("Finished processing all files.")
このスクラップは2024/03/24にクローズされました