diff --git a/certificates/resources/images/european_commission_logo.png b/certificates/EC.png similarity index 100% rename from certificates/resources/images/european_commission_logo.png rename to certificates/EC.png diff --git a/certificates/ECW-stamp.png b/certificates/ECW-stamp.png new file mode 100644 index 00000000..6939ed77 Binary files /dev/null and b/certificates/ECW-stamp.png differ diff --git a/certificates/README.md b/certificates/README.md new file mode 100644 index 00000000..c607b1cb --- /dev/null +++ b/certificates/README.md @@ -0,0 +1,4 @@ +# CodeEUCertificates + +Instructions: +$ python pyploma.py "Name Surname" Event_ID Year diff --git a/certificates/resources/images/background.png b/certificates/V14.png similarity index 100% rename from certificates/resources/images/background.png rename to certificates/V14.png diff --git a/certificates/__init__.py b/certificates/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/certificates/resources/template.tex b/certificates/certi.tex old mode 100644 new mode 100755 similarity index 71% rename from certificates/resources/template.tex rename to certificates/certi.tex index d1e1dff0..80a12abd --- a/certificates/resources/template.tex +++ b/certificates/certi.tex @@ -1,10 +1,10 @@ \documentclass[12pt]{article} \usepackage[utf8]{inputenc} -\usepackage[english]{babel} +\usepackage[spanish]{babel} \usepackage{mathpazo} \renewcommand{\familydefault}{\rmdefault} \usepackage[landscape,a4paper]{geometry} -\geometry{verbose,tmargin=0cm,bmargin=0cm,lmargin=3cm,rmargin=3cm} +\geometry{verbose,tmargin=0cm,bmargin=0cm,lmargin=0cm,rmargin=0cm} \usepackage{fancybox} \usepackage{calc} \usepackage{multicol} @@ -18,13 +18,13 @@ \vfill \centering \includegraphics[width=\paperwidth,height=\paperheight,% -keepaspectratio]{images/background.png}% +keepaspectratio]{V14.png}% \vfill }}} \begin{document} -\AddToShipoutPicture{\BackgroundPic} +\[\AddToShipoutPicture{\BackgroundPic} ~ \vspace{1.2cm} ~ @@ -35,8 +35,8 @@ \begin{center} \begin{tabular}{lr} %~\hspace{0.7cm} -\includegraphics[height=3.4cm]{images/codeweek_logo.png} -\includegraphics[height=3.4cm]{images/european_commission_logo.png} +\includegraphics[height=3.4cm]{codeweekeu.png} +\includegraphics[height=3.4cm]{EC.png} \end{tabular} \end{center} \end{table} @@ -44,11 +44,10 @@ \LARGE{CodeWeek EU organisers are honoured\\ \vspace{1cm} \fontsize{50}{60}{\textbf{TO CERTIFY}} -} \vspace{0.4cm} -\Huge{that \textbf{ +\Huge{that \textbf{%pointname }} \vspace{0.4cm} @@ -57,7 +56,8 @@ \vspace{0.3cm} -\Huge{\textbf{EUROPE CODE WEEK 2016}} +\Huge{\textbf{EUROPE CODE WEEK \textbf{%pointyear +}}} \vspace{0.3cm} @@ -81,18 +81,19 @@ \begin{center} \begin{tabular}{lr} %~\hspace{0.7cm} -\includegraphics[height=2.5cm]{images/signature_and_stamp.png} +\includegraphics[height=2.5cm]{signature2.png} \end{tabular} \end{center} \end{table} \vspace{-2.2cm} \begin{center} -\footnotesize{On behalf of Europe Code Week Ambassadors}\\ -%\end{tabular} +\footnotesize{On behalf of Europe Code Week Ambassadors}\\ +\end{tabular} %Diploma elaborado con el software libre \texttt{Pyploma}, (c) %\url{fjruizruano@gmail.com} bajo licencia %GPLv3. Visite: \url{http://code.google.com/p/pyploma} \end{center} -\end{document} +\] +\end{document} \ No newline at end of file diff --git a/certificates/resources/images/codeweek_logo.png b/certificates/codeweekeu.png similarity index 100% rename from certificates/resources/images/codeweek_logo.png rename to certificates/codeweekeu.png diff --git a/certificates/generator.py b/certificates/generator.py deleted file mode 100644 index e5a4e460..00000000 --- a/certificates/generator.py +++ /dev/null @@ -1,59 +0,0 @@ -from os import system -from os import unlink -from os.path import dirname -from os.path import realpath -import re - -def generate_certificate_for(event_id, certificate_name, name_of_certificate_holder): - resources_path = dirname(realpath(__file__)) + '/resources/' - static_files_path = dirname(dirname(realpath(__file__))) + '/staticfiles/certificates/' - - generic_template_path = resources_path + 'template.tex' - personalized_template_path = resources_path + str(event_id) + '.tex' - resulting_certificate_path = static_files_path + certificate_name - - with open(generic_template_path) as template: - personalized_certificate_content = template.read().replace( - '', tex_escape(name_of_certificate_holder)) - - with open(personalized_template_path, 'w') as personalized_template: - personalized_template.write(personalized_certificate_content.encode('utf-8')) - - commands = [ - 'cd ' + resources_path, - 'pdflatex -interaction=nonstopmode -output-directory ' + resources_path + ' ' + personalized_template_path, - 'mkdir -p ' + static_files_path, - 'mv -f ' + personalized_template_path.replace('.tex', '.pdf') + ' ' + resulting_certificate_path, - 'rm -rf ' + resources_path + str(event_id) + '.*', - ] - - if system(' && '.join(commands)) != 0: - return False - - return resulting_certificate_path - -def tex_escape(text): - """ - Escapes special chars in a text to be safely included in a LaTeX document. - See: http://stackoverflow.com/a/25875504/75715 - :param text: a plain text message - :return: the message escaped to appear correctly in LaTeX - """ - conv = { - '&': r'\&', - '%': r'\%', - '$': r'\$', - '#': r'\#', - '_': r'\_', - '{': r'\{', - '}': r'\}', - '~': r'\textasciitilde{}', - '^': r'\^{}', - '\\': r'\textbackslash{}', - '<': r'\textless', - '>': r'\textgreater', - } - replacements = (re.escape(unicode(key)) for key in sorted(conv.keys(), key = lambda item: - len(item))) - - regex = re.compile('|'.join(replacements)) - return regex.sub(lambda match: conv[match.group()], text) diff --git a/certificates/pyploma.py b/certificates/pyploma.py new file mode 100755 index 00000000..1f8829a6 --- /dev/null +++ b/certificates/pyploma.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# This diploma generator read a list of names to +# fill a LaTeX template with a point for the name. +# Optinally, it can compile the LaTeX files and join them. +# If LaTeX errors are present, then press Enter. + +print "Pyploma: Diploma generator for LaTeX and pdf.\n" + +import sys +# Invoke terminal +from commands import * +import commands +def run_command(cmd): + getstatusoutput(cmd) + +if len(sys.argv) != 4: + print "Usage: python pyploma.py \"Name To be Printed\" Event_ID\"Year" +else: + name = str(sys.argv[1]) + filename = str(sys.argv[2]) + year = str(sys.argv[3]) + + salida = open(filename + ".tex","w") # create a LaTeX file for each person in the list + + text = open("certi.tex") # open the LaTeX document + text = text.read() # read it + text_list = list(text) # transform it into a list + + y_name = text.find("%pointname") #search the point for name inclusion + z_name = len("%pointname")+2 + text_list[y_name+z_name:y_name+z_name] = name # insert the name + x_name = text.find("%pointyear") #search the point for year inclusion + n_name = len("%pointyear")+4 + text_list[x_name+n_name:x_name+n_name] = year # insert the year + + text_final = "".join(text_list) # from list to string + + salida.write(text_final) # save changes in the created file + salida.close() # closes the file + + run_command(str("pdflatex -interaction=nonstopmode " + filename + ".tex")) # compile LaTeX a pdf (optional) + print name #control + + run_command(str("pdftk output*.pdf cat output todos_diplomas.pdf")) # create pdf with all the created diplomas (optional) + + print "\nAnd we are done! :-)" #control diff --git a/certificates/signature.png b/certificates/signature.png new file mode 100755 index 00000000..60996405 Binary files /dev/null and b/certificates/signature.png differ diff --git a/certificates/resources/images/signature_and_stamp.png b/certificates/signature2.png similarity index 100% rename from certificates/resources/images/signature_and_stamp.png rename to certificates/signature2.png