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
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="1007.0894"
height="723.58148"
viewBox="0 0 3550 2550.63"
version="1.1"
id="svg3"
sodipodi:docname="template.svg"
inkscape:version="0.92.1 r15371">
<metadata
id="metadata9">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title />
</cc:Work>
</rdf:RDF>
</metadata>
<defs
id="defs7">
<linearGradient
inkscape:collect="always"
id="linearGradient4603">
<stop
style="stop-color:#000000;stop-opacity:1;"
offset="0"
id="stop4599" />
<stop
style="stop-color:#000000;stop-opacity:0;"
offset="1"
id="stop4601" />
</linearGradient>
<clipPath
clipPathUnits="userSpaceOnUse"
id="clipPath3817">
<rect
style="opacity:0.05;fill:#666666;fill-opacity:1;stroke:#666666;stroke-width:26.95543289;stroke-miterlimit:4;stroke-dasharray:none"
id="rect3819"
width="3547.9897"
height="2523.1006"
x="0.7070353"
y="13.449624" />
</clipPath>
<radialGradient
inkscape:collect="always"
xlink:href="#linearGradient4603"
id="radialGradient4607"
cx="1733.6173"
cy="2082.9883"
fx="1733.6173"
fy="2082.9883"
r="475.78732"
gradientTransform="matrix(1,0,0,0.84632097,3.8476562e-6,320.11525)"
gradientUnits="userSpaceOnUse" />
<filter
style="color-interpolation-filters:sRGB"
id="filter904"
inkscape:label="filter0">
<feMorphology
id="feMorphology906"
radius="2 2"
operator="dilate" />
</filter>
</defs>
<sodipodi:namedview
pagecolor="#e2eaef"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="2560"
inkscape:window-height="1346"
id="namedview5"
showgrid="false"
inkscape:pagecheckerboard="true"
units="mm"
inkscape:zoom="1.69"
inkscape:cx="459.66284"
inkscape:cy="489.4337"
inkscape:window-x="2509"
inkscape:window-y="-11"
inkscape:window-maximized="1"
inkscape:current-layer="svg3"
inkscape:lockguides="true"
inkscape:measure-start="-36.229,837.795"
inkscape:measure-end="-37.7385,837.795"
scale-x="3.52501"
fit-margin-top="0"
fit-margin-left="0"
fit-margin-right="0"
fit-margin-bottom="0"
showborder="false" />
<rect
style="opacity:1;fill:#e2eaef;fill-opacity:1;stroke:none;stroke-width:46.8098793;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="rect4609"
width="3550"
height="2550.0071"
x="0"
y="29.201254" />
<flowRoot
xml:space="preserve"
id="flowRoot4562"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:18.66666603px;font-family:Flux;-inkscape-font-specification:Flux;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none"
transform="translate(805.53619,-3522.7143)"><flowRegion
id="flowRegion4564"><rect
id="rect4566"
width="107.17735"
height="95.268753"
x="378.09787"
y="297.97617" /></flowRegion><flowPara
id="flowPara4568" /></flowRoot> <text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:58.33349609px;line-height:1.25;font-family:Flux;-inkscape-font-specification:Flux;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:3.12500858"
x="2581.7598"
y="-2365.5195"
id="text4560-7-2"><tspan
sodipodi:role="line"
id="tspan4558-3-4"
x="2581.7598"
y="-2314.3047"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:134.16703796px;font-family:Flux;-inkscape-font-specification:'Flux Medium';text-align:center;text-anchor:middle;fill:#306a98;fill-opacity:1;stroke-width:3.12500858" /></text>
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:58.33349228px;line-height:1.25;font-family:Flux;-inkscape-font-specification:Flux;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:3.12500858"
x="1776.5242"
y="312.49139"
id="text4560"><tspan
sodipodi:role="line"
id="tspan4558"
x="1776.5242"
y="312.49139"
style="font-style:normal;font-variant:normal;font-weight:500;font-stretch:normal;font-size:241.66734314px;font-family:Flux;-inkscape-font-specification:'Flux Medium';text-align:center;text-anchor:middle;fill:#306a98;fill-opacity:1;stroke-width:3.12500858">Certificado de Participação</tspan></text>
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:58.33349609px;line-height:1.25;font-family:Flux;-inkscape-font-specification:Flux;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:3.12500858"
x="1775.3168"
y="988.95526"
id="text4560-7"><tspan
sodipodi:role="line"
x="1775.3168"
y="988.95526"
style="font-style:normal;font-variant:normal;font-weight:500;font-stretch:normal;font-size:134.16703796px;font-family:Flux;-inkscape-font-specification:'Flux Medium';text-align:center;text-anchor:middle;fill:#306a98;fill-opacity:1;stroke-width:3.12500858"
id="tspan4612">Certificamos que</tspan></text>
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:bolder;font-stretch:normal;font-size:58.33349609px;line-height:1.25;font-family:Flux;-inkscape-font-specification:Flux;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:3.12500858;filter:url(#filter904)"
x="2103.0295"
y="1397.5194"
id="text4560-7-2-6"><tspan
sodipodi:role="line"
id="tspan4558-3-4-5"
x="2103.0295"
y="1397.5194"
style="font-style:normal;font-variant:normal;font-weight:bolder;font-stretch:normal;font-size:134.16703796px;font-family:Flux;-inkscape-font-specification:'Flux Medium';text-align:center;text-anchor:middle;fill:#306a98;fill-opacity:1;stroke-width:3.12500858">XXXXXXXXXX</tspan></text>
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:bolder;font-stretch:normal;font-size:58.33349609px;line-height:1.25;font-family:Flux;-inkscape-font-specification:Flux;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:3.12500858;filter:url(#filter904)"
x="2888.1797"
y="1567.1019"
id="text4560-7-2-6-9"><tspan
sodipodi:role="line"
id="tspan4558-3-4-5-1"
x="2888.1797"
y="1567.1019"
style="font-style:normal;font-variant:normal;font-weight:bolder;font-stretch:normal;font-size:134.16703796px;font-family:Flux;-inkscape-font-specification:'Flux Medium';text-align:center;text-anchor:middle;fill:#306a98;fill-opacity:1;stroke-width:3.12500858">YYYYYYYYYYYYY</tspan></text>
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:bolder;font-stretch:normal;font-size:58.33349609px;line-height:1.25;font-family:Flux;-inkscape-font-specification:Flux;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:3.12500858;filter:url(#filter904)"
x="2308.5698"
y="1732.8705"
id="text4560-7-2-6-9-4"><tspan
sodipodi:role="line"
id="tspan4558-3-4-5-1-2"
x="2308.5698"
y="1732.8705"
style="font-style:normal;font-variant:normal;font-weight:bolder;font-stretch:normal;font-size:134.16703796px;font-family:Flux;-inkscape-font-specification:'Flux Medium';text-align:center;text-anchor:middle;fill:#306a98;fill-opacity:1;stroke-width:3.12500858">ZZ</tspan></text>
<text
id="text912"
y="1397.1813"
x="276.19003"
style="font-style:normal;font-weight:normal;font-size:134.16703796px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#306a98;fill-opacity:1;stroke:none;stroke-width:3.52500844"
xml:space="preserve"><tspan
style="font-style:normal;font-variant:normal;font-weight:500;font-stretch:normal;font-size:134.16703796px;font-family:Flux;-inkscape-font-specification:'Flux Medium';fill:#306a98;fill-opacity:1;stroke-width:3.52500844"
y="1397.1813"
x="276.19003"
id="tspan910"
sodipodi:role="line">participou da xª edição da</tspan></text>
<text
id="text912-4"
y="1397.3564"
x="2519.6863"
style="font-style:normal;font-weight:normal;font-size:134.16703796px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#306a98;fill-opacity:1;stroke:none;stroke-width:3.52500844"
xml:space="preserve"><tspan
style="font-style:normal;font-variant:normal;font-weight:500;font-stretch:normal;font-size:134.16703796px;font-family:Flux;-inkscape-font-specification:'Flux Medium';fill:#306a98;fill-opacity:1;stroke-width:3.52500844"
y="1397.3564"
x="2519.6863"
id="tspan910-2"
sodipodi:role="line">, realizada nos</tspan></text>
<flowRoot
xml:space="preserve"
id="flowRoot4704"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:18.66666603px;line-height:1.25;font-family:Flux;-inkscape-font-specification:Flux;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none"
transform="translate(805.53619,-3522.7143)"><flowRegion
id="flowRegion4706"><rect
id="rect4708"
width="1832.5817"
height="1095.9261"
x="-455.8811"
y="-36.890148" /></flowRegion><flowPara
id="flowPara4710" /></flowRoot> <rect
style="opacity:0.50499998;fill:#e2eaef;fill-opacity:0;stroke:url(#radialGradient4607);stroke-width:12.82680798;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="rect4589"
width="938.7478"
height="792.51074"
x="1264.2434"
y="1686.7363" />
<text
xml:space="preserve"
style="font-style:normal;font-weight:normal;font-size:134.16703796px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#306a98;fill-opacity:1;stroke:none;stroke-width:3.52500844"
x="248.246"
y="1566.3065"
id="text912-1"><tspan
sodipodi:role="line"
id="tspan910-6"
x="248.246"
y="1566.3065"
style="font-style:normal;font-variant:normal;font-weight:500;font-stretch:normal;font-size:134.16703796px;font-family:Flux;-inkscape-font-specification:'Flux Medium';fill:#306a98;fill-opacity:1;stroke-width:3.52500844">dias 5, 6 e 7 de maio de 2017, na cidade do</tspan></text>
<text
xml:space="preserve"
style="font-style:normal;font-weight:normal;font-size:134.16703796px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#306a98;fill-opacity:1;stroke:none;stroke-width:3.52500844"
x="3268.8015"
y="1564.355"
id="text912-1-3"><tspan
sodipodi:role="line"
id="tspan910-6-7"
x="3268.8015"
y="1564.355"
style="font-style:normal;font-variant:normal;font-weight:500;font-stretch:normal;font-size:134.16703796px;font-family:Flux;-inkscape-font-specification:'Flux Medium';fill:#306a98;fill-opacity:1;stroke-width:3.52500844">,</tspan></text>
<text
xml:space="preserve"
style="font-style:normal;font-weight:normal;font-size:134.16703796px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#306a98;fill-opacity:1;stroke:none;stroke-width:3.52500844"
x="838.58978"
y="1731.2192"
id="text912-1-7"><tspan
sodipodi:role="line"
id="tspan910-6-0"
x="838.58978"
y="1731.2192"
style="font-style:normal;font-variant:normal;font-weight:500;font-stretch:normal;font-size:134.16703796px;font-family:Flux;-inkscape-font-specification:'Flux Medium';fill:#306a98;fill-opacity:1;stroke-width:3.52500844">com carga horária total de</tspan></text>
<text
xml:space="preserve"
style="font-style:normal;font-weight:normal;font-size:134.16703796px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#306a98;fill-opacity:1;stroke:none;stroke-width:3.52500844"
x="2402.7126"
y="1731.2192"
id="text912-1-7-4"><tspan
sodipodi:role="line"
id="tspan910-6-0-2"
x="2402.7126"
y="1731.2192"
style="font-style:normal;font-variant:normal;font-weight:500;font-stretch:normal;font-size:134.16703796px;font-family:Flux;-inkscape-font-specification:'Flux Medium';fill:#306a98;fill-opacity:1;stroke-width:3.52500844">horas.</tspan></text>
<flowRoot
xml:space="preserve"
id="flowRoot1004"
style="fill:black;fill-opacity:1;stroke:none;font-family:sans-serif;font-style:normal;font-weight:normal;font-size:18.66666667px;line-height:1.25;letter-spacing:0px;word-spacing:0px"><flowRegion
id="flowRegion1006"><rect
id="rect1008"
width="175.14793"
height="178.69823"
x="588.16571"
y="318.84775" /></flowRegion><flowPara
id="flowPara1010" /></flowRoot></svg>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment