【问题标题】:python convert pdf files to epspython将pdf文件转换为eps
【发布时间】:2017-07-14 13:41:06
【问题描述】:

你好,我有很多 pdf 文件,我想使用 python 转换为 .eps。

我找到了一些代码,但对我不起作用,代码执行时没有错误,但我没有获取一些 .eps 文件。

有什么想法吗?

我有 python 2.7.13

代码 1:

from glob import *
from os import system
fileList = glob('*.pdf')
for f in fileList:
  system('pdftops -eps {0}'.format(f))

代码 2:

import os, re, sys 
dirList = os.listdir( '.' )
try:
    os.mkdir( 'EpsFigs' )
except:
    pass
for f in dirList:
    m = re.match('([\w\-]+).(|jpg|jp2|png|pdf|)$',f)
    if m:
        cmd = 'convert %s EpsFigs/%s.eps'%( f, m.group(1) )
        os.system(cmd)

【问题讨论】:

  • 为什么不直接通过命令行转换呢?
  • @RomanPerekhrest 怎么样?

标签: python pdf eps


【解决方案1】:

使用linux命令pdf2ps将pdf转为eps。

pdf2ps [ options ] input.pdf [output.ps]

例如,

pdf2ps input.pdf output.eps

如果你真的想用python,可以用subprocess.call调用上面的命令:

from subprocess import call
call(["pdf2ps", "input.pdf", "output.eps"])

参考

【讨论】:

  • 我的代码有错误WindowsError: [Error 2] 知道为什么吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-10-28
  • 1970-01-01
  • 2013-09-09
  • 2019-11-24
  • 2020-10-30
  • 2010-11-06
  • 1970-01-01
相关资源
最近更新 更多