2015-06-09 48 views
2

我想將PDF轉換到指定的目錄文本PDF格式轉換爲文本蟒蛇錯誤

這是我嘗試

import os 
import subprocess 

def pdftotext(pdf): 
    # insert your code here 
    basename, _ = os.path.splitext(os.path.basename(pdf)) 
    subprocess.call(['pdftotext', '-enc', 'UTF-8', 
       pdf, os.path.join('c:\pdf\pydf\data', basename + '.txt')]) 

pdftotext("C:\\pdf\\pydf\\pdfs\\ipm.pdf") 
with open(os.path.join('c:\\pdf\\pydf\\data', 'ipm.txt')) as infile: 
    print(infile.read(1000)) 

的代碼,但它得到錯誤

Traceback (most recent call last): 
File "C:/pdf/browser.py", line 10, in <module> 
pdftotext("C:\\pdf\\pydf\\pdfs\\ipm.pdf") 
File "C:/pdf/browser.py", line 8, in pdftotext 
pdf, os.path.join('c:\pdf\pydf\data', basename + '.txt'), '-']) 
File "C:\Python34\lib\subprocess.py", line 537, in call 
with Popen(*popenargs, **kwargs) as p: 
File "C:\Python34\lib\subprocess.py", line 859, in __init__ 
restore_signals, start_new_session) 
File "C:\Python34\lib\subprocess.py", line 1112, in _execute_child 
startupinfo) 
FileNotFoundError: [WinError 2] The system cannot find the file specified 

什麼是錯的我的代碼?

+0

對不起,我剛纔編輯我的職務 – Fakhriyanto

+1

該系統找不到指定的文件(C: –

+0

未找到文件‘FileNotFoundError:[WinError 2]系統找不到指定的文件’ –

回答

0

到該文件的路徑是不正確,而不是C:\ PDF \ pydf \ PDF文件\ ipm.pdf使用 os.path.join( 'C:', 'PDF文件', 'PDF文件',「IPM。 PDF')