You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

批量转换PDF为CSV报错:TypeError缺少output_path参数

批量PDF转CSV报错:TypeError: convert_into() missing required 'output_path'

我的代码:

import glob
import tabula

for filepath in glob.iglob('C:/Users/username/Downloads/folder with space/myfolderwithpdfs/*.pdf'):
    tabula.convert_into(filepath, pages="all", output_format='csv')

报错信息:

TypeError                                 Traceback (most recent call last)
Input In [11], in <cell line: 6>()
      5 # transform the pdfs into excel files
      6 for filepath in glob.iglob('C:/Users/username/Downloads/folder with space/myfolderwithpdfs/*.pdf'):
----> 7     tabula.convert_into(filepath, pages="all", output_format='csv')

TypeError: convert_into() missing 1 required positional argument: 'output_path'

问题原因:

tabula.convert_into() 方法必须显式指定输出文件路径(output_path参数),你只传入了输入PDF路径和其他参数,没有告诉程序转换后的CSV要保存到哪里,因此触发TypeError。

修正后的代码:

import glob
import tabula
import os

for filepath in glob.iglob('C:/Users/username/Downloads/folder with space/myfolderwithpdfs/*.pdf'):
    # 基于原PDF文件名生成对应CSV路径,替换后缀即可
    output_path = os.path.splitext(filepath)[0] + '.csv'
    tabula.convert_into(filepath, output_path, pages="all", output_format='csv')

说明:

  • 用os.path.splitext(filepath)[0]获取去掉后缀的原文件名,再拼接.csv,确保每个PDF对应一个同名CSV文件,默认保存在原PDF同目录下。
  • 如果需要将CSV统一存到其他目录,可直接指定output_path为目标路径,例如:'C:/Users/username/Downloads/csv_output/' + os.path.basename(filepath).replace('.pdf', '.csv')。

内容的提问来源于stack exchange,提问作者Kenny

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.21 13:45:30