Catalyst,Reduction temperature (8C),Hydrogen uptake (mmol/g),Pd dispersion (%)
2% Pd/ZnO,200,8 � 1,8.6
2% Pd/ZnO,300,8 � 2,8.6
2% Pd/ZnO,400,2.7 � 0.4,2.9
2% Pd/ZnO,500,3.1 � 0.4,3.3
6% Pd/ZnO,200,17 � 2,6.2
10% Pd/ZnO,200,25 � 4,5.4
2% Pd/CeO2,200,45 � 9,48
2% Pd/CeO2,400,36 � 5,38
2% Pd/CeO2,550,12 � 2,13
6% Pd/CeO2,200,98 � 18,34
10% Pd/CeO2,200,116 � 18,25
page_4.pdf

import re
import fitz # PyMuPDF
from gmft.auto import TableDetector, AutoTableFormatter
import pandas as pd
from gmft.pdf_bindings import PyPDFium2Document
def extract_pdf_content(pdf_path):
# 使用gmft提取表格
detector = TableDetector()
formatter = AutoTableFormatter()
# 读取PDF文件
doc_tables = PyPDFium2Document(pdf_path)
tables = []
# 提取表格
for page_index, page in enumerate(doc_tables):
detected_tables = detector.extract(page)
for table in detected_tables:
formatted_table = formatter.format(table)
# 获取表格数据,调用df方法获取DataFrame
table_data = formatted_table.df() # 获取表格内容
if table_data is not None:
# 将表格数据转换为DataFrame并存储
df = table_data
tables.append({
"page": page_index + 1,
"position": table.bbox,
"dataframe": df, # 存储DataFrame
})
doc_tables.close()
# 使用 PyMuPDF 提取文本
doc_text = fitz.open(pdf_path)
full_text = []
for i in range(len(doc_text)):
page = doc_text[i]
text = page.get_text("text") # 获取页面文本
full_text.append({
"page": i + 1,
"text": text
})
doc_text.close()
return {"tables": tables, "text": full_text}
if name == "main":
pdf_path = "1.pdf"
result = extract_pdf_content(pdf_path)
print(f"提取到 {len(result['tables'])} 个表格:")
for table in result['tables']:
print(f"\n第 {table['page']} 页表格(位置:{table['position']})")
print(table['dataframe']) # 输出表格
print("\n提取文本示例:")
for text_block in result['text']: # 输出所有页面的文本
print(f"\n第 {text_block['page']} 页文本:\n{text_block['text']}") # 输出完整文本
Catalyst,Reduction temperature (8C),Hydrogen uptake (mmol/g),Pd dispersion (%)
2% Pd/ZnO,200,8 � 1,8.6
2% Pd/ZnO,300,8 � 2,8.6
2% Pd/ZnO,400,2.7 � 0.4,2.9
2% Pd/ZnO,500,3.1 � 0.4,3.3
6% Pd/ZnO,200,17 � 2,6.2
10% Pd/ZnO,200,25 � 4,5.4
2% Pd/CeO2,200,45 � 9,48
2% Pd/CeO2,400,36 � 5,38
2% Pd/CeO2,550,12 � 2,13
6% Pd/CeO2,200,98 � 18,34
10% Pd/CeO2,200,116 � 18,25
page_4.pdf
import re
import fitz # PyMuPDF
from gmft.auto import TableDetector, AutoTableFormatter
import pandas as pd
from gmft.pdf_bindings import PyPDFium2Document
def extract_pdf_content(pdf_path):
# 使用gmft提取表格
detector = TableDetector()
formatter = AutoTableFormatter()
if name == "main":
pdf_path = "1.pdf"
result = extract_pdf_content(pdf_path)