-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtcpdf_example.py
More file actions
40 lines (30 loc) · 821 Bytes
/
tcpdf_example.py
File metadata and controls
40 lines (30 loc) · 821 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env python
from php import PHP
def main():
php = PHP()
php.include('tcpdf/config/lang/eng.php')
php.include('tcpdf/tcpdf.php')
pdf = php.new('TCPDF', 'P', 'mm', 'A4', True, 'UTF-8')
pdf.setFontSubsetting(False)
pdf.setAuthor('VSzA')
pdf.setCreator('PPCG')
pdf.setTitle('TCPDF in Python!?')
pdf.setPrintHeader(False)
pdf.setMargins(10, 10)
pdf.AddPage()
pdf.SetFont('dejavusans', 'B', 12)
pdf.Cell(0, 0, 'Hello Python')
pdf.Ln()
x = pdf.GetX()
y = pdf.GetY()
pdf.setXY(30, 30)
pdf.Cell(0, 0, 'GOTOs are bad')
pdf.setXY(x, y + 2.5)
pdf.Cell(0, 0, 'I can has PHP variables')
pdf.Output()
pdf_data = str(php)
with file('output.pdf', 'wb') as pdf_file:
pdf_file.write(pdf_data)
print '{0} bytes of PDF have been written'.format(len(pdf_data))
if __name__ == '__main__':
main()