Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from reportlab.lib.pagesizes import A4,landscape, portrait
- from reportlab.lib.units import mm
- from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
- from reportlab.lib.enums import TA_LEFT, TA_RIGHT, TA_CENTER, TA_JUSTIFY
- from reportlab.lib import colors
- from reportlab.pdfgen import *
- from reportlab.pdfgen.canvas import Canvas
- from reportlab.platypus import *
- from reportlab.platypus import Paragraph, Frame, Table, TableStyle, KeepInFrame, BaseDocTemplate, PageTemplate
- from reportlab.platypus import SimpleDocTemplate
- from reportlab.platypus import flowables
- from reportlab.platypus.paragraph import ParagraphStyle
- from reportlab.pdfbase.ttfonts import TTFont
- from reportlab.pdfbase import pdfmetrics
- def margins():
- balance_1.setLineWidth(0.01) # Дебелина на линията
- balance_1.setStrokeColor('greenyellow') # Цвят на линията
- balance_1.line(left_m, bottom_m, left_m, A4[1] - top_m) # Left margin
- balance_1.line(left_m, A4[1] - top_m, A4[0] - right_m, A4[1] - top_m) # Top margin
- balance_1.line(A4[0] - right_m, A4[1] - top_m, A4[0] - right_m, bottom_m) # Right margin
- balance_1.line(A4[0] - right_m, bottom_m, left_m, bottom_m) # Bottom margin
- balance_1.setStrokeColor('red') # Цвят на линията
- def frames(x0, y0, width, height, bound, id):
- frame = Frame(x0, y0, width, height,
- leftPadding=0, topPadding=0, rightPadding=0, bottomPadding=0,
- showBoundary=bound, id=id)
- #frame.addFromList('', balance_1) # Показва frame
- return frame
- top_m = 56 # 85 = 30 mm; 56 = 20 mm
- top_f = 85 # Top frame = 85 mm = 30
- h_balance_f = 453 # 538 = 190 mm; 453 = 160 mm
- bottom_f = 189 # 189 = 67 mm
- bottom_m = 56 # 85 = 30 mm; 56 = 20 mm
- right_m = 56 # Right margin = 20 mm
- left_m = 71 # Top margin = 30 mm = 85, 71 = 25 mm
- width_f = A4[0] - left_m - right_m
- # Create pdf form with name: Balance
- balance_1 = Canvas('Balance_1.pdf', pagesize=A4) # balance е целият обект - pdf файла.
- # Create Visualisation margins frame
- margins()
- # Create Balance Frames
- height_f = h_balance_f
- a = frames(left_m, A4[1] - (top_m + top_f), width_f/2, -1 * height_f, 1, 'balance_frame_l') # Ляв фрейм
- frames(A4[0] - right_m, A4[1] - top_m - top_f, -1 * width_f/2, -1 * height_f, 1, 'balance_frame_r') # Десен фрейм
- #frames(x1_f, A4[1] - (top_m + top_f), width_f, -1 * height_f, 1, 'balance_frame') # Един Фрейм
- frames(left_m, A4[1] - top_m, width_f / 3, -1 * (top_f - 20), 1, 'comp_name')
- frames(A4[0] - right_m, A4[1] - top_m, -1 * width_f / 3, -1 * (top_f - 20), 1, 'activity')
- # Заглавие
- title = 'СЧЕТОВОДЕН БАЛАНС'
- data_balance = 'към 31.12.2021 година'
- pdfmetrics.registerFont((TTFont('Timesbd', 'timesbd.ttf')))
- balance_1.setFont('Timesbd', 10, leading=100)
- balance_1.drawString(width_f / 2 + 4 * mm, bottom_m + bottom_f + height_f + 20, title)
- pdfmetrics.registerFont((TTFont('Times', 'times.ttf')))
- balance_1.setFont('Times', 10, leading=100)
- balance_1.drawString(width_f / 2 + 12 + 4* mm, bottom_m + bottom_f + height_f + 5, data_balance)
- # Create Table in Frame
- data_table = [
- ['1. Продукти от развойна дейност', '255', '355'],
- ['2. Търговска репутация', '23', '1255']
- ]
- t = Table(data_table)
- pdfmetrics.registerFont((TTFont('Times', 'times.ttf', 'UTF-8')))
- t.wrapOn(balance_1, 100, 60)
- t.drawOn(balance_1, 100, 160)
- # Създаваме параграф
- p = Paragraph('I2of5')
- # Списък с неща които искаме да влязат във фрейма
- story = []
- story.append(t) # В списъка добавяме таблицата
- story.append(p) # В списъка добавяме параграфа
- a.addFromList(story, balance_1)
- balance_1.showPage() # saves current page
- balance_1.save() # stores the file and close the canvas
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement