def create_pdf(self): pdf = StringIO.StringIO() doc = SimpleDocTemplate(pdf) doc.leftMargin = 31 doc.rightMargin = 31 doc.topMargin = 390 doc.bottomMargin = 110 story = [] order_items = [["Artikelnr.", "Name", "Menge", "Preis", "Summe"]] for item in self.order.items.all(): amount = str(item.amount) + " " + item.product.unit price = currency(item.product_price_gross) total = currency(item.price_gross) order_items.append( [item.product.sku, item.product_name, amount, price, total]) order_items_table = Table(order_items, (80, 238, 60, 70, 70)) order_items_table.setStyle(dn_order_items_style) story.append(order_items_table) story.append(Spacer(1, 40)) # END story.append(Paragraph(getattr(settings, "DN_END"), styleN)) doc.build(story, onFirstPage=self.page, onLaterPages=self.page) pdf.seek(0) return pdf
def __init__(self, report: InterestTransferListReport, year: int, today: str): self.buffer = io.BytesIO() story = [] styles = getSampleStyleSheet() styleH1 = styles['Heading2'] styleH2 = styles['Heading3'] styleB = copy.deepcopy(styles['Normal']) styleB.spaceAfter = 0.1*cm styleB.fontName = 'Helvetica-Bold' doc = SimpleDocTemplate(self.buffer, pagesize=A4) doc.leftMargin = 1*cm doc.rightMargin = 1*cm doc.topMargin = 1*cm doc.bottomMargin = 1*cm story.append(Paragraph(f"Zinsen für das Jahr {year}", styleH1)) for data in report.per_contract_data: story.append(Paragraph(f"Direktkreditvertrag Nr. {data.contract.number}, {data.contract.contact}", styleH2)) story.append(Paragraph(f"Kontostand {today}: {euro(data.contract.balance)}", styleB)) story.append(Paragraph(f"Zinsberechung {year}:", styleB)) story.append(interest_year_table(data.interest_rows)) story.append(Spacer(1, 0.1*cm)) story.append(Paragraph(f"Zinsen {year}: {euro(data.interest)}", styleB)) story.append(Spacer(1, 0.5*cm)) story.append(Paragraph(f"SUMME ZINSEN {year}: {euro(report.sum_interest)}", styleB)) doc.build(story) self.buffer.seek(0)
def create_pdf(self): pdf = StringIO.StringIO() doc = SimpleDocTemplate(pdf) doc.leftMargin=31 doc.rightMargin=31 doc.topMargin=390 doc.bottomMargin=110 story = [] order_items = [["Artikelnr.", "Name", "Menge", "Preis", "Summe"]] for item in self.order.items.all(): amount = str(item.amount) + " " + item.product.unit price = currency(item.product_price_gross) total = currency(item.price_gross) order_items.append([item.product.sku, item.product_name, amount, price, total]) order_items_table = Table(order_items, (80, 238, 60, 70, 70)) order_items_table.setStyle(dn_order_items_style) story.append(order_items_table) story.append(Spacer(1, 40)) # END story.append(Paragraph(getattr(settings, "DN_END"), styleN)) doc.build(story, onFirstPage=self.page, onLaterPages=self.page) pdf.seek(0) return pdf
def genera_lettera(citazione): path_file = '%s/lettere/lett_%s%s.pdf' % (settings.DOCDIR, citazione['id_frase'], citazione['canzone']) row = len(citazione['testo'].split(''' ''')) print(citazione['canzone']) size = 6 if row <80 else 4 size = 0 if row < 35: size = 10 elif row < 55: size = 8 elif row < 60: size = 6 else: size = 4 size = int(6 + (100/row)) size = size if row < 80 else 6 size = 10 if row < 38 else size #citazione['autore'] = ' righe %s %%s' % row % size tabella_testo = [ [ par_nero("""{canzone}<br/><br/>""".format(**citazione), font=12, align=TA_CENTER, fontName='papyrus') ], [ #par_nero("{testo}".format(**citazione), font=size, lead=size, align=TA_CENTER, fontName='Times-BoldItalic') par_nero("{testo}".format(**citazione), font=size, lead=size, align=TA_CENTER, fontName='papyrus') ], [ #par_nero("{autore}".format(**citazione), font=8, align=TA_RIGHT) par_nero("{autore}".format(**citazione), font=8, align=TA_RIGHT, fontName='papyrus') ] ] style_row = TableStyle([]) #style_row.add('LINEABOVE', (0, 0), (-1, -1), 0.25, colors.grey) #style_row.add('LINEBELOW', (0, 0), (-1, -1), 0.25, colors.grey) #style_row.add('LINEAFTER', (0, 0), (-1, -1), 0.25, colors.grey) #style_row.add('LINEBEFORE', (0, 0), (-1, -1), 0.25, colors.grey) table = Table(tabella_testo, colWidths=12 * units.cm, style=style_row) doc = SimpleDocTemplate(path_file, pagesize=(13*units.cm, 21*units.cm)) margin_top = 0.5 if row > 60 else (90/row) doc.topMargin = units.cm * margin_top doc.bottomMargin = 0.5 *units.cm doc.build([table])
def create_pdf(self): pdf = StringIO.StringIO() doc = SimpleDocTemplate(pdf) doc.leftMargin=31 doc.rightMargin=31 doc.topMargin=390 doc.bottomMargin=110 story = [] order_items = [["Artikelnr.", "Name", "Menge", "Preis", "Summe"]] for item in self.order.items.all(): # Amount amount = str(item.amount) if item.product.unit: amount += " " + item.product.unit if item.product.active_packing_unit: amount += "\n(" + str(packages(item)) + " " + item.product.packing_unit_unit + ")" # Name item_name = item.product_name for property in item.product.get_displayed_properties(): item_name += "\n" + property["title"] + ": " + property["value"] + " " + property["unit"] for property in item.product.get_variant_properties(): item_name += "\n" + property["title"] + ": " + property["value"] + " " + property["unit"] if item.product.is_configurable_product(): for property in item.get_properties(): item_name += "\n" + property["title"] + ": " + property["value"] + property["unit"] + " " + property["price"] price = currency(item.product_price_gross) if item.product.price_unit: price += " / " + item.product.price_unit total = currency(item.price_gross) order_items.append([item.product.sku, item_name, amount, price, total]) if self.order.voucher_number: order_items.append(["", "Voucher", "1", currency(self.order.voucher_price), currency(self.order.voucher_price)]) order_items.append(["", "Versandart (" + self.order.shipping_method.name + ")", "1", currency(self.order.shipping_price), currency(self.order.shipping_price)]) order_items.append(["", "Zahlungsweise (" + self.order.payment_method.name + ")", "1", currency(self.order.payment_price), currency(self.order.payment_price)]) order_items.append(["", "", "", "Summe", currency(self.order.price)]) order_items.append(["", "", "", "Inkl. MwSt", currency(self.order.tax)]) order_items_table = Table(order_items, (80, 238, 60, 70, 70)) order_items_table.setStyle(in_order_items_style) story.append(order_items_table) story.append(Spacer(1, 40)) # END story.append(Paragraph(getattr(settings, "IN_END"), styleN)) doc.build(story, onFirstPage=self.page, onLaterPages=self.page) pdf.seek(0) return pdf
def render_to_pdf(self, context): response = HttpResponse(content_type="application/pdf") self.page_width, self.page_height = defaultPageSize doc = SimpleDocTemplate(response, pagesize=defaultPageSize) self.styles = getSampleStyleSheet() self.styles["h1"].alignment = 1 self.styles["h2"].alignment = 1 elements = self.get_elements(context["results"]) if self.competition.sponsors.exists(): doc.bottomMargin = 1.5 * inch doc.build(elements, onFirstPage=self.draw_title, onLaterPages=self.draw_title) return response
def get_document(args, rightMargin=2.5*mm, leftMargin = 2.5*mm, topMargin = 2.5*mm, bottomMargin = 2.5*mm): save_path = f'{args.title}.pdf' doc = SimpleDocTemplate(save_path) doc.title = args.title doc.rightMargin = rightMargin doc.leftMargin = leftMargin doc.topMargin = topMargin doc.bottomMargin = bottomMargin doc.width = A4[0] - (doc.rightMargin + doc.leftMargin) doc.height = A4[1] - (doc.topMargin + doc.bottomMargin) return doc
def start_pdf(mdata): global doc, elements, dwidth, dheight pdf_file = os.path.join(PDF_DIR, mdata['title'] + '.pdf') doc = SimpleDocTemplate(pdf_file, pagesize=letter) elements = [] dwidth, dheight = letter # margins doc.topMargin = TOP_MARGIN doc.leftMargin = LEFT_MARGIN doc.bottomMargin = TOP_MARGIN doc.rightMargin = LEFT_MARGIN
def generar_etiquetas(file_output, lista_productos, page_renglones, page_columnas, start_position="a1"): etiquetas = [] etiquetas_x_hoja = page_renglones * page_columnas doc = SimpleDocTemplate(file_output, pagesize=letter) doc.topMargin = 1.1 * cm doc.bottomMargin = 0 doc.rightMargin = 3.0 * cm # container for the 'Flowable' objects elements = [] cantidad_celdas_vacias = ((ord(start_position[0]) - ord('a')) * 3) + ( (ord(start_position[1]) - ord('0')) - 1) etiquetas = etiquetas + [None for _ in range(cantidad_celdas_vacias)] for producto in lista_productos: etiquetas = etiquetas + [ producto.copy() for _ in range(producto['cantidad']) ] while len(etiquetas) >= etiquetas_x_hoja: pagina = generate_page_pdf(etiquetas[0:etiquetas_x_hoja], page_columnas) elements.append(pagina) elements.append(PageBreak()) print "tamaño buffer etiquetas ", len( etiquetas[0:etiquetas_x_hoja]) del etiquetas[0:etiquetas_x_hoja] if len(etiquetas) > 0: etiquetas = etiquetas + [ None for _ in range(etiquetas_x_hoja - len(etiquetas)) ] pagina = generate_page_pdf(etiquetas[0:etiquetas_x_hoja], page_columnas) elements.append(pagina) # write the document to disk doc.build(elements) return etiquetas
def create_pdf(self): pdf = StringIO.StringIO() doc = SimpleDocTemplate(pdf) doc.leftMargin = 31 doc.rightMargin = 31 doc.topMargin = 390 doc.bottomMargin = 110 story = [] order_items = [["Artikelnr.", "Name", "Menge", "Preis", "Summe"]] for item in self.order.items.all(): # Amount amount = str(item.amount) if item.product.unit: amount += " " + item.product.unit if item.product.active_packing_unit: amount += "\n(" + str(packages( item)) + " " + item.product.packing_unit_unit + ")" # Name item_name = item.product_name for property in item.product.get_displayed_properties(): item_name += "\n" + property["title"] + ": " + property[ "value"] + " " + property["unit"] for property in item.product.get_variant_properties(): item_name += "\n" + property["title"] + ": " + property[ "value"] + " " + property["unit"] if item.product.is_configurable_product(): for property in item.get_properties(): item_name += "\n" + property["title"] + ": " + property[ "value"] + property["unit"] + " " + property["price"] price = currency(item.product_price_gross) if item.product.price_unit: price += " / " + item.product.price_unit total = currency(item.price_gross) order_items.append( [item.product.sku, item_name, amount, price, total]) if self.order.voucher_number: order_items.append([ "", "Voucher", "1", currency(self.order.voucher_price), currency(self.order.voucher_price) ]) order_items.append([ "", "Versandart (" + self.order.shipping_method.name + ")", "1", currency(self.order.shipping_price), currency(self.order.shipping_price) ]) order_items.append([ "", "Zahlungsweise (" + self.order.payment_method.name + ")", "1", currency(self.order.payment_price), currency(self.order.payment_price) ]) order_items.append(["", "", "", "Summe", currency(self.order.price)]) order_items.append( ["", "", "", "Inkl. MwSt", currency(self.order.tax)]) order_items_table = Table(order_items, (80, 238, 60, 70, 70)) order_items_table.setStyle(in_order_items_style) story.append(order_items_table) story.append(Spacer(1, 40)) # END story.append(Paragraph(getattr(settings, "IN_END"), styleN)) doc.build(story, onFirstPage=self.page, onLaterPages=self.page) pdf.seek(0) return pdf
def __init__(self, report: InterestTransferListReport, year: int, today: str): self.snippets = get_custom_texts() self.buffer = io.BytesIO() self.today = today story = [] self._setup_styles() doc = SimpleDocTemplate(self.buffer, pagesize=A4) doc.leftMargin = 1.5 * cm doc.rightMargin = 1.5 * cm doc.topMargin = 1.0 * cm doc.bottomMargin = 1.5 * cm for data in report.per_contract_data: story.extend(self._header(data)) story.append(Spacer(1, 1.0 * cm)) story.append( Paragraph( f"Kontostand Direktkreditvertrag Nr. {data.contract.number}", self.styleH2)) story.append(Spacer(1, 1.0 * cm)) story.append( Paragraph(f"Guten Tag {data.contract.contact.name}, ", self.styleN)) story.append(Spacer(1, 0.3 * cm)) story.append( Paragraph(( f"der Kontostand des Direktkreditvertrags Nr. {data.contract.number} beträgt heute, " f" am {today} {euro(data.contract.balance)}. "), self.styleN)) story.append( Paragraph( f"Die Zinsen für das Jahr {year} berechnen sich wie folgt:", self.styleN)) story.append(Spacer(1, 0.3 * cm)) story.append(interest_year_table(data.interest_rows, narrow=True)) story.append(Spacer(1, 0.3 * cm)) story.append( Paragraph(f"<b>Zinsen {year}:</b> {euro(data.interest)}", self.styleN)) story.append(Spacer(1, 0.5 * cm)) story.append( Paragraph(( "Wir werden die Zinsen in den nächsten Tagen auf das im Vertrag angegebene Konto " "überweisen. Bitte beachten Sie, dass Sie sich selbst um die Abführung von " "Kapitalertragssteuer und Solidaritätszuschlag kümmern sollten, da wir das nicht " "übernehmen können. "), self.styleN)) story.append(Spacer(1, 0.5 * cm)) story.append(Paragraph("Vielen Dank!", self.styleN)) story.append(Spacer(1, 1.5 * cm)) story.append(Paragraph("Mit freundlichen Grüßen", self.styleN)) story.append(Spacer(1, 1.0 * cm)) story.append(Paragraph(self.snippets['your_name'], self.styleN)) story.append( Paragraph(f"für die {self.snippets['gmbh_name']}", self.styleN)) story.append(Spacer(1, 0.3 * cm)) story.append(PageBreak()) doc.build(story, onFirstPage=self._draw_footer, onLaterPages=self._draw_footer) self.buffer.seek(0)
def create_report(self, info): # Converting to PDF # document theme if local: doc = SimpleDocTemplate('{}_TestReport.pdf'.format(info["serialNo"])) else: doc = SimpleDocTemplate('/home/test/reports/{}_TestReport.pdf'.format(info["serialNo"])) doc.topMargin = 20 doc.bottomMargin = 25 doc.leftMargin = 25 doc.rightMargin = 25 doc.allowSplitting = False header_path = self.project_path + "/" + "header.png" if os.path.exists(header_path): header = Image(header_path, 8 * inch, 1 * inch) header.hAlign = "CENTRE" self.elements.append(header) self.elements.append(Spacer(1, 20)) else: logging.warning("Header not found") self.elements.append(self.draw_line(colors.lightgrey)) self.elements.append(Spacer(1, 1)) self.elements.append(self.draw_line(colors.lightgrey)) self.elements.append(Spacer(1, 3)) self.elements.append(Paragraph("Serial No: " + info["serialNo"], self.styles['Title'])) self.elements.append(self.draw_line(colors.lightgrey)) self.elements.append(Spacer(1, 1)) self.elements.append(self.draw_line(colors.lightgrey)) self.elements.append(Spacer(1, 20)) # Create Tables for each test # Device Info Table if info["deviceInfo"]: self.heading_block("Device Info") dev_table = pd.DataFrame(info["deviceInfo"], index=[0]) dev_table = dev_table.T dev_table.reset_index(inplace=True) dev_table.columns = ["Item", "Detail"] dev_table.set_index(["Item"], inplace=True) dev_table.replace("", "N/A", inplace=True) self.draw_table(dev_table) # Mac Table if info["macInfo"]: self.heading_block("MAC Info") self.draw_table(info["macInfo"], column=["interface", "macaddr"]) # Operation Table if info["operationInfo"]: self.heading_block("Operation Details") opt_table = pd.DataFrame(info["operationInfo"], index=[0]) opt_table = opt_table.T opt_table.reset_index(inplace=True) opt_table.columns = ["Operation", "Status"] opt_table.set_index(["Operation"], inplace=True) opt_table.replace("", "N/A", inplace=True) self.draw_table(opt_table) # Test Table if info["testInfo"]: self.heading_block("Test Details") test_table = pd.DataFrame(info["testInfo"], index=[0]) test_table = test_table.T test_table.reset_index(inplace=True) test_table.columns = ["Test", "Status"] test_table.set_index(["Test"], inplace=True) test_table.replace("", "N/A", inplace=True) self.draw_table(test_table) # Hardware Test Table if info["hwtestInfo"]: self.heading_block("Hardware Test Details") self.draw_table(info["hwtestInfo"], column=["item", "result", "detail"]) # Burn test details if info["burntestInfo"]: self.heading_block("Burn Test Details") self.draw_table(info["burntestInfo"], column=["item", "result", "detail"]) # Last test details if info["lasttestInfo"]: self.heading_block("Last Test Details") self.draw_table(info["lasttestInfo"], column=["item", "result", "detail"]) # LanBurn Throughput Table self.heading_block("LanBurn Throughput") speed_table = pd.DataFrame.from_dict(info["performancestatsInfo"]) speed_table.columns = [x.title() for x in speed_table.columns] speed_table.set_index(["Nic"], inplace=True) self.draw_table(speed_table) # LanBurn Throughput Bar Chart self.elements.append(Spacer(1, 30)) filename = "lanburn.png" self.throughput_bar_chart(speed_table, self.project_path, filename) im = Image(filename, 4 * inch, 2.5 * inch) self.elements.append(im) if self.render_pdf: # Build all the elements to create a PDF doc.build(self.elements)
print() if not args.output: exit() from reportlab.platypus import PageBreak, Paragraph, SimpleDocTemplate, Table, TableStyle from reportlab.lib import colors from reportlab.lib.pagesizes import inch, letter from reportlab.lib.styles import getSampleStyleSheet print('Writing report to %s ...' % (args.output, )) styles = getSampleStyleSheet() doc = SimpleDocTemplate(args.output, pagesize=letter) doc.bottomMargin = 0.85 * inch elements = [] header = Paragraph('Transactions', styles['Heading1']) elements.append(header) balance = Decimal(0) rows = [['Date', 'Description', 'Credit', 'Debit', 'Balance']] ts = TableStyle([('ALIGNMENT', (2, 0), (-1, -1), 'RIGHT'), ('LINEBELOW', (0, 0), (-1, 0), 1.0, colors.grey)]) data = sorted(set(data)) # FIXME: Splits are not unique, unfortunately. for date, num, split in data: trans = split.parent other = split.GetOtherSplit() val = split.GetValue()