Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@JoaoFelipe
Last active June 16, 2017 16:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JoaoFelipe/19419666971bd70c7316aa49e81411d1 to your computer and use it in GitHub Desktop.
Save JoaoFelipe/19419666971bd70c7316aa49e81411d1 to your computer and use it in GitHub Desktop.
Gerador de certificados PySE
Nome Matrícula
Joao
Felipe 20170616
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
{
"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
}
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment