2017-08-06 2 views
0

目的:MS Officeのコードが使用さ改宗者PPTは(エラーが発生した)

Windowsサーバにインストールされていない:

from subprocess import Popen, PIPE 
import time 

def convert(src, dst): 
    d = {'src': src, 'dst': dst} 
    commands = [ 
     '/usr/bin/docsplit pdf --output %(dst)s %(src)s' % d, 
     'oowriter --headless -convert-to pdf:writer_pdf_Export %(dst)s %(src)s' % d, 
    ] 

    for i in range(len(commands)): 
     command = commands[i] 
     st = time.time() 
     process = Popen(command, stdout=PIPE, stderr=PIPE, shell=True) # I am aware of consequences of using `shell=True` 
     out, err = process.communicate() 
     errcode = process.returncode 
     if errcode != 0: 
      raise Exception(err) 
     en = time.time() - st 
     print ('Command %s: Completed in %s seconds' % (str(i+1), str(round(en, 2)))) 

if __name__ == '__main__': 
    src = 'C:\xxx\ppt' 
    dst = 'C:\xxx\ppt\destination' 
    convert(src, dst) 

シナリオのpython 3.6.1を使用してPDFにPPTを変換しますエラーが発生しました:

Traceback (most recent call last): 
    File "C:/PythonFolder/ppt_to_pdf.py", line 134, in <module> 
    convert(src, dst) 
    File "C:/PythonFolder/ppt_to_pdf.py", line 123, in convert 
    process = Popen(command, stdout=PIPE, stderr=PIPE, shell=True) # I am aware of consequences of using `shell=True` 
    File "C:\Python 3.6.1\lib\subprocess.py", line 707, in __init__ 
    restore_signals, start_new_session) 
    File "C:\Python 3.6.1\lib\subprocess.py", line 990, in _execute_child 
    startupinfo) 
ValueError: embedded null character 

このエラーを解決する方法はありますか? この場合に役立つその他のPythonライブラリ。

+0

WindowsまたはLinuxで動作していますか? – identicon

+0

Windowsで走っているなら、 '/ usr/bin/docsplit pdf --output%(dst)s%(src)s'コマンドはPPTをLinuxに変換するとは思えません。 Popenはそのコマンドの処理に問題があり、そのエラーが発生している可能性があります。 – identicon

+0

私は窓で走っています。その場合、回避策はありますか? – grc

答えて

0

Windows上で動作しているので、/usr/bin/docsplit pdf --output %(dst)s %(src)sというコマンドは、Linux用のようだから、PPTを変換しません。 Popenはそのコマンドの処理に問題があり、エラーが発生している可能性があります。

WindowsのコマンドラインでPPTをPDFに変換するのはちょっと難しいです。あなたの最善の策はto install LibreOffice and run with headless modeだと思います。質問者がC#interopライブラリを使用して終了するa SuperUser question on itもありますが、Microsoft Officeをインストールする必要があると思います。

ありがとうございました。

関連する問題