Skip to content
Sign upLog in
← Back to Community

Converting multiple SVG files to PDF in Python?

Profile icon
georgereynolds

I have a python 3 script which uses 'convert' (a unix/linux utliity) to convert multiple SVG files to a single PDF file. Works very well from my Windows 10 box using the Ubuntu Linux command line, but not in repl.it.

Any alternatives or tips ?

I've seen python SVG convert utilities but not sure if any work with multiple SVG files to one PDF file

def convert_to_pdf(): print("Tidying files...") shutil.rmtree(str(directory_in_str)+"/out") print("Converting to PDF (can take a while)...") cmd = 'convert '+str(directory_in_str)+'/*.svg '+str(directory_in_str)+'/'+str(magid)+"_"+str(issueid)+'.pdf' returned_value = subprocess.call(cmd, shell=True) # returns the exit code in unix print('PDF conversion process ended with value: ', returned_value) if returned_value == 0: print('PDF conversion completed OK') else: print ('PDF conversion failed?')
Voters
Profile icon
HarshilMalde
Profile icon
georgereynolds
Comments
hotnewtop
Profile icon
leooel

Hi, I have a working draft, I convert SVG files into one PDF.

Profile icon
PaoloAmoroso

The convert program isn't available in the Repl.it shell, so I'm afraid your script can't work on the platform as it relies on that specific program.

Profile icon
georgereynolds

@PaoloAmoroso

Yeah I appreciate that. However, is there anything else I can use natively in python to achieve the same objective?

Profile icon
PaoloAmoroso

@georgereynolds
there are good image and file conversion libraries in PyPI but I'm afraid I haven't tried any yet.