【问题标题】:How to open multiple pdf filesusing pdf plumber in Python?如何在 Python 中使用 pdfplumber 打开多个 pdf 文件?
【发布时间】:2020-06-25 07:23:59
【问题描述】:

我有一个装满 pdf 文件的文件夹。我需要根据给定的条件遍历每个 pdf 文件。使用熊猫是不可能的。有没有什么方法可以使用 pdfplumber 遍历每个文件?

import os
import glob
import shutil
import pandas as pd
import plotly.express as px
import xlrd
import matplotlib.pyplot as plt
%matplotlib inline
import time
from datetime import datetime
from pytz import timezone
import numpy as np
from tabula import read_pdf
import tabula
import requests
import pdfplumber
from tabula import read_pdf

glob.glob("C:/Users/Dreamer/Desktop/test_run/machine/*.pdf")



#THIS IS THE CONDITION I WANT TO IMPLEMENT IN EACH FILE

with pdfplumber.open(path) as pdf:
    page = pdf.pages[0]
    text = page.extract_text()

for row in text.split('\n'):
    if row.startswith('Raumtemperatur '):
        jobstart = row.split()[-2]
        jobend   = row.split()[-1]
print("jobstart", jobstart) 
print("jobstart", jobend)

期待解决方案或替代方案:)

【问题讨论】:

  • 通过遍历 glob 到 with 块的路径来传递 pdf_path?
  • 是的,对该文件夹中的每个 pdf 文件使用“with”块逻辑 :)

标签: python excel pdf


【解决方案1】:

IIUC,

import glob
from tqdm.auto import tqdm
for current_pdf_file in tqdm(glob.glob("C:/Users/Dreamer/Desktop/test_run/machine/*.pdf")):
    with pdfplumber.open(current_pdf_file) as my_pdf:
         # do other things here?

【讨论】:

    猜你喜欢
    • 2020-10-03
    • 2013-04-24
    • 1970-01-01
    • 1970-01-01
    • 2011-06-04
    • 2023-01-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多