本文整理汇总了Python中pyPdf.PdfFileWriter.getNumPages方法的典型用法代码示例。如果您正苦于以下问题:Python PdfFileWriter.getNumPages方法的具体用法?Python PdfFileWriter.getNumPages怎么用?Python PdfFileWriter.getNumPages使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyPdf.PdfFileWriter
的用法示例。
在下文中一共展示了PdfFileWriter.getNumPages方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_two_on_one_page
# 需要导入模块: from pyPdf import PdfFileWriter [as 别名]
# 或者: from pyPdf.PdfFileWriter import getNumPages [as 别名]
def test_two_on_one_page(self):
# Build a document with two pages
pdf = PdfFileReader(self.get_pdf_stream())
output = PdfFileWriter()
output.addPage(pdf.getPage(0))
output.addPage(pdf.getPage(0))
assert output.getNumPages() == 2
assert output.getPage(0).extractText().count('Test') == 1
buf = StringIO()
output.write(buf)
buf.seek(0)
rv = self.app.get('/')
self.assertEquals(rv.status_code, 200)
rv = self.app.post('/handleform',
data={'file': (buf, 'test.pdf')})
rv = self.combine_and_download(pages_sheet='2')
pdf_download = PdfFileReader(StringIO(rv.data))
self.assertEquals(pdf_download.getPage(0).extractText().count('Test'),
2)
self.assertEquals(pdf_download.getNumPages(), 1)
self.clean_up()
示例2: consume_files
# 需要导入模块: from pyPdf import PdfFileWriter [as 别名]
# 或者: from pyPdf.PdfFileWriter import getNumPages [as 别名]
def consume_files(filelist):
i = 0
while (len(filelist) > 0):
output = PdfFileWriter()
merge_pages_better(output, filelist)
outputstream = file(PREFIX_STR+str(i)+'.pdf', 'wb')
print "%s%d.pdf has %d pages" % (PREFIX_STR, i, output.getNumPages())
i = i + 1
output.write(outputstream)
outputstream.close()
return 1
示例3: merge_pdf
# 需要导入模块: from pyPdf import PdfFileWriter [as 别名]
# 或者: from pyPdf.PdfFileWriter import getNumPages [as 别名]
def merge_pdf(url_list):
# Download each PDF and merge them into one giant PDF, post this giant PDF to anonfiles.com, add URL to scraperwiki database
output = PdfFileWriter()
for url in url_list:
if url[0] == "http://www.cota.com/assets/Riding-Cota/Schedules/Current/083.pdf":
url[0] = "http://www.cota.com/assets/Riding-Cota/Schedules/Current/83.pdf"
url[1] = "83.pdf"
if url[0] == "http://www.cota.com/assets/Riding-Cota/Schedules/Current/039.pdf":
url[0] = "http://www.cota.com/assets/Riding-Cota/Schedules/Current/39.pdf"
url[1] = "39.pdf"
if url[0] == "http://www.cota.com/assets/Riding-Cota/Schedules/Current/021.pdf":
url[0] = "http://www.cota.com/assets/Riding-Cota/Schedules/Current/21.pdf"
url[1] = "21.pdf"
if url[0] == "http://www.cota.com/assets/Riding-Cota/Schedules/Current/016S.pdf":
url[0] = "http://www.cota.com/assets/Riding-Cota/Schedules/Current/16S.pdf"
url[1] = "16S.pdf"
if url[0] == "http://www.cota.com/assets/Riding-Cota/Schedules/Current/015.pdf":
url[0] = "http://www.cota.com/assets/Riding-Cota/Schedules/Current/15.pdf"
url[1] = "15.pdf"
pdf_file = os.system("wget %s" % url[0])
input1 = PdfFileReader(file('/tmp/%s' % url[1], "rb"))
numPages = input1.getNumPages()
print "number of pages = %s" % (numPages)
page1 = input1.getPage(0)
page2 = input1.getPage(1)
output.addPage(page1)
output.addPage(page2)
if numPages == 3:
page3 = input1.getPage(2)
output.addPage(page3)
final_page_count = output.getNumPages()
print "Number of Pages in Final = %s" % (final_page_count)
outputStream = file("/tmp/bus.pdf", "wb")
output.write(outputStream)
outputStream.close()
reply = os.system('curl -kF "[email protected];filename=bus.pdf" https://anonfiles.com/api/hotlink -o "reply.txt"')
with open('reply.txt', 'r') as f:
read_data = f.read()
data_dict = {
'Title':'Link to COTA Bus Schedule',
'URL':read_data,
}
scraperwiki.sqlite.save(unique_keys=['Title', 'URL'], data=data_dict)
示例4: splitPDF
# 需要导入模块: from pyPdf import PdfFileWriter [as 别名]
# 或者: from pyPdf.PdfFileWriter import getNumPages [as 别名]
def splitPDF(inputpdf, output_fn, start, end):
""" from the input pdf creates a new pdf file with the name output_fn
containing only the pages of the pdf from start to end
"""
outputpdf = PdfFileWriter()
print 'added pages ',
for i in xrange(start, end):
outputpdf.addPage(inputpdf.getPage(i))
print str(i) + ',',
print 'finished. printed', outputpdf.getNumPages(), 'pages'
outstream = file(output_fn, 'wb')
outputpdf.write(outstream)
outstream.close()
示例5: merge_pdfs
# 需要导入模块: from pyPdf import PdfFileWriter [as 别名]
# 或者: from pyPdf.PdfFileWriter import getNumPages [as 别名]
def merge_pdfs(output_name, files):
""" Merges files in the order given. Make sure to sort first."""
output = PdfFileWriter()
for f in files:
try:
i = PdfFileReader(file(f, "rb"))
except IOError as e:
print(e)
except PdfReadError as e:
print(e)
else:
for p in i.pages:
output.addPage(p)
if output.getNumPages():
ostream = file(output_name, "wb")
output.write(ostream)
ostream.close()
示例6: test_page_ranges
# 需要导入模块: from pyPdf import PdfFileWriter [as 别名]
# 或者: from pyPdf.PdfFileWriter import getNumPages [as 别名]
def test_page_ranges(self):
rv = self.app.get('/')
self.assertEquals(rv.status_code, 200)
pdf = PdfFileReader(self.get_pdf_stream())
# Build a document with twenty pages
output = PdfFileWriter()
page = pdf.getPage(0)
for i in range(1, 21):
new_page = CombineTestCase.replace_text(page, 'Test', 'Test %d' % i)
output.addPage(new_page)
assert output.getNumPages() == 20
buf = StringIO()
output.write(buf)
buf.seek(0)
rv = self.app.post('/handleform',
data={'file': (buf, 'test.pdf')},
follow_redirects=True)
ids = self.extract_ids_from_main_page(rv.data)
pages_kw = 'pages_%d' % ids[0]
rv = self.combine_and_download(**{pages_kw: '-5, 10, 12-14, 18-'})
pdf_download = PdfFileReader(StringIO(rv.data))
# Test ranges
ranges = [1, 2, 3, 4, 5, 10, 12, 13, 14, 18, 19, 20]
self.assert_(all(
(('Test %d' % page) in pdf_download.getPage(i).extractText())
for i, page in enumerate(ranges)))
self.assertEquals(pdf_download.getNumPages(), len(ranges))
self.clean_up()
示例7: range
# 需要导入模块: from pyPdf import PdfFileWriter [as 别名]
# 或者: from pyPdf.PdfFileWriter import getNumPages [as 别名]
for x in range(len(INPUT)) :
hackfile = 'editionHack/hack{0}.pdf'.format(x+OFFSET)
goodfile = 'editionHack/'+INPUT[x]+".pdf"
output = PdfFileWriter()
input1 = PdfFileReader(file(goodfile, "rb"))
page1 = input1.getPage(0)
watermark = PdfFileReader(file(hackfile, "rb"))
page1.mergePage(watermark.getPage(0))
output.addPage(page1)
outputStream = file("editionHack/finalPage{0}.pdf".format(x+OFFSET), "wb")
print "finalPage{0}.pdf".format(x+OFFSET)
output.write(outputStream)
outputStream.close()
output = PdfFileWriter()
for x in range(3,11) :
input1 = PdfFileReader(file('editionHack/finalPage{0}.pdf'.format(x), "rb"))
output.addPage(input1.getPage(0))
input1 = PdfFileReader(file('sitOzfarsWysr_a4.pdf', "rb"))
for x in range(input1.getNumPages()) :
output.addPage(input1.getPage(x))
if output.getNumPages() % 2 == 1 :
input1 = PdfFileReader(file('editionHack/blankPage.pdf', "rb"))
output.addPage(input1.getPage(0))
outputStream = file("editionHack/sowInterior.pdf".format(x), "wb")
output.write(outputStream)
outputStream.close()
示例8: PdfFileReader
# 需要导入模块: from pyPdf import PdfFileWriter [as 别名]
# 或者: from pyPdf.PdfFileWriter import getNumPages [as 别名]
})
# Add It
output._addObject(properties)
# Add back the one we deleted first
output._addObject(item)
address = PdfFileReader(file("input\\address\\"+fname, "rb"))
location = PdfFileReader(file("input\\location\\"+fname, "rb"))
print "Location Pages:", location.numPages
print "Address Pages:", address.numPages
if location.numPages > 1 :
print "Location has more than 1 page, exiting..."
sys.exit()
page = location.getPage(0)
for i in xrange(address.numPages):
#print ".",
output.addPage(address.getPage(i))
output.addPage(page)
# output should be double address
print "Output Pages:", output.getNumPages()
#if output.getNumPages() == (address.numPages *2):
if output.getNumPages() > 0:
outStream = file("output\\"+fname, "wb")
output.write(outStream)
outStream.close()
print "Generation Complete"
示例9: PdfFileWriter
# 需要导入模块: from pyPdf import PdfFileWriter [as 别名]
# 或者: from pyPdf.PdfFileWriter import getNumPages [as 别名]
# This is the pyPdf library. Install with: $ pip install pyPdf
from pyPdf import PdfFileWriter, PdfFileReader
# Open a writer object
output = PdfFileWriter()
# Load the pdf file(s) you want to input pages from
input1 = PdfFileReader(file("test.pdf", "rb"))
# Add some pages from your source/input files to the writer object
output.addPage(input1.getPage(8))
output.addPage(input1.getPage(15))
# For kicks, print the number of pages added to the console
print "number of pages is: %s " % output.getNumPages()
# Explain the kind of file this will be when outputted
outputStream = file("assembled_pdf.pdf", "wb")
# Write the actual output file
output.write(outputStream)
# Close the output file
outputStream.close()
示例10: write_file
# 需要导入模块: from pyPdf import PdfFileWriter [as 别名]
# 或者: from pyPdf.PdfFileWriter import getNumPages [as 别名]
page2 = output_pdf.addBlankPage(x/2, y)
page2.mergeTranslatedPage(p, -x/2, 0)
split_count = split_count + 1
else:
# Portrait, fine on its own
output_pdf.addPage(p)
progress.animate(amount=i)
progress.animate(amount=pages)
print 'Total pages: %d -> %d ' % (
pages,
output_pdf.getNumPages()
)
if split_count:
print '/-{ %d }-\\ double spreads split apart' % split_count
print 'Writing... here is a bird to keep you company'
def write_file():
# Write the file
output_file = file(input_base + '.split' + input_ext, "wb")
output_pdf.write(output_file)
output_file.close()
t = threading.Thread(target=write_file)
t.start()
示例11: range
# 需要导入模块: from pyPdf import PdfFileWriter [as 别名]
# 或者: from pyPdf.PdfFileWriter import getNumPages [as 别名]
batchnames.append("batch"+str(i)+".pdf")
# Loop through HouseDistricts
for i in range(1,100):
output = PdfFileWriter()
outputfilename = "pdfs/HD"+str(i)+".pdf"
for b in batchnames:
input_pdf = PdfFileReader(file("pdfs/"+b, "rb"))
with open('csvs/district_data.csv', 'rb') as csvfile:
district_reader = csv.reader(csvfile, delimiter=',', quotechar='"')
for row in district_reader:
if row[0] == b:
if row[9]== str(i):
output.addPage(input_pdf.getPage(int(row[1])-1))
if output.getNumPages() >0:
outputStream = file(outputfilename, "wb")
output.write(outputStream)
outputStream.close()
print "There are %s form letters from %s " % (output.getNumPages(), outputfilename)
# Loop through SenateDistricts
for i in range(1,34):
output = PdfFileWriter()
outputfilename = "pdfs/SD"+str(i)+".pdf"
for b in batchnames:
input_pdf = PdfFileReader(file("pdfs/"+b, "rb"))
with open('csvs/district_data.csv', 'rb') as csvfile:
district_reader = csv.reader(csvfile, delimiter=',', quotechar='"')
for row in district_reader: