当前位置: 首页>>代码示例>>Python>>正文


Python PdfFileReader.getPage方法代码示例

本文整理汇总了Python中pyPdf.PdfFileReader.getPage方法的典型用法代码示例。如果您正苦于以下问题:Python PdfFileReader.getPage方法的具体用法?Python PdfFileReader.getPage怎么用?Python PdfFileReader.getPage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyPdf.PdfFileReader的用法示例。


在下文中一共展示了PdfFileReader.getPage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: reshuffle

# 需要导入模块: from pyPdf import PdfFileReader [as 别名]
# 或者: from pyPdf.PdfFileReader import getPage [as 别名]
def reshuffle(output_directory, input_file, filename):
    output_pdf = PdfFileWriter()

    with open(input_file, 'rb') as readfile:

        input_pdf = PdfFileReader(readfile)
        total_pages = input_pdf.getNumPages()

        if total_pages == 7:

            print filename,

            if "hardest_jet_phi_all_linear" in filename or "hardest_jet_eta_all_linear" in filename or "hardest_jet_pT_all_linear" in filename or "hardest_jet_pT_jec_all_linear" in filename or "area" in filename or "jec" in filename or "pfc_neutral_0_100_pT" in filename or "pfc_charged_0_100_pT" in filename or "pfc_neutral_0_5_pT" in filename or "pfc_charged_0_5_pT" in filename:
                output_pdf.addPage(input_pdf.getPage(4))
                output_pdf.addPage(input_pdf.getPage(5))
                output_pdf.addPage(input_pdf.getPage(6))
                print "85"
            else:
                output_pdf.addPage(input_pdf.getPage(5))
                output_pdf.addPage(input_pdf.getPage(4))
                output_pdf.addPage(input_pdf.getPage(6))
                print "150"

            for i in range(0, 4):
                output_pdf.addPage(input_pdf.getPage(i))

            with open(output_directory + filename, "wb") as writefile:
                output_pdf.write(writefile)
开发者ID:tripatheea,项目名称:MODAnalyzer,代码行数:30,代码来源:reshuffle_pdfs.py

示例2: merge

# 需要导入模块: from pyPdf import PdfFileReader [as 别名]
# 或者: from pyPdf.PdfFileReader import getPage [as 别名]
def merge(fppath, bppath, outputpath, no_delete, fed_backwards):
  fpfile = PdfFileReader(open(fppath))
  bpfile = PdfFileReader(open(bppath))

  outputfile = PdfFileWriter()

  outputpages = []
  for i in range(fpfile.getNumPages()):
    backpages = True
    try:
      outputpages.append(fpfile.getPage(i))
      if backpages:
        if fed_backwards:
          outputpages.append(bpfile.getPage(bpfile.getNumPages() - i - 1))
        else:
          outputpages.append(bpfile.getPage(i))
    except IndexError:
      backpages = False

  if not no_delete:
    outputpages = [page for page in outputpages if page.extractText() != '']

  [outputfile.addPage(page) for page in outputpages]

  outputfile.write(open(os.path.expanduser(outputpath), 'w'))
开发者ID:mgarriott,项目名称:PDFMerger,代码行数:27,代码来源:merge.py

示例3: test_two_on_one_page

# 需要导入模块: from pyPdf import PdfFileReader [as 别名]
# 或者: from pyPdf.PdfFileReader import getPage [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()
开发者ID:cburgmer,项目名称:pdfserver,代码行数:28,代码来源:tests.py

示例4: test_concat_pdf_files

# 需要导入模块: from pyPdf import PdfFileReader [as 别名]
# 或者: from pyPdf.PdfFileReader import getPage [as 别名]
    def test_concat_pdf_files( self ):
        try:
            os.unlink( r"docs/c.pdf" )
        except:
            pass
        self.assertTrue( True )
        input_a = PdfFileReader( file( r"docs/a.pdf", 'rb' ) )
        input_b = PdfFileReader( file( r"docs/b.pdf", 'rb' ) )

        output = PdfFileWriter()

        for x in range( 0, input_a.getNumPages() ):
            output.addPage( input_a.getPage( x ) )
        for x in range( 0, input_b.getNumPages() ):
            output.addPage( input_b.getPage( x ) )

        outputStream = file( r"docs/c.pdf", 'wb' )
        output.write( outputStream )
        outputStream.close()
        
        count = input_a.getNumPages() + input_b.getNumPages()
        
        check = PdfFileReader( file( r"docs/c.pdf", 'rb' ) )
        self.assertEqual( count, check.getNumPages() )
        os.unlink( r"docs/c.pdf" )
开发者ID:bkulyk,项目名称:pyMailMergeService,代码行数:27,代码来源:testPyPDF.py

示例5: add_guides

# 需要导入模块: from pyPdf import PdfFileReader [as 别名]
# 或者: from pyPdf.PdfFileReader import getPage [as 别名]
    def add_guides(self):
        pdf_in = PdfFileReader(open('sig.pdf', 'rb'))
        pdf_out = PdfFileWriter()

        for i in xrange(pdf_in.getNumPages()):
            page = pdf_in.getPage(i)
            if not i:
                guides = StringIO()

                if self.args.longarm:
                    create_pdf(
                        guides, a4lwidth_pt, a4lheight_pt, generate_longarm())
                else:
                    if self.args.a5:
                        w, h = a5width_pt, a5height_pt
                    else:
                        w, h = a4lwidth_pt, a4lheight_pt
                    create_pdf(guides, w, h, generate_shortarm(
                        self.args.a5, bool(self.args.signature)))

                pdf_guides = PdfFileReader(guides)
                page.mergePage(pdf_guides.getPage(0))
            pdf_out.addPage(page)

        pdf_out.write(open('sigs.pdf', 'wb'))
开发者ID:pb-,项目名称:mkbooklet,代码行数:27,代码来源:main.py

示例6: make_Cert

# 需要导入模块: from pyPdf import PdfFileReader [as 别名]
# 或者: from pyPdf.PdfFileReader import getPage [as 别名]
def make_Cert(code, redeem_for):
	packet = StringIO.StringIO()
	# create a new PDF with Reportlab

	can = canvas.Canvas(packet, pagesize=letter)
	can.setFont('Helvetica', 32)
	can.drawString(280,540, code)
	can.setFont('Helvetica', 32)
	can.drawString(220,300, redeem_for)
	can.save()

	#move to the beginning of the StringIO buffer
	packet.seek(0)
	new_pdf = PdfFileReader(packet)
	# read your existing PDF
	existing_pdf = PdfFileReader(file("cert.pdf", "rb"))
	output = PdfFileWriter()
	# add the "watermark" (which is the new pdf) on the existing page
	page = existing_pdf.getPage(0)
	page.mergePage(new_pdf.getPage(0))
	output.addPage(page)
	# finally, write "output" to a real file
	outputStream = file(redeem_for.replace(" ", "_") + "_cert.pdf", "wb")
	output.write(outputStream)
	outputStream.close()
开发者ID:kmax12,项目名称:lts,代码行数:27,代码来源:make_gift.py

示例7: add_footer_pdf

# 需要导入模块: from pyPdf import PdfFileReader [as 别名]
# 或者: from pyPdf.PdfFileReader import getPage [as 别名]
def add_footer_pdf(in_fname, op_fname, imgPath):
	from pyPdf import PdfFileWriter, PdfFileReader
	from reportlab.pdfgen import canvas
	from StringIO import StringIO
	
	output = PdfFileWriter()
	
	# Using ReportLab to insert image into PDF
	imgTemp1 = StringIO()
	imgDoc1 = canvas.Canvas(imgTemp1)
	
	# Draw image on Canvas and save PDF in buffer
	imgDoc1.drawImage(imgPath, 210, 20, 155, 35)    
	imgDoc1.save()
	
	overlay1 = PdfFileReader(StringIO(imgTemp1.getvalue())).getPage(0)
	
	in_file = PdfFileReader(file(in_fname,"rb"))
	n_pg = in_file.getNumPages() - 1
	
	page = in_file.getPage(0)
	output.addPage(page)
	
	# Use PyPDF to merge the image-PDF into the template
	for i in range(n_pg):
		page = in_file.getPage(i+1)
		page.mergePage(overlay1)
		output.addPage(page)
		
		#Save the result
		
		outputStream = file(op_fname,"w")
		output.write(outputStream)
		outputStream.close()
开发者ID:swaratechnologies,项目名称:PyPerFin,代码行数:36,代码来源:misc_utils.py

示例8: __call__

# 需要导入模块: from pyPdf import PdfFileReader [as 别名]
# 或者: from pyPdf.PdfFileReader import getPage [as 别名]
    def __call__(self, data, attachments=[], pages=None):
        self.rendered = {}
        for field, ctx in self.fields.items():
            if "template" not in ctx:
                continue

            self.context = ctx
            kwargs = self.template_args(data)
            template = self.context["template"]

            try:
                rendered_field = template.render(**kwargs)
            except Exception as err:
                logger.error("%s: %s %s", field, template, err)
            else:
                # Skip the field if it is already rendered by filter
                if field not in self.rendered:
                    self.rendered[field] = rendered_field

        filled = PdfFileReader(self.exec_pdftk(self.rendered))
        for pagenumber, watermark in self.watermarks:
            page = filled.getPage(pagenumber)
            page.mergePage(watermark)

        output = PdfFileWriter()
        pages = pages or xrange(filled.getNumPages())
        for p in pages:
            output.addPage(filled.getPage(p))

        for attachment in attachments:
            output.addBlankPage().mergePage(attachment.pdf())

        return output
开发者ID:Jenselme,项目名称:pdfjinja,代码行数:35,代码来源:pdfjinja.py

示例9: generate

# 需要导入模块: from pyPdf import PdfFileReader [as 别名]
# 或者: from pyPdf.PdfFileReader import getPage [as 别名]
def generate(donor):
    os.system('mkdir -p output')
    donor_url = donor.replace(' ','%20')
    page1 = 'output/%s1' % (donor.replace(' ','-').lower())
    page2 = 'output/%s2' % (donor.replace(' ','-').lower())

    combined = 'output/%s.pdf' % (donor.replace(' ','-').lower())
    if os.path.exists(combined): return

    os.system('cp "%s" "%s.svg"' % (page1_svg, page1))
    os.system('sed "s|/France/|/%s/|" "%s" > "%s.svg"' % (donor_url, page1_svg, page1))
    os.system('inkscape  --file="%s.svg" --verb=za.co.widgetlabs.update --verb=FileSave --verb=FileQuit 2> /dev/null' % (page1))
    os.system('inkscape --file="%s.svg" --export-pdf="%s.pdf" 2> /dev/null' % (page1, page1))
    os.system('cp "%s" "%s.svg"' % (page2_svg, page2))
    os.system('sed "s|/France/|/%s/|" "%s" > "%s.svg"' % (donor_url, page2_svg, page2))
    os.system('inkscape  --file="%s.svg" --verb=za.co.widgetlabs.update --verb=FileSave --verb=FileQuit 2> /dev/null' % (page2))
    os.system('inkscape --file="%s.svg" --export-pdf="%s.pdf" ' % (page2, page2))
    # Merge pages
    input1 = PdfFileReader(file('%s.pdf' % (page1), 'rb'))
    input2 = PdfFileReader(file('%s.pdf' % (page2), 'rb'))
    output = PdfFileWriter()
    output.addPage(input1.getPage(0))
    output.addPage(input2.getPage(0))
    outputStream = file(combined, 'wb')
    output.write(outputStream)
    outputStream.close()
    sleep(2)
开发者ID:adieyal,项目名称:who-scorecards,代码行数:29,代码来源:generate.py

示例10: rewrite

# 需要导入模块: from pyPdf import PdfFileReader [as 别名]
# 或者: from pyPdf.PdfFileReader import getPage [as 别名]
    def rewrite(self, context, font={'name': 'Times-Roman', 'size': 11}):

        packet = StringIO.StringIO()
        # create a new PDF with Reportlab
        can = canvas.Canvas(packet, pagesize=letter)
        can.setFont(font['name'], font['size'])
        for i in context:
            can.drawString(i['x'], i['y'], i['value'])
        can.save()

        # move to the beginning of the StringIO buffer
        packet.seek(0)
        new_pdf = PdfFileReader(packet)
        # read your existing PDF
        existing_pdf = PdfFileReader(file(self.path, "rb"))
        output = PdfFileWriter()
        # merge the new file with the existing
        page = existing_pdf.getPage(0)
        page.mergePage(new_pdf.getPage(0))
        output.addPage(page)
        # finally, write "output" to a real file
        outputStream = file(self.destination, "wb")
        output.write(outputStream)
        outputStream.close()

        return True
开发者ID:diegoloredo,项目名称:pyPdfFinder,代码行数:28,代码来源:writer.py

示例11: pdf_watermark_fast_first_page

# 需要导入模块: from pyPdf import PdfFileReader [as 别名]
# 或者: from pyPdf.PdfFileReader import getPage [as 别名]
    def pdf_watermark_fast_first_page(self, pathname, Wm_f, wt1='',**kwargs):
        try :
            url_watermark=kwargs['url_wtm']
        except:pass
        from pyPdf import PdfFileWriter, PdfFileReader
        import StringIO
        from reportlab.pdfgen import canvas
        from reportlab.lib.pagesizes import letter

        packet = StringIO.StringIO()
        # create a new PDF with Reportlab
        can = canvas.Canvas(packet, pagesize=letter)
        can.drawString(10, 100, url_watermark)
        can.save()

        #move to the beginning of the StringIO buffer
        packet.seek(0)
        new_pdf = PdfFileReader(packet)
        # read your existing PDF
        existing_pdf = PdfFileReader(file(pathname, "rb"))
        output = PdfFileWriter()
        # add the "watermark" (which is the new pdf) on the existing page
        page = existing_pdf.getPage(0)
        page.mergePage(new_pdf.getPage(0))
        output.addPage(page)
        # finally, write "output" to a real file
        outputStream = file(Wm_f, "wb")
        # import sys;sys.setrecursionlimit(11500)
        output.write(outputStream)
        outputStream.close()
        return Wm_f
开发者ID:Heroku-elasa,项目名称:heroku-buildpack-python-ieee-new,代码行数:33,代码来源:save_source.py

示例12: Packet

# 需要导入模块: from pyPdf import PdfFileReader [as 别名]
# 或者: from pyPdf.PdfFileReader import getPage [as 别名]
class Packet(object):
	def __init__(self, results_pdf):
		self.results_pdf = PdfFileReader(open(results_pdf, "rb"))
		self.num_pages = self.results_pdf.getNumPages()
		self.result_list = self.result_string.split('\n')
		self.entry_start = 0


	@property
	def num_rounds(self):
		first_entry = self.results_pdf.getPage(0).extractText().split('\n')[0]
		i = len(first_entry)-1
		while i >= 0:
			if first_entry[i] in digits:
				return int(first_entry[i])
			i-=1
	
	@property 
	def result_string(self):
		result_string = ""
		for i in range(0, self.num_pages):
			result_string+=self.results_pdf.getPage(i).extractText()
		return result_string
	
	def next_entry(self):
		school_code = school_codes(self.result_list[self.entry_start])
		start, end = self.entry_start+1, self.entry_start+self.num_rounds+2
		rest = self.result_list[start:end]
		self.entry_start+=self.num_rounds+2 
		return [school_code] + rest
开发者ID:AlonDaks,项目名称:fd-pdf-to-csv,代码行数:32,代码来源:pdf2csv.py

示例13: render

# 需要导入模块: from pyPdf import PdfFileReader [as 别名]
# 或者: from pyPdf.PdfFileReader import getPage [as 别名]
 def render(self):
     output = PdfFileWriter()
     base1 = "%s/lib/%s" % (path.dirname(__file__), "kfza_base.pdf")
     base1 = open(base1, 'rb')
     b1_pdf = PdfFileReader(base1)
     wm = b1_pdf.getPage(0)
     p1 = PdfFileReader(self.generate_page_one())
     page1 = p1.getPage(0)
     page1.mergePage(wm)
     output.addPage(page1)
     bpdf = "%s/lib/%s" % (path.dirname(__file__), self.base_pdf)
     with open(bpdf, 'rb') as pdf:
         pf = PdfFileReader(pdf)
         if pf.isEncrypted:
             pf.decrypt('')
         for page in range(pf.getNumPages()):
             output.addPage(pf.getPage(page))
         if self.context.course.extra_questions:
             b1_pdf = PdfFileReader(base1)
             wm = b1_pdf.getPage(0)
             p1 = PdfFileReader(self.generate_page_one())
             page1 = p1.getPage(1)
             page1.mergePage(wm)
             output.addPage(page1)
         ntf = TemporaryFile()
         output.write(ntf)
     ntf.seek(0)
     base1.close()
     return ntf
开发者ID:novareto,项目名称:nva.psyquizz,代码行数:31,代码来源:offline.py

示例14: addPdfOverlay

# 需要导入模块: from pyPdf import PdfFileReader [as 别名]
# 或者: from pyPdf.PdfFileReader import getPage [as 别名]
	def addPdfOverlay(self, pdf_doc, overlay_doc, output_doc, repeatOverlay=False):
		'''
			Essentially merging two PDF documents.
			
			pdf_doc: (string)
				Path to PDF document.
			overlay_doc: (string)
				Path to PDF overlay document to overlay pdf_doc.
			repeatOverlay: (boolean)
				If set to True, page 1 of the overlay document is repeated
				for each page of the pdf_doc. (default: False)
		'''
		pdf = PdfFileReader(file(pdf_doc, "rb"))
		pdf_overlay = PdfFileReader(file(overlay_doc, "rb"))
		page_cnt = pdf.numPages
		if repeatOverlay:
			overlay_pages = [pdf_overlay.getPage(0) for n in range(page_cnt)]
		else:
			overlay_pages = pdf_overlay.pages
		outputWriter = PdfFileWriter()
		for n in range(page_cnt):
			pg = pdf.getPage(n)
			pg.mergePage(overlay_pages[n])
			outputWriter.addPage(pg)
		
		# Output
		outputStream = file(output_doc, "wb")
		outputWriter.write(outputStream)
		
		# Close streams
		outputStream.close()
		pdf.stream.close()
		pdf_overlay.stream.close()
开发者ID:gridcell,项目名称:PDFUtils,代码行数:35,代码来源:pdfutils.py

示例15: save_ready_template

# 需要导入模块: from pyPdf import PdfFileReader [as 别名]
# 或者: from pyPdf.PdfFileReader import getPage [as 别名]
def save_ready_template(request, id):
    person_print = FIO.objects.get(id=id)
    packet = StringIO.StringIO()
    # create a new PDF with Reportlab
    can = canvas.Canvas(packet, pagesize=letter)
    can.drawString(284, 579, "{} {}".format(person_print.name, person_print.surname))
    can.showPage()
    can.drawString(260, 494, "{} {}".format(person_print.name, person_print.surname))
    can.showPage()
    can.save()
    # move to the beginning of the StringIO buffer
    packet.seek(0)
    new_pdf = PdfFileReader(packet)
    # read your existing PDF
    existing_pdf = PdfFileReader(file("/Users/danilakimov/Desktop/template1.pdf", "rb"))
    output = PdfFileWriter()
    # add the "watermark" (which is the new pdf) on the existing page
    page = existing_pdf.getPage(0)
    page.mergePage(new_pdf.getPage(0))
    output.addPage(page)
    page = existing_pdf.getPage(1)
    page.mergePage(new_pdf.getPage(1))
    output.addPage(page)
    # finally, write "output" to a real file
    outputStream = file("/Users/danilakimov/Desktop/readytemplate.pdf", "wb")
    output.write(outputStream)
    outputStream.close()
    return render(request, 'template_page.html', {'person_template': person_print})
开发者ID:bobbiblabbi,项目名称:auto_v3,代码行数:30,代码来源:views.py


注:本文中的pyPdf.PdfFileReader.getPage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。