Converting multiple SVG files to PDF in Python?
georgereynolds (0)

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?')
You are viewing a single comment. View All
PaoloAmoroso (67)

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.

georgereynolds (0)

@PaoloAmoroso

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

PaoloAmoroso (67)

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