Beispiel #1
0
    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)
Beispiel #2
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
Beispiel #3
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
Beispiel #4
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
            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
Beispiel #5
0
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
Beispiel #7
0
def go():
	doc = SimpleDocTemplate(f'cv_{LANGUAGE}.pdf')
	doc.leftMargin = LEFT_BAR + LEFT_BAR_MARGIN
	doc.rightMargin = 20
	doc.topMargin = 0.5 * cm
	Story = []
	style = styles['Normal']
	style.__dict__['justifyBreaks'] = 0
	style.__dict__['autoLeading'] = 'max'
	style.__dict__['alignment'] = 4
	style.__dict__['spaceAfter'] = 6
	style.refresh()
	for entry in parsedCV:
		p = Paragraph(entry, style)
		Story.append(p)
		#Story.append(Spacer(1,2*cm))
	doc.build(Story, onFirstPage=firstPage, onLaterPages=laterPages)
Beispiel #8
0
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
Beispiel #9
0
def make_test(exam):

    # Set up custom fonts
    register_true_type_font()

    answers = False


    # Set up Doc properties
    styles = getSampleStyleSheet()
    
    if answers == True:
        doc = SimpleDocTemplate(f"exams/export/2021 {exam.name} ANSWERS.pdf",pagesize=letter)  
    else:
        doc = SimpleDocTemplate(f"exams/export/2021 {exam.name} Test.pdf",pagesize=letter)   

    doc_properties.Title = f"2021 {exam.name} Written Test"
    doc_properties.pageinfo = f"2021 {exam.name} Written Test"

    Story = [Spacer(1,.5*inch)]    
    style = styles["Normal"]   

    doc.leftMargin = 0.75 * inch
    doc.rightMargin = 0.75 * inch
    doc.title = '2021 State Conference Test'
    doc.auther = 'Pennsylvania TSA'

    for num, question, a, b, c, d, correct in zip(exam.numbers, exam.question, exam.choice_a, exam.choice_b, exam.choice_c, exam.choice_d, exam.correct):
        Story.append(IntegrateQuestions(num, question, a, b, c, d, correct, answers))
        Story.append(Spacer(0, 0.25*inch))

    # Append post-table text, if any
    Story.append(Spacer(0, 0.2*inch))  
    post_text = "This is the end of the test. Please submit your answer sheet."        
    p = Paragraph(post_text, style)
    Story.append(p)        

    # Finally, generate and save the PDF
    doc.build(Story, onFirstPage=FirstPage, onLaterPages=LaterPages)
Beispiel #10
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
            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)
                        default='setup.json',
                        help='setup configuration file')
    args = parser.parse_args()

    setup(args.setup, STYLES)

    doc = SimpleDocTemplate(args.output, pagesize=A4)

    elements = []

    payload = load_payload('application.json')
    elements.append(Spacer(0, 1 * cm))
    make_heading(elements, [payload['title']])
    make_application_text(elements, payload)
    make_human_signature(elements, payload)

    doc.leftMargin = 29
    doc.rightMargin = 29

    def make_first_page_ld(canvas, doc): return make_first_page(canvas, doc,
                                                                args.qr_code,
                                                                payload)

    decl = doc.build(elements,
                     onFirstPage=make_first_page_ld,
                     onLaterPages=make_later_pages)

    if args.certificate and args.password:
        crypto_sign(args.certificate, args.password, args.output)
    print(payload['digest'])
Beispiel #13
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)
Beispiel #14
0
  def doPrint(self, app, qrcode_value, raw_score):
    pdf_file_name = tempfile.mktemp (".pdf")
    styles = getSampleStyleSheet ()
    h1 = styles["h1"]
    h1.alignment=TA_CENTER
    h1.fontSize = 36
    h1.spaceBefore = 10
    h1.spaceAfter = 22
    normal = styles["Normal"]
    normal.alignment=TA_CENTER
    normal.fontSize = 16
    starStyle = ParagraphStyle(name='Star',
                                  fontName='FontAwesome',
                                  fontSize=20,
                                  alignment=TA_CENTER,
                                  spaceAfter = 18)

    doc = SimpleDocTemplate (pdf_file_name)
    doc.pagesize = (8*cm, 29*cm)
    doc.topMargin = 0
    doc.leftMargin = 0
    doc.rightMargin = 0

    wheel_threshold = app.config.get('wheel_threshold')
    number_questions = app.config.get('number_questions')
    percent = float(raw_score) / float(number_questions)
    canWheel = float(percent) >= float(wheel_threshold) / float(number_questions)

    parts = []
    imagename = "images/stylo.png"
    normal.spaceAfter = 18
    if canWheel:
      parts.append(Paragraph(app.config.get('wheel_txt'), normal))

      d = barcode.createBarcodeDrawing("QR", width=4*cm, height=4*cm, barBorder=0, value=qrcode_value)
      d.hAlign = "CENTER"
      d.vAlign = "TOP"    
      parts.append(d)
    else:
      parts.append(Paragraph(app.config.get('no_wheel_txt'), normal))
      parts.append(Image(imagename, 4*cm, 4*cm))

    raw_score = min(raw_score, len(app.config.scoreValueTable())-1)
    parts.append(Paragraph(str(app.config.scoreValueTable()[raw_score]), h1))
    empty_star = u"\uF006"
    full_star = u"\uF005"
    
    stars = u""
    if percent <= 0.3:
      stars += 3 * empty_star
    elif percent < 0.6:
      stars += full_star + 2 * empty_star
    elif percent < 1:
      stars += 2 * full_star + empty_star
    else:
      stars += 3 * full_star
      
    parts.append(Paragraph(stars, starStyle))
    
    parts.append(Paragraph(app.config.get('url'), normal))
    doc.build(parts)
    #call([app.config.get('acrobat'), "", pdf_file_name])
    call([app.config.get('foxit'), "/t", pdf_file_name, app.config.get('printer_name')])