当前位置: 代码迷 >> python >> 将参数传递给pdf2txt函数
  详细解决方案

将参数传递给pdf2txt函数

热度:119   发布时间:2023-06-14 08:57:31.0

我正在尝试使用PDFMiner从PDF文件提取文本。 我想使用脚本pdf2txt.py在以下位置运行示例示例

这条线

pdf2txt.py samples/simple1.pdf

由于我正在使用IDLE在Windows上工作,因此我在IDLE中运行以下脚本

import pdf2txt

pdf2txt.main(['C:\Users\Desktop\Dictionary Construction\simple1.pdf'])

每次给我

用法:C:\\ Usersernor \\ Desktop \\ Dictionary Construction \\ simple1.pdf [-d] [-p pagenos] [-m maxpages] [-P密码] [-o输出] [-C] [-n] [-A ] [-V] [-M char_margin] [-L line_margin] [-W word_margin] [-Fboxs_flow] [-Y layout_mode] [-O output_dir] [-R旋转] [-t text | html | xml | tag ] [-c编解码器] [-s比例]文件...

我知道这是一条错误消息,告诉我该参数未解析。 pdf2txt.py的前几行如下:

def main(argv):
    import getopt
def usage():
    print ('usage: %s [-d] [-p pagenos] [-m maxpages] [-P password] [-o output]'
           ' [-C] [-n] [-A] [-V] [-M char_margin] [-L line_margin] [-W word_margin]'
           ' [-F boxes_flow] [-Y layout_mode] [-O output_dir] [-R rotation]'
           ' [-t text|html|xml|tag] [-c codec] [-s scale]'
           ' file ...' % argv[0])
    return 100
try:
    (opts, args) = getopt.getopt(argv[1:], 'dp:m:P:o:CnAVM:L:W:F:Y:O:R:t:c:s:')
except getopt.GetoptError:

如何格式化我的论点呢? 我知道这是一个愚蠢的问题,但它使我感到困惑。

请帮我!

谢谢,

杰森

更新

遵循路易斯的建议,我将命令更改为

pdf2txt.main(['simple1.html','mypdf.pdf'])

现在它可以在shell窗口中产生输出了,但是,我找不到输出文件'simple1.html',我尝试了以下命令:

pdf2txt.main(['-o C:\Users\Desktop\Dictionary Construction\simple1.html','mypdf.pdf'])

pdf2txt.main(['C:\Users\Desktop\Dictionary Construction\simple1.html','mypdf.pdf'])

他们都不在我指定的文件夹中工作并产生文件。

您应该将其称为:

pdf2txt.py samples/simple1.txt samples/simple1.pdf

假设,如果要输出样本/simple1.txt。

  相关解决方案