-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtryPDF.py
More file actions
38 lines (25 loc) · 729 Bytes
/
Copy pathtryPDF.py
File metadata and controls
38 lines (25 loc) · 729 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
import sys
import PyPDF2
from fpdf import FPDF
def testReadPDF():
samplePDF = 'Lakotalanguageplansandideas.pdf'
pdf_file = open(samplePDF)
read_pdf = PyPDF2.PdfFileReader(pdf_file)
number_of_pages = read_pdf.getNumPages()
print '%d pages in document' % number_of_pages
for pageNum in xrange(number_of_pages):
page = read_pdf.getPage(pageNum)
print 'Page %d content:' % pageNum
page_content = page.extractText()
print page_content
print
def testWritePDF(outfilename):
pdf = FPDF()
pdf.add_page()
pdf.set_font('Arial', 'B', 16)
pdf.cell(40, 10, 'Hello World!')
pdf.output(outfilename, 'F')
def main(argv):
testWritePDF('new.pdf')
if __name__ == '__main__':
main(sys.argv)