0
目的:微軟Office未安裝在Windows Server轉換PPT到PDF(時遇到錯誤)
使用代碼:
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
場景轉換的PPT到PDF遇到的錯誤:
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庫,這將有助於在這種情況下。
你在Windows或Linux上運行嗎? – identicon
如果你在Windows上運行,我不認爲命令'/ usr/bin/docsplit pdf --output%(dst)s%(src)s'會轉換PPT,因爲它看起來適用於Linux。 Popen可能無法處理該命令,導致該錯誤。 – identicon
我正在windows上運行。如果是這種情況,是否有任何解決方法? – grc