Advertisement
ALEXANDAR_GEORGIEV

balance_1

Jul 4th, 2022
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.96 KB | None | 0 0
  1. from reportlab.lib.pagesizes import A4,landscape, portrait
  2. from reportlab.lib.units import mm
  3. from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
  4. from reportlab.lib.enums import TA_LEFT, TA_RIGHT, TA_CENTER, TA_JUSTIFY
  5. from reportlab.lib import colors
  6. from reportlab.pdfgen import *
  7. from reportlab.pdfgen.canvas import Canvas
  8. from reportlab.platypus import *
  9. from reportlab.platypus import Paragraph, Frame, Table, TableStyle, KeepInFrame, BaseDocTemplate, PageTemplate
  10. from reportlab.platypus import SimpleDocTemplate
  11. from reportlab.platypus import flowables
  12. from reportlab.platypus.paragraph import ParagraphStyle
  13.  
  14. from reportlab.pdfbase.ttfonts import TTFont
  15. from reportlab.pdfbase import pdfmetrics
  16.  
  17.  
  18. def margins():
  19.     balance_1.setLineWidth(0.01)  # Дебелина на линията
  20.     balance_1.setStrokeColor('greenyellow')  # Цвят на линията
  21.     balance_1.line(left_m, bottom_m, left_m, A4[1] - top_m)  # Left margin
  22.     balance_1.line(left_m, A4[1] - top_m, A4[0] - right_m, A4[1] - top_m)  # Top margin
  23.     balance_1.line(A4[0] - right_m, A4[1] - top_m, A4[0] - right_m, bottom_m)  # Right margin
  24.     balance_1.line(A4[0] - right_m, bottom_m, left_m, bottom_m)  # Bottom margin
  25.     balance_1.setStrokeColor('red')  # Цвят на линията
  26.  
  27.  
  28. def frames(x0, y0, width, height, bound, id):
  29.     frame = Frame(x0, y0, width, height,
  30.               leftPadding=0, topPadding=0, rightPadding=0, bottomPadding=0,
  31.               showBoundary=bound, id=id)
  32.     #frame.addFromList('', balance_1)  # Показва frame
  33.     return frame
  34.  
  35.  
  36. top_m = 56          # 85 = 30 mm; 56 = 20 mm
  37. top_f = 85          # Top frame = 85 mm = 30
  38. h_balance_f = 453   # 538 = 190 mm; 453 = 160 mm
  39. bottom_f = 189      # 189 = 67 mm
  40. bottom_m = 56       # 85 = 30 mm; 56 = 20 mm
  41.  
  42. right_m = 56   # Right margin = 20 mm
  43. left_m = 71     # Top margin = 30 mm = 85, 71 = 25 mm
  44. width_f = A4[0] - left_m - right_m
  45. # Create pdf form with name: Balance
  46. balance_1 = Canvas('Balance_1.pdf', pagesize=A4)  # balance е целият обект - pdf файла.
  47. # Create Visualisation margins frame
  48. margins()
  49. # Create Balance Frames
  50. height_f = h_balance_f
  51.  
  52. a = frames(left_m, A4[1] - (top_m + top_f), width_f/2, -1 * height_f, 1, 'balance_frame_l')   # Ляв фрейм
  53. frames(A4[0] - right_m, A4[1] - top_m - top_f, -1 * width_f/2, -1 * height_f, 1, 'balance_frame_r')     # Десен фрейм
  54.  
  55. #frames(x1_f, A4[1] - (top_m + top_f), width_f, -1 * height_f, 1, 'balance_frame')  # Един Фрейм
  56. frames(left_m, A4[1] - top_m, width_f / 3, -1 * (top_f - 20), 1, 'comp_name')
  57. frames(A4[0] - right_m, A4[1] - top_m, -1 * width_f / 3, -1 * (top_f - 20), 1, 'activity')
  58.  
  59. # Заглавие
  60. title = 'СЧЕТОВОДЕН БАЛАНС'
  61. data_balance = 'към 31.12.2021 година'
  62.  
  63. pdfmetrics.registerFont((TTFont('Timesbd', 'timesbd.ttf')))
  64. balance_1.setFont('Timesbd', 10, leading=100)
  65. balance_1.drawString(width_f / 2 + 4 * mm, bottom_m + bottom_f + height_f + 20, title)
  66.  
  67. pdfmetrics.registerFont((TTFont('Times', 'times.ttf')))
  68. balance_1.setFont('Times', 10, leading=100)
  69. balance_1.drawString(width_f / 2 + 12 + 4* mm, bottom_m + bottom_f + height_f + 5, data_balance)
  70.  
  71. # Create Table in Frame
  72. data_table = [
  73.     ['1. Продукти от развойна дейност', '255', '355'],
  74.     ['2. Търговска репутация', '23', '1255']
  75. ]
  76. t = Table(data_table)
  77. pdfmetrics.registerFont((TTFont('Times', 'times.ttf', 'UTF-8')))
  78. t.wrapOn(balance_1, 100, 60)
  79. t.drawOn(balance_1, 100, 160)
  80.  
  81. # Създаваме параграф
  82. p = Paragraph('I2of5')
  83. # Списък с неща които искаме да влязат във фрейма
  84. story = []
  85. story.append(t)     # В списъка добавяме таблицата
  86. story.append(p)     # В списъка добавяме параграфа
  87.  
  88. a.addFromList(story, balance_1)
  89. balance_1.showPage()  # saves current page
  90. balance_1.save()  # stores the file and close the canvas
  91.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement