Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ced1856

Browse files
authored
Add files via upload
1 parent 0c74834 commit ced1856

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

python-write-pdf/readme.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
You can go through the tutorial https://www.roytuts.com/how-to-create-a-pdf-file-using-python/

python-write-pdf/simple.pdf

2.73 KB
Binary file not shown.

python-write-pdf/write-simple-pdf.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from fpdf import FPDF
2+
3+
pdf = FPDF()
4+
5+
#header of the pdf file
6+
header = 'Header of PDF Report'
7+
pdf.add_page()
8+
pdf.set_font('Arial', 'B', 16)
9+
w = pdf.get_string_width(header) + 6
10+
pdf.set_x((210 - w) / 2)
11+
pdf.cell(w, 9, header, 0, 0, 'C')
12+
pdf.line(20, 18, 210-20, 18)
13+
14+
#line break
15+
pdf.ln(10)
16+
pdf.set_font('Times', '', 12)
17+
pdf.multi_cell(0, 5, 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.')
18+
19+
pdf.ln()
20+
pdf.set_font('Arial', '', 12)
21+
pdf.set_fill_color(200, 220, 255)
22+
pdf.cell(0, 6, 'Chapter %d : %s' % (1, 'Sample Label'), 0, 1, 'L', 1)
23+
24+
pdf.ln()
25+
pdf.set_font('Courier', 'B', 12)
26+
pdf.multi_cell(0, 5, 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.')
27+
28+
pdf.ln()
29+
pdf.set_font('', 'U', 11)
30+
pdf.multi_cell(0, 6, 'It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using \'Content here, content here\', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for \'lorem ipsum\' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose.')
31+
32+
pdf.ln()
33+
pdf.set_font('', 'I')
34+
pdf.cell(0, 5, 'This is italic text')
35+
36+
#pdf.set_y(0)
37+
pdf.set_y(-30)
38+
pdf.set_font('Arial', '', 8)
39+
pdf.set_text_color(0)
40+
pdf.cell(0, 5, 'Page ' + str(pdf.page_no()), 0, 0, 'C')
41+
42+
pdf.output('simple.pdf', 'F')

0 commit comments

Comments
 (0)