]> wagnertech.de Git - SVBaL.git/blob - python/ausweis/ausweis.py
pydev-s6
[SVBaL.git] / python / ausweis / ausweis.py
1 #!/usr/bin/python3
2
3 import sys
4
5 """
6 Testaufruf:
7 ./ausweis.py Michael Wagner "25.5.1965" MitgliederausweisSVBaLVorlage_leer.pdf ./
8 """
9
10 class Mitglied:
11     def __init__(self, nachname, vorname, geburtsdatum):
12         self.nachname = nachname
13         self.vorname = vorname
14         self.geburtsdatum = geburtsdatum
15     
16 def erzeuge_ausweis(mitglied: Mitglied, hintergrund_pdf, ausgabe_pfad):
17     from PyPDF2 import PdfFileWriter, PdfFileReader
18     import io
19     from reportlab.pdfgen import canvas
20     from reportlab.lib.pagesizes import letter
21     
22     packet = io.BytesIO()
23     can = canvas.Canvas(packet, pagesize=letter)
24     can.setFont("Helvetica", 12)
25     can.drawString(460, 110, "235147")
26     can.drawString(330, 80, mitglied.vorname+" "+mitglied.nachname)
27     can.setFont("Helvetica", 9)
28     can.drawString(400, 56, mitglied.geburtsdatum)
29     can.drawString(400, 42, "1.3.2012")
30     can.drawString(400, 20, "Gleiwitzer Str. 28")
31     
32     can.save()
33     
34     #move to the beginning of the StringIO buffer
35     packet.seek(0)
36     
37     # create a new PDF with Reportlab
38     new_pdf = PdfFileReader(packet)
39     # read your existing PDF
40     existing_pdf = PdfFileReader(open(hintergrund_pdf, "rb"))
41     output = PdfFileWriter()
42     # add the "watermark" (which is the new pdf) on the existing page
43     page = existing_pdf.pages[0]
44     page.mergePage(new_pdf.pages[0])
45     output.addPage(page)
46     # finally, write "output" to a real file
47     output_stream = open(outpath+"destination.pdf", "wb")
48     output.write(output_stream)
49     output_stream.close()
50
51 if __name__ == "__main__":
52     if len(sys.argv) == 6:
53         nachname = sys.argv[1]
54         vorname = sys.argv[2]
55         geburtsdatum = sys.argv[3]
56         infile = sys.argv[4]
57         outpath = sys.argv[5]
58     else:
59         print ("Nachname: ")
60         nachname = input()
61         print ("Vorname:")
62         vorname = input()
63         print ("Geburtsdatum:")
64         geburtsdatum = input()
65         print ("Input-Datei: ")
66         infile = input()
67         print ("Ausgabepfad:")
68         outpath = input()
69         
70     mitglied = Mitglied(nachname, vorname, geburtsdatum)
71     erzeuge_ausweis(mitglied,infile, outpath)
72