python convert pdf files to eps [duplicate]
Asked Answered
M

1

1

hello I have many pdf files and I eant to convert to .eps using python.

I have find some codes but don't work for me that codes execute without some error but I don't take some .eps file .

any idea ?

I have python 2.7.13

code 1 :

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

code 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)
Miramirabeau answered 14/7, 2017 at 13:41 Comment(2)
why not convert via command line directly?Ferromagnesian
@Ferromagnesian how ?Miramirabeau
N
3

Use linux command pdf2ps to convert pdf to eps.

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

For example,

pdf2ps input.pdf output.eps

If you really want to use python, you can call the above command with subprocess.call:

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

Reference

Narcoma answered 14/7, 2017 at 14:34 Comment(1)
i have error with this code WindowsError: [Error 2] any idea why ?Miramirabeau

© 2022 - 2024 — McMap. All rights reserved.