Example #1
0
 def __init__(self, path=None) :
     try:
         command = find_command('gs', path=path)
     except EnvironmentError:
         try:
             command = find_command('gswin32c.exe', path=path)
         except EnvironmentError:
             raise EnvironmentError("Could not find Ghostscript on path."
             " There should be either a gs executable or a gswin32c.exe on your system's path")
     
     self.command = command        
Example #2
0
    def __init__(self, path=None):
        try:
            command = find_command('gs', path=path)
        except EnvironmentError:
            try:
                command = find_command('gswin32c.exe', path=path)
            except EnvironmentError:
                raise EnvironmentError(
                    "Could not find Ghostscript on path."
                    " There should be either a gs executable or a gswin32c.exe on your system's path"
                )

        self.command = command
Example #3
0
def svg_formatter(data, format, fout):
    """ Generate a logo in Scalable Vector Graphics (SVG) format.
    Requires the program 'pdf2svg' be installed.
    """

    fpdf = StringIO()
    pdf_formatter(data, format, fpdf)
    fpdf.seek(0)

    try:
        command = find_command('pdf2svg')
    except EnvironmentError:
        raise EnvironmentError(
            "Scalable Vector Graphics (SVG) format requires the program 'pdf2svg'. "
            "Cannot find 'pdf2svg' on search path.")

    import tempfile, os
    fpdfi, fname_pdf = tempfile.mkstemp(suffix=".pdf")
    fsvgi, fname_svg = tempfile.mkstemp(suffix=".svg")
    try:

        fpdf2 = open(fname_pdf, 'w')
        fpdf2.write(fpdf.getvalue())
        fpdf2.seek(0)

        args = [command, fname_pdf, fname_svg]
        p = Popen(args)
        (out, err) = p.communicate()

        fsvg = open(fname_svg)
        fout.write(fsvg.read())
    finally:
        os.remove(fname_svg)
        os.remove(fname_pdf)
Example #4
0
def svg_formatter(data, format, fout) : 
    """ Generate a logo in Scalable Vector Graphics (SVG) format.
    Requires the program 'pdf2svg' be installed.
    """

    fpdf = StringIO()
    pdf_formatter(data, format, fpdf)
    fpdf.seek(0)
    
    try:
   	    command = find_command('pdf2svg') 
    except EnvironmentError:
    	raise EnvironmentError("Scalable Vector Graphics (SVG) format requires the program 'pdf2svg'. "
    	                        "Cannot find 'pdf2svg' on search path.")

    import tempfile, os
    fpdfi, fname_pdf = tempfile.mkstemp(suffix=".pdf")
    fsvgi, fname_svg = tempfile.mkstemp(suffix=".svg")
    try:
        
        fpdf2 = open(fname_pdf, 'w')
        fpdf2.write(fpdf.getvalue() )
        fpdf2.seek(0)
  
        args = [command, fname_pdf, fname_svg]
        p = Popen(args)
        (out,err) = p.communicate() 

        fsvg = open(fname_svg)
        fout.write(fsvg.read())
    finally:
        os.remove(fname_svg)
        os.remove(fname_pdf)