pdf - Force add new page in pyFPDF using python -


i'm using pyfpdf templates generate pdf want print 2 pages not 1 possible! example:

elements = [     { 'name': 'company_logo', 'type': 'i', 'x1': 20.0, 'y1': 17.0, 'x2': 78.0, 'y2': 30.0, 'font': none, 'size': 0.0, 'bold': 0, 'italic': 0, 'underline': 0, 'foreground': 0, 'background': 0, 'align': 'i', 'text': 'logo', 'priority': 2, },     { 'name': 'company_name', 'type': 't', 'x1': 17.0, 'y1': 32.5, 'x2': 115.0, 'y2': 37.5, 'font': 'arial', 'size': 12.0, 'bold': 1, 'italic': 0, 'underline': 0, 'foreground': 0, 'background': 0, 'align': 'i', 'text': '', 'priority': 2, },     { 'name': 'box', 'type': 'b', 'x1': 15.0, 'y1': 15.0, 'x2': 185.0, 'y2': 260.0, 'font': 'arial', 'size': 0.0, 'bold': 0, 'italic': 0, 'underline': 0, 'foreground': 0, 'background': 0, 'align': 'i', 'text': none, 'priority': 0, },     { 'name': 'box_x', 'type': 'b', 'x1': 95.0, 'y1': 15.0, 'x2': 105.0, 'y2': 25.0, 'font': 'arial', 'size': 0.0, 'bold': 1, 'italic': 0, 'underline': 0, 'foreground': 0, 'background': 0, 'align': 'i', 'text': none, 'priority': 2, },     { 'name': 'line1', 'type': 'l', 'x1': 100.0, 'y1': 25.0, 'x2': 100.0, 'y2': 57.0, 'font': 'arial', 'size': 0, 'bold': 0, 'italic': 0, 'underline': 0, 'foreground': 0, 'background': 0, 'align': 'i', 'text': none, 'priority': 3, }, ] #here instantiate template , define header f = template(format="a4", elements=elements,              title="sample invoice") f.add_page() #we fill of fields of template information want #note access elements treating template instance "dict" f["company_name"] = "sample company" f["company_logo"] = "pyfpdf/tutorial/logo.png"  #and render page f.render("./template.pdf") 

all data appears in same pdf when use method, want of elements print on second page of pdf? how can , help?!

you can separate elements in 2 different lists (elements1, elements2) , use each 1 in different templates , merge them using pypdf2

f1 = template(format="a4", elements=elements1,          title="sample invoice")  f2 = template(format="a4", elements=elements2,          title="sample invoice")  pypdf2 import pdffilemerger, pdffilereader stringio import stringio  page1 = stringio() page2 = stringio() final_pdf = stringio()  page1.write(f1.render('doc1.pdf',dest='s')) page2.write(f2.render('doc2.pdf',dest='s'))  pages = [ pdffilereader(page1), pdffilereader(page2) ] pdf_merger = pdffilemerger()  page in pages:     pdf_merger.append(page)  pdf_merger.write(final_pdf) 

you can final output final_pdf.getvalue().


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -