Last active
June 16, 2017 16:53
-
-
Save JoaoFelipe/19419666971bd70c7316aa49e81411d1 to your computer and use it in GitHub Desktop.
Gerador de certificados PySE
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Nome | Matrícula | |
---|---|---|
Joao | ||
Felipe | 20170616 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## O inkscape está travando em algumas conversões para PDF aqui\n", | |
"\n", | |
"Se isso acontecer, apenas reinicie o notebook, e reexecute a última célula" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"# Instalar inkscapte e colocar no path: https://inkscape.org/pt/\n", | |
"!pip install svgutils" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"import re\n", | |
"import os\n", | |
"import svgutils.transform\n", | |
"from svgutils.transform import fromfile, TextElement\n", | |
"from IPython.display import display, SVG\n", | |
"\n", | |
"# ToDo: alterar para arquivo de template\n", | |
"TEMPLATE = 'template.svg'\n", | |
"\n", | |
"svgutils.transform.SVG = \"\"\n", | |
"\n", | |
"template = fromfile(TEMPLATE)\n", | |
"width, wunit = re.findall('([\\d\\.]+)(.*)', template.width)[0]\n", | |
"height, hunit = re.findall('([\\d\\.]+)(.*)', template.height)[0]\n", | |
"\n", | |
"# ToDo: definir posição\n", | |
"x = float(width) / 2\n", | |
"y = float(height) / 2\n", | |
"\n", | |
"\n", | |
"# ToDO: alterar para leiturar da lista de participantes\n", | |
"nomes = [\n", | |
" \"Anaís\",\n", | |
" \"Bê\",\n", | |
" \"Cássio\",\n", | |
" \"Débora\",\n", | |
" \"Erivàldo\",\n", | |
" \"Feijó\",\n", | |
" \"Grr😬\",\n", | |
" \"Hãõ\",\n", | |
"]\n", | |
"\n", | |
"if not os.path.exists(\"certificados\"):\n", | |
" os.mkdir(\"certificados\")\n", | |
"for i, nome in enumerate(nomes):\n", | |
" svgpath = os.path.join(\"certificados\", \"{}.svg\".format(nome))\n", | |
" pdfpath = os.path.join(\"certificados\", \"{}.pdf\".format(nome))\n", | |
" if os.path.exists(pdfpath):\n", | |
" continue # Pula o que já foi feito\n", | |
" print(i, nome)\n", | |
" template = fromfile(TEMPLATE)\n", | |
" # ToDo: alterar para o formato desejado\n", | |
" template.append(TextElement(\n", | |
" x, y, nome,\n", | |
" size=16,\n", | |
" anchor=\"middle\",\n", | |
" font=\"Verdana\",\n", | |
" weight=\"normal\",\n", | |
" letterspacing=0\n", | |
" ))\n", | |
" \n", | |
" template.save(svgpath)\n", | |
" !inkscape --export-pdf={pdfpath} {svgpath}" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.6.0" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment