def draw_shapes(): pdf = FPDF() pdf.add_page() pdf.set_fill_color(0, 255, 255) pdf.ellipse(10, 10, 10, 100, 'F') # F: Fill; DF: Draw & fill pdf.set_line_width(1) pdf.set_fill_color(255, 0, 255) pdf.rect(15, 15, 100, 50) pdf.output('draw_shapes.pdf')
def draw_shapes(): pdf = FPDF() pdf.add_page() pdf.set_fill_color(255, 0, 0) pdf.ellipse(10, 10, 10, 100, 'F') pdf.set_line_width(1) pdf.set_fill_color(0, 255, 0) pdf.rect(20, 20, 100, 50) pdf.output('draw_shapes.pdf')
def draw_shapes(request): pdf = FPDF() pdf.add_page() pdf.set_fill_color(255, 0, 0) pdf.ellipse(10, 10, 10, 100, 'F') pdf.set_line_width(1) pdf.set_fill_color(0, 255, 0) pdf.rect(20, 20, 100, 50) pdf.output('draw_shapes.pdf') return HttpResponse('<h1>Pdf created successfully</h1>')
def MakePDFMonthCal (year, month, calParams, outputFile): startMonth = 1 endMonth = 12 # Create a calendar instance if (calParams ['FirstDay'] == SUNDAY): cal = calendar.Calendar (calendar.SUNDAY) else: cal = calendar.Calendar (calendar.MONDAY) pdfFile = FPDF (orientation=calParams['PageOrientation'], unit='in', format='letter') pdfFile.add_page() pdfFile.set_left_margin (calParams['PageXOrigin']) pdfFile.set_top_margin (calParams['PageYOrigin']) calXOffset = 0 calYOffset = 0 calMonth = month fontStyle = '' if (calParams['FontBold'] == True): fontStyle += 'b' if (calParams['FontItalic'] == True): fontStyle += 'i' calHeight = calParams['PageHeight'] calWidth = calParams['PageWidth'] numCols = 1 numRows = 1 if (month == -1): pdfFile.set_draw_color (calParams['DebugColourR'], calParams['DebugColourG'], calParams['DebugColourB']) pdfFile.set_line_width (calParams['DebugLineThickness']) pdfFile.set_xy (calParams['PageXOrigin'], calParams['PageYOrigin']) pdfFile.set_font (calParams['Font'], style=fontStyle, size=INCH_TO_POINT*calParams['YearHeader']) pdfFile.set_text_color (calParams['FontColourR'], calParams['FontColourG'], calParams['FontColourB']) pdfFile.cell (calWidth-calParams['YearGridSpacing'], calParams['YearHeader'], txt=str(year), border=calParams['Debug'], align='C') calParams['PageYOrigin'] += (calParams['YearHeader'] + calParams['YearHeaderSpace']) if (calParams['PageOrientation'] == PORTRAIT): calHeight = (calParams['PageHeight'] - calParams['YearHeader'] - calParams['YearHeaderSpace']) / YEAR_MONTH_ROWS_PORT calWidth = calParams['PageWidth'] / YEAR_MONTH_COLS_PORT numCols = YEAR_MONTH_COLS_PORT numRows = YEAR_MONTH_ROWS_PORT else: calHeight = (calParams['PageHeight'] - calParams['YearHeader'] - calParams['YearHeaderSpace']) / YEAR_MONTH_ROWS_LAND calWidth = calParams['PageWidth'] / YEAR_MONTH_COLS_LAND numCols = YEAR_MONTH_COLS_LAND numRows = YEAR_MONTH_ROWS_LAND calHeight -= calParams['YearGridSpacing'] calWidth -= calParams['YearGridSpacing'] else: startMonth = month endMonth = month for calMonth in range (startMonth, endMonth+1): if (calParams['Debug']): pdfFile.set_draw_color (calParams['DebugColourR'], calParams['DebugColourG'], calParams['DebugColourB']) pdfFile.set_line_width (calParams['DebugLineThickness']) pdfFile.rect (calParams['PageXOrigin'] + calXOffset, calParams['PageYOrigin'] + calYOffset, calWidth, calHeight) # # Make title... # pdfFile.set_text_color (calParams['FontColourR'], calParams['FontColourG'], calParams['FontColourB']) if (calParams['TitleStyle'] == 1): pdfFile.set_xy (calParams['PageXOrigin'] + calXOffset, calParams['PageYOrigin'] + calYOffset) pdfFile.set_font (calParams['Font'], style=fontStyle, size=INCH_TO_POINT*calParams['BlockMonthTitleHeight']*calHeight) pdfFile.cell (calWidth, \ calParams['BlockMonthTitleHeight']*calHeight, \ txt=calendar.month_name[calMonth], \ border=calParams['Debug'], align='C') elif (calParams['TitleStyle'] == 2): pdfFile.set_font (calParams['Font'], style=fontStyle, size=INCH_TO_POINT*calParams['BlockMonthTitleHeight']*calHeight) monthFontWidth = pdfFile.get_string_width (calendar.month_name[calMonth]) yearFontWidth = pdfFile.get_string_width (str(year)) pdfFile.set_xy (calParams['PageXOrigin'] + calXOffset, calParams['PageYOrigin'] + calYOffset) pdfFile.cell (monthFontWidth, calParams['BlockMonthTitleHeight']*calHeight + calYOffset,\ txt=calendar.month_name[calMonth], border=calParams['Debug'], align='L') pdfFile.set_xy (calParams['PageXOrigin'] + calXOffset + calWidth - yearFontWidth, calParams['PageYOrigin'] + calYOffset) pdfFile.cell (yearFontWidth, calParams['BlockMonthTitleHeight']*calHeight + calYOffset,\ txt=str(year), border=calParams['Debug'], align='R') # # Weekday titles... # dayIndices = list ( range (0, NUMBER_WEEKDAYS) ) if (calParams ['FirstDay'] == SUNDAY): dayIndices.insert (0, NUMBER_WEEKDAYS-1) dayIndices.pop () fontScaleFactor, fontMaxWidth, fontMaxSize = FindMaxFontHeight (calParams['Font'], fontStyle, \ calParams['BlockDayTitleHeight'] * calHeight, \ calWidth/NUMBER_WEEKDAYS, \ MAX_WEEKDAY_STR) for day in range (0, NUMBER_WEEKDAYS): pdfFile.set_xy (calParams['PageXOrigin'] + calXOffset + calWidth * day / NUMBER_WEEKDAYS, \ calParams['PageYOrigin'] + calYOffset + (calParams['BlockMonthTitleHeight'] + calParams['BlockTitleSpace']) * calHeight) pdfFile.set_font (calParams['Font'], style=fontStyle, size=fontScaleFactor*calParams['BlockDayTitleHeight']*calHeight) if (calParams['DayTitleStyle'] == 1): pdfFile.cell (calWidth / NUMBER_WEEKDAYS, calParams['BlockDayTitleHeight'] * calHeight, \ txt=calendar.day_name[dayIndices[day]], border=calParams['Debug'], align='C') elif (calParams['DayTitleStyle'] == 2): pdfFile.cell (calWidth / NUMBER_WEEKDAYS, calParams['BlockDayTitleHeight'] * calHeight, \ txt=calendar.day_name[dayIndices[day]], border=calParams['Debug'], align='L') # Horizontal Lines if (calParams['HorizontalLines'] == True): pdfFile.set_line_width (calParams['HorizontalLineThickness']) pdfFile.set_draw_color (calParams['HorizontalLineColourR'], calParams['HorizontalLineColourG'], calParams['HorizontalLineColourB']) HorizontalLineAmount = calParams['HorizontalLineSpacing'] * GRID_ROWS for row in range (0, HorizontalLineAmount + 1): lineXStart = calParams['PageXOrigin'] + calXOffset lineXEnd = calParams['PageXOrigin'] + calXOffset + calWidth lineYStart = calParams['PageYOrigin'] + calYOffset + calHeight \ - (row / HorizontalLineAmount) * calParams['BlockDayRegionHeight'] * calHeight lineYEnd = lineYStart pdfFile.line (lineXStart, lineYStart, lineXEnd, lineYEnd) # boxes... if (calParams['DayGridStyle'] == 4): pdfFile.set_line_width (calParams['GridLineThickness']) pdfFile.set_draw_color (calParams['DayRegionColourR'], calParams['DayRegionColourG'], calParams['DayRegionColourB']) gridOffset = calParams['DayGridSpacing'] for col in range (0, NUMBER_WEEKDAYS): for row in range (0, GRID_ROWS): boxXStart = calParams['PageXOrigin'] + calXOffset + (col / NUMBER_WEEKDAYS) * calWidth + gridOffset boxXEnd = calWidth / NUMBER_WEEKDAYS - 2*gridOffset boxYStart = calParams['PageYOrigin'] + calYOffset + (1 - calParams['BlockDayRegionHeight']) * calHeight \ + calParams['BlockDayRegionHeight'] * calHeight * row / GRID_ROWS + gridOffset boxYEnd = calParams['BlockDayRegionHeight'] * calHeight / GRID_ROWS - 2*gridOffset drawStyle = 'D' if (calParams['DayGridInvert'] == True): pdfFile.set_fill_color (calParams['FontColourR'], calParams['FontColourG'], calParams['FontColourB']) drawStyle = 'F' pdfFile.rect (boxXStart, boxYStart, boxXEnd, boxYEnd, style=drawStyle) # circles if (calParams['DayGridStyle'] == 5 or calParams['DayGridStyle'] == 6): pdfFile.set_line_width (calParams['GridLineThickness']) pdfFile.set_draw_color (calParams['DayRegionColourR'], calParams['DayRegionColourG'], calParams['DayRegionColourB']) gridOffset = calParams['DayGridSpacing'] for col in range (0, NUMBER_WEEKDAYS): for row in range (0, GRID_ROWS): boxXStart = calParams['PageXOrigin'] + calXOffset + (col / NUMBER_WEEKDAYS) * calWidth + gridOffset boxXEnd = calWidth / NUMBER_WEEKDAYS - 2*gridOffset boxYStart = calParams['PageYOrigin'] + calYOffset + (1 - calParams['BlockDayRegionHeight']) * calHeight \ + calParams['BlockDayRegionHeight'] * calHeight * row / GRID_ROWS + gridOffset boxYEnd = calParams['BlockDayRegionHeight'] * calHeight / GRID_ROWS - 2*gridOffset dX = boxXEnd dY = boxYEnd minBoxXStart = maxBoxXStart = boxXStart minBoxXEnd = maxBoxXEnd = boxXEnd minBoxYStart = maxBoxYStart = boxYStart minBoxYEnd = maxBoxYEnd = boxYEnd if (dX < dY): offset = (dY - dX) / 2 minBoxYStart += offset minBoxYEnd -= (2*offset) maxBoxXStart -= offset maxBoxXEnd += offset else: offset = (dX - dY) / 2 minBoxXStart += offset minBoxXEnd -= (2*offset) maxBoxYStart -= offset maxBoxYEnd += (2*offset) drawStyle = 'D' if (calParams['DayGridInvert'] == True): pdfFile.set_fill_color (calParams['FontColourR'], calParams['FontColourG'], calParams['FontColourB']) drawStyle = 'F' pdfFile.ellipse (minBoxXStart, minBoxYStart, minBoxXEnd, minBoxYEnd, style=drawStyle) if (calParams['DayGridStyle'] == 6): pdfFile.ellipse (boxXStart, boxYStart, boxXEnd, boxYEnd) ## ## numbers ## if (calParams['Debug']): pdfFile.set_draw_color (calParams['DebugColourR'], calParams['DebugColourG'], calParams['DebugColourB']) pdfFile.set_line_width (calParams['DebugLineThickness']) fontScaleFactor, fontMaxWidth, fontMaxSize = FindMaxFontHeight (calParams['Font'], fontStyle, \ calParams['BlockDayRegionHeight'] * calHeight / GRID_ROWS, \ calParams['DayFontScale'] * calWidth / NUMBER_WEEKDAYS, MAX_NUMBER_STR) gridOffset = 0 if (calParams['DayNumPlacement'] == 2): gridOffset += max (calParams['DayCornerOffset'] * calWidth / NUMBER_WEEKDAYS, \ calParams['DayCornerOffset'] * calParams['BlockDayRegionHeight'] * calHeight / GRID_ROWS) if (calParams['DayGridStyle'] == 4): gridOffset += calParams['DayGridSpacing'] if (calParams['DayGridInvert'] == True): pdfFile.set_text_color (255, 255, 255) else: pdfFile.set_text_color (calParams['FontColourR'], calParams['FontColourG'], calParams['FontColourB']) # iterate over all the days in the month col = 0 row = 0 for i in cal.itermonthdays (year, calMonth): # if it is a day within the month, not from the previous or next month then display it if (i != 0): # Central placement if (calParams['DayNumPlacement'] == 1): numberXLoc = calParams['PageXOrigin'] + calXOffset + col / NUMBER_WEEKDAYS * calWidth numberYLoc = calParams['PageYOrigin'] + calYOffset + (1 - calParams['BlockDayRegionHeight']) * calHeight \ + (row / GRID_ROWS) * calParams['BlockDayRegionHeight'] * calHeight \ + calParams['BlockDayRegionHeight'] * calHeight / (2 * GRID_ROWS) \ + gridOffset pdfFile.set_xy (numberXLoc, numberYLoc) pdfFile.set_font (calParams['Font'], style=fontStyle, size=fontScaleFactor*calParams['BlockDayRegionHeight'] * calHeight / GRID_ROWS) pdfFile.cell (calWidth/NUMBER_WEEKDAYS, 0, txt=str(i), align='C', border=calParams['Debug']) # Corner placement elif (calParams['DayNumPlacement'] == 2): numberXLoc = calParams['PageXOrigin'] + calXOffset + col / NUMBER_WEEKDAYS * calWidth numberYLoc = calParams['PageYOrigin'] + calYOffset + (1 - calParams['BlockDayRegionHeight']) * calHeight \ + (row / GRID_ROWS) * calParams['BlockDayRegionHeight'] * calHeight if (calParams['HorizontalLines'] == True): pdfFile.set_fill_color (255, 255, 255) pdfFile.rect (numberXLoc, numberYLoc, fontMaxWidth + 3*gridOffset, fontMaxSize / INCH_TO_POINT + 3*gridOffset, style='F') numberXLoc += gridOffset numberYLoc += gridOffset pdfFile.set_xy (numberXLoc, numberYLoc) pdfFile.set_font (calParams['Font'], style=fontStyle, size=fontScaleFactor*calParams['BlockDayRegionHeight'] * calHeight / GRID_ROWS) pdfFile.cell (fontMaxWidth, fontMaxSize / INCH_TO_POINT, txt=str(i), align='L', border=calParams['Debug']) col += 1 if (col % 7 == 0): col = 0 row += 1 if (calParams['Debug']): pdfFile.set_draw_color (calParams['DayRegionColourR'], calParams['DayRegionColourG'], calParams['DayRegionColourB']) pdfFile.set_line_width (calParams['GridLineThickness']) ## ## grid ## pdfFile.set_draw_color (calParams['DayRegionColourR'], calParams['DayRegionColourG'], calParams['DayRegionColourB']) pdfFile.set_line_width (calParams['GridLineThickness']) # horizontal grid lines if (calParams['DayGridStyle'] == 1 or calParams['DayGridStyle'] == 2): for row in range (0, GRID_ROWS+1): lineXStart = calParams['PageXOrigin'] + calXOffset lineXEnd = calParams['PageXOrigin'] + calXOffset + calWidth lineYStart = calParams['PageYOrigin'] + calYOffset + calHeight - (row / GRID_ROWS) * calParams['BlockDayRegionHeight'] * calHeight lineYEnd = lineYStart pdfFile.line (lineXStart, lineYStart, lineXEnd, lineYEnd) # vertical grid lines if (calParams['DayGridStyle'] == 1 or calParams['DayGridStyle'] == 3): for day in range (0, NUMBER_WEEKDAYS+1): lineXStart = calParams['PageXOrigin'] + calXOffset + calWidth - (day / NUMBER_WEEKDAYS) * calWidth lineXEnd = lineXStart lineYStart = calParams['PageYOrigin'] + calYOffset + (1 - calParams['BlockDayRegionHeight']) * calHeight lineYEnd = calParams['PageYOrigin'] + calYOffset + calHeight pdfFile.line (lineXStart, lineYStart, lineXEnd, lineYEnd) if (calMonth % numCols == 0): calXOffset = 0 calYOffset += (calHeight + calParams['YearGridSpacing']) else: calXOffset += calWidth calXOffset += calParams['YearGridSpacing'] pdfFile.output (outputFile) return 0
pdf = FPDF() # Set Author Name of the PDF pdf.set_author('@NavonilDas') # Set Subject of The PDF pdf.set_subject('python') # Set the Title of the PDF pdf.set_title('Generating PDF with Python') pdf.add_page() # Set Font family Courier with font size 28 pdf.set_font("Courier", '', 18) # Add Text at (0,50) pdf.text(0, 50, "Example to generate PDF in python.") # Set Font Family Courier with italic and font size 28 pdf.set_font("Courier", 'i', 28) pdf.text(0, 60, "This is an italic text") # Write text at 0,60 # Draw a Rectangle at (10,100) with Width 60,30 pdf.rect(10, 100, 60, 30, 'D') # Set Fill color pdf.set_fill_color(255, 0, 0) # Red = (255,0,0) # Draw a Circle at (10,135) with diameter 50 pdf.ellipse(10, 135, 50, 50, 'F') # Save the Output at Local File pdf.output('output.pdf', 'F')
header_y, 1, 1) pdf.ln(2) # about section pdf.set_font(title_font, '', font_size['section_title']) pdf.cell(1, line_height['section'] - 1, data['sections']['about'], ln=2) pdf.set_font(text_font, '', font_size['text']) col_1_count = len(data['about']['introduction']) / 2 desc_y = pdf.get_y() for idx, desc in enumerate(data['about']['introduction']): if idx == col_1_count: pdf.set_y(desc_y) if idx < col_1_count: pdf.set_x(page_size['left'] + page_size['section_indent']) else: pdf.set_x(page_size['middle_x']) pdf.ellipse(pdf.get_x(), pdf.get_y() + 1.1, ellipse['size'], ellipse['size'], 'F') pdf.cell(ellipse['margin']) pdf.cell(1, line_height['text'] - 1, desc, ln=2) pdf.ln(page_size['section_margin']) # education section pdf.set_x(page_size['left']) pdf.set_font(title_font, '', font_size['section_title']) pdf.cell(1, line_height['section'] - 1, data['sections']['education'], ln=2) pdf.set_font(text_font, '', font_size['text']) for univ in data['education']['universities']: pdf.set_x(page_size['left'] + page_size['section_indent']) pdf.set_font_size(font_size['text'] + 1) pdf.set_text_color(*brown)
class PdfHandler: def __init__(self, orientation='P', unit='pt', format='A4'): self.pdf_handler = FPDF(orientation=orientation, unit=unit, format=format) def _set_margins(self, left, top, right=-1): return self.pdf_handler.set_margins(left, top, right=right) def _set_title(self, title): return self.pdf_handler.set_title(title) def _set_subject(self, subject): return self.pdf_handler.set_subject(subject) def _set_author(self, author): return self.pdf_handler.set_author(author) def _set_keywords(self, keywords): return self.pdf_handler.set_keywords(keywords) def _set_creator(self, creator): return self.pdf_handler.set_creator(creator) def _add_page(self, orientation=''): return self.pdf_handler.add_page(orientation=orientation) def _set_draw_color(self, r, g=-1, b=-1): return self.pdf_handler.set_draw_color(r, g=g, b=b) def _set_fill_color(self, r, g=-1, b=-1): return self.pdf_handler.set_fill_color(g=g, b=b) def _set_text_color(self, r, g=-1, b=-1): return self.pdf_handler.set_text_color(r, g=-g, b=b) def _get_string_width(self, s): return self.pdf_handler.get_string_width(s) def _set_line_width(self, width): return self.pdf_handler.set_line_width(width) def _line(self, x1, y1, x2, y2): return self.pdf_handler.line(x1, y1, x2, y2) def _dashed_line(self, x1, y1, x2, y2, dash_length=1, space_length=1): return self.pdf_handler.dashed_line(x1, y1, x2, y2, dash_length=dash_length, space_length=space_length) def _rect(self, x, y, w, h, style=''): return self.pdf_handler.rect(x, y, w, h, style=style) def _ellipse(self, x, y, w, h, style=''): return self.pdf_handler.ellipse(x, y, w, h, style=style) def _set_font(self, family, style='', size=0): return self.pdf_handler.set_font(family, style=style, size=size) def _set_font_size(self, size): return self.pdf_handler.set_font_size(size) def _text(self, x, y, txt=''): return self.pdf_handler.text(x, y, txt=txt) def _multi_cell(self, w, h, txt='', border=0, align='J', fill=0, split_only=False): return self.pdf_handler.multi_cell(w, h, txt=txt, border=border, align=align, fill=fill, split_only=split_only) def _write(self, h, txt='', link=''): return self.pdf_handler.write(h, txt=txt, link=link) def _image(self, name, x=None, y=None, w=0, h=0, image_type='', link=''): return self.pdf_handler.image(name, x=x, y=y, w=w,h=h,type=image_type,link=link) def _normalize_text(self, txt): return self.pdf_handler.normalize_text(txt) def _output(self, name='', dest=''): return self.pdf_handler.output(name, dest)
class MakePDF(FPDF): annotation = "Даний підбір виконано автоматично. Для підтвердження підбору зверніться у проектну організацію" title1 = "Специфікація пакетів перемичок" title2 = "Специфікація елементів перемичок" title3 = "Відомість перемичок" def __init__(self, result_dict: dict, filename: str): super().__init__() count_of_lines = len(result_dict) if count_of_lines > 10: count_of_lines = 10 self.form3 = FPDF(orientation="L", unit="mm", format="A3") self.form3.add_page() self.form3.add_font("iso", "", "static/ISOCPEUR/ISOCPEUR.ttf", uni=True) self._draw_form_3() self._draw_specification_for_package(result_dict, 20, 30, self.title1) self._count_dict = dict() self._calculation_count(result_dict) self._draw_specification_for_element( self._count_dict, 20, 30 + 15 + (count_of_lines + 2) * 8 + 20, self.title2) self._draw_statement(count_of_lines, 230, 30, self.title3) self.make(result_dict) self._annotation(text=self.annotation) self.form3.output(f"static/{filename}") def _calculation_count(self, result_dict: dict): temp_list = [] position = 1 for value in result_dict.values(): for element in value: for elem in element.keys(): temp_list.append(elem) for k, v in Counter(temp_list).items(): self._count_dict[k] = {"count": v, "position": position} position += 1 return self._count_dict def make(self, result_dict: dict): n = 0 for mark, parameters_list in result_dict.items(): self.make_package_of_serial_beam(parameters_list, mark, n) n += 1 def make_package_of_serial_beam(self, package: list, mark: str, n): scale = 20 i = n if i < 5: x0 = 265 y0 = 67 + 4 * 8 * i self.form3.set_font("iso", "", 11) self.form3.text(x0 - 29, y0 - 5, mark) for nested_dict in package: position = str( self._count_dict.get(list( nested_dict.keys())[0])["position"]) self._draw_serial_beam( list(nested_dict.values())[0], x0, y0, position) x0 += nested_dict[list(nested_dict.keys()) [0]]["width, m"] * 1000 / scale + 10 / scale else: x0 = 355 y0 = 67 + 4 * 8 * (i - 5) self.form3.set_font("iso", "", 11) self.form3.text(x0 - 29, y0 - 5, mark) for nested_dict in package: position = str( self._count_dict.get(list( nested_dict.keys())[0])["position"]) self._draw_serial_beam( list(nested_dict.values())[0], x0, y0, position) x0 += nested_dict[list(nested_dict.keys()) [0]]["width, m"] * 1000 / scale + 10 / scale i += 1 def _draw_serial_beam(self, parameters: dict, x=260, y=70, position: str = '00'): x0 = x y0 = y scale = 20 b = parameters["width, m"] * 1000 / scale h = parameters["height, m"] * 1000 / scale self.form3.set_line_width(0.5) self.form3.rect(x0, y0, b, -h) self.form3.set_line_width(0.05) self.form3.line(x0, y0, x0 + b, y0 - h) self.form3.line(x0 + b, y0, x0, y0 - h) self.form3.line(x0 + b / 2, y0 - h + 1.25, x0 + b / 4, y0 - h - 5) self.form3.line(x0 + b / 4, y0 - h - 5, x0 + b / 4 + 4, y0 - h - 5) self.form3.ellipse(x0 + b / 2 - 0.5, y0 - h + 0.75, 1, 1, "F") self.form3.set_font("iso", "", 11) self.form3.text(x0 + b / 4 + 0.5, y0 - h - 5.5, position) def _draw_form_3(self, y=0): y0 = y self.form3.set_line_width(0.5) self.form3.rect(20, y0 + 10, 390, y0 + 277) self.form3.rect(230, y0 + 232, 180, y0 + 55) self.form3.line(240, y0 + 232, 240, y0 + 257) self.form3.line(250, y0 + 232, 250, y0 + 287) self.form3.line(260, y0 + 232, 260, y0 + 257) self.form3.line(270, y0 + 232, 270, y0 + 287) self.form3.line(285, y0 + 232, 285, y0 + 287) self.form3.line(295, y0 + 232, 295, y0 + 287) self.form3.line(365, y0 + 257, 365, y0 + 287) self.form3.line(380, y0 + 257, 380, y0 + 272) self.form3.line(395, y0 + 257, 395, y0 + 272) self.form3.line(295, y0 + 242, 410, y0 + 242) self.form3.line(230, y0 + 252, 295, y0 + 252) self.form3.line(230, y0 + 257, 410, y0 + 257) self.form3.line(365, y0 + 262, 410, y0 + 262) self.form3.line(295, y0 + 272, 410, y0 + 272) self.form3.set_line_width(0.05) self.form3.line(230, y0 + 237, 295, y0 + 237) self.form3.line(230, y0 + 242, 295, y0 + 242) self.form3.line(230, y0 + 247, 295, y0 + 247) self.form3.line(230, y0 + 262, 295, y0 + 262) self.form3.line(230, y0 + 267, 295, y0 + 267) self.form3.line(230, y0 + 272, 295, y0 + 272) self.form3.line(230, y0 + 277, 295, y0 + 277) self.form3.line(230, y0 + 282, 295, y0 + 282) self.form3.set_font("iso", "", 11) self.form3.text(233, y0 + 255.75, "Зм.") self.form3.text(240.75, y0 + 255.75, "Кільк.") self.form3.text(252, y0 + 255.75, "Арк.") self.form3.text(260.5, y0 + 255.75, "№док.") self.form3.text(273, y0 + 255.75, "Підпис") self.form3.text(286, y0 + 255.75, "Дата") self.form3.text(231, y0 + 260.75, "Виконав") self.form3.text(251, y0 + 260.75, "Бережний") self.form3.text(367, y0 + 260.75, "Стадія") self.form3.text(382.5, y0 + 260.75, "Аркуш") self.form3.text(396.25, y0 + 260.75, "Аркушів") self.form3.text(296, y0 + 275.75, self.title1) self.form3.text(296, y0 + 280.75, self.title2) self.form3.text(296, y0 + 285.75, self.title3) self.form3.set_font("iso", "", 14) self.form3.text(370, y0 + 268.75, "ЕП") self.form3.text(386.5, y0 + 268.75, "1") self.form3.text(401.5, y0 + 268.75, "1") self.form3.text(336, y0 + 238.25, str(datetime.utcnow().strftime("%Y—%m—%d %H:%M"))) self.form3.image("static/images/logo_dark.png", 366.25, y0 + 273.25, 42.5, 12.5) def _draw_specification_for_package(self, result_dict: dict, x=230, y=30, title: str = "Специфікація"): keys_list = [] for key in result_dict.keys(): keys_list.append(key) count_of_lines = len(result_dict) + 2 x0 = x y0 = y self.form3.set_line_width(0.5) self.form3.line(x0 + 0, y0 + 0, x0 + 180, y0 + 0) self.form3.line(x0 + 0, y0 + 15, x0 + 180, y0 + 15) self.form3.line(x0 + 0, y0 + 0, x0 + 0, y0 + 15 + count_of_lines * 8) self.form3.line(x0 + 15, y0 + 0, x0 + 15, y0 + 15 + count_of_lines * 8) self.form3.line(x0 + 75, y0 + 0, x0 + 75, y0 + 15 + count_of_lines * 8) self.form3.line(x0 + 135, y0 + 0, x0 + 135, y0 + 15 + count_of_lines * 8) self.form3.line(x0 + 145, y0 + 0, x0 + 145, y0 + 15 + count_of_lines * 8) self.form3.line(x0 + 160, y0 + 0, x0 + 160, y0 + 15 + count_of_lines * 8) self.form3.line(x0 + 180, y0 + 0, x0 + 180, y0 + 15 + count_of_lines * 8) y = y0 + 23 i = 0 self.form3.set_line_width(0.05) while i < count_of_lines: try: text = f"Збірна перемичка {keys_list[i]}" self.form3.set_font("iso", "", 11) self.form3.text(x0 + 4, y0 + 20.25 + i * 8, keys_list[i]) self.form3.text(x0 + 76, y0 + 20.25 + i * 8, text) self.form3.text(x0 + 139, y0 + 20.25 + i * 8, '1') except IndexError: pass self.form3.set_font("iso", "", 11) self.form3.line(x0 + 0, y, x0 + 180, y) i += 1 y += 8 self.form3.set_font("iso", "", 14) self.form3.text(x0 + 65, y0 - 5, title) self.form3.set_font("iso", "", 11) self.form3.text(x0 + 5, y0 + 9.25, "Поз.") self.form3.text(x0 + 35, y0 + 9.25, "Позначення") self.form3.text(x0 + 94, y0 + 9.25, "Найменування") self.form3.text(x0 + 135.5, y0 + 9.25, "Кільк.") self.form3.text(x0 + 145.3, y0 + 7.25, "Маса од.,") self.form3.text(x0 + 151, y0 + 11, "кг") self.form3.text(x0 + 163, y0 + 9.25, "Примітка") def _draw_specification_for_element(self, count_dict: dict, x=230, y=30, title: str = "Специфікація"): catalog = Catalog() keys_list = [] for key in count_dict.keys(): keys_list.append(key) count_of_lines = len(count_dict) + 2 x0 = x y0 = y self.form3.set_line_width(0.5) self.form3.line(x0 + 0, y0 + 0, x0 + 180, y0 + 0) self.form3.line(x0 + 0, y0 + 15, x0 + 180, y0 + 15) self.form3.line(x0 + 0, y0 + 0, x0 + 0, y0 + 15 + count_of_lines * 8) self.form3.line(x0 + 15, y0 + 0, x0 + 15, y0 + 15 + count_of_lines * 8) self.form3.line(x0 + 75, y0 + 0, x0 + 75, y0 + 15 + count_of_lines * 8) self.form3.line(x0 + 135, y0 + 0, x0 + 135, y0 + 15 + count_of_lines * 8) self.form3.line(x0 + 145, y0 + 0, x0 + 145, y0 + 15 + count_of_lines * 8) self.form3.line(x0 + 160, y0 + 0, x0 + 160, y0 + 15 + count_of_lines * 8) self.form3.line(x0 + 180, y0 + 0, x0 + 180, y0 + 15 + count_of_lines * 8) y = y0 + 23 i = 0 self.form3.set_line_width(0.05) while i < count_of_lines: try: self.form3.set_font("iso", "", 11) self.form3.text(x0 + 6.5, y0 + 20.25 + i * 8, str(count_dict[keys_list[i]]["position"])) self.form3.text(x0 + 16, y0 + 20.25 + i * 8, "ДСТУ Б В.2.6-55:2008") self.form3.text(x0 + 76, y0 + 20.25 + i * 8, keys_list[i]) self.form3.text(x0 + 139, y0 + 20.25 + i * 8, str(count_dict[keys_list[i]]["count"])) self.form3.text( x0 + 146.5, y0 + 20.25 + i * 8, str(round( catalog.get_weight(keys_list[i]) * 1000 / 9.8, 3))) self.form3.text( x0 + 161, y0 + 20.25 + i * 8, f"{str(round(catalog.get_weight(keys_list[i]) * 1000 / 9.8 * count_dict[keys_list[i]]['count'], 3))} кг" ) except IndexError: pass self.form3.line(x0 + 0, y, x0 + 180, y) i += 1 y += 8 self.form3.set_font("iso", "", 14) self.form3.text(x0 + 65, y0 - 5, title) self.form3.set_font("iso", "", 11) self.form3.text(x0 + 5, y0 + 9.25, "Поз.") self.form3.text(x0 + 35, y0 + 9.25, "Позначення") self.form3.text(x0 + 94, y0 + 9.25, "Найменування") self.form3.text(x0 + 135.5, y0 + 9.25, "Кільк.") self.form3.text(x0 + 145.3, y0 + 7.25, "Маса од.,") self.form3.text(x0 + 151, y0 + 11, "кг") self.form3.text(x0 + 163, y0 + 9.25, "Примітка") def _draw_statement(self, count_of_lines: int, x=230, y=30, title: str = "Відомість"): x0 = x y0 = y self.form3.set_line_width(0.5) self.form3.line(x0 + 0, y0 + 0, x0 + 90, y0 + 0) self.form3.line(x0 + 0, y0 + 15, x0 + 90, y0 + 15) if count_of_lines <= 5: self.form3.set_font("iso", "", 14) self.form3.text(x0 + 25, y0 - 5, title) self.form3.set_font("iso", '', 11) self.form3.text(x0 + 5, y0 + 9.25, "Марка") self.form3.text(x0 + 42, y0 + 9.25, "Схема перерізу") self.form3.line(x0 + 0, y0 + 0, x0 + 0, y0 + 15 + count_of_lines * 8 * 4) self.form3.line(x0 + 20, y0 + 0, x0 + 20, y0 + 15 + count_of_lines * 8 * 4) self.form3.line(x0 + 90, y0 + 0, x0 + 90, y0 + 15 + count_of_lines * 8 * 4) elif 5 < count_of_lines <= 10: self.form3.set_font("iso", "", 14) self.form3.text(x0 + 70, y0 - 5, title) self.form3.set_font("iso", "", 11) self.form3.text(x0 + 5, y0 + 9.25, "Марка") self.form3.text(x0 + 42, y0 + 9.25, "Схема перерізу") self.form3.text(x0 + 95, y0 + 9.25, "Марка") self.form3.text(x0 + 132, y0 + 9.25, "Схема перерізу") self.form3.line(x0 + 0, y0 + 0, x0 + 0, y0 + 15 + 5 * 8 * 4) self.form3.line(x0 + 20, y0 + 0, x0 + 20, y0 + 15 + 5 * 8 * 4) self.form3.line(x0 + 90, y0 + 0, x0 + 90, y0 + 15 + 5 * 8 * 4) self.form3.line(x0 + 90, y0 + 0, x0 + 180, y0 + 0) self.form3.line(x0 + 90, y0 + 15, x0 + 180, y0 + 15) self.form3.line(x0 + 110, y0 + 0, x0 + 110, y0 + 15 + (count_of_lines - 5) * 8 * 4) self.form3.line(x0 + 180, y0 + 0, x0 + 180, y0 + 15 + (count_of_lines - 5) * 8 * 4) else: pass self.form3.set_line_width(0.05) y = y0 + 47 i = 0 while i < count_of_lines and i < 5: self.form3.line(x0 + 0, y, x0 + 90, y) i += 1 y += 8 * 4 y = y0 + 47 while count_of_lines > i >= 5 and i < 10: self.form3.line(x0 + 90, y, x0 + 180, y) i += 1 y += 8 * 4 def _annotation(self, text: str = "Примітка", x=30, y=257): self.form3.set_font("iso", "", 11) self.form3.text(x, y, text)
def create_form1(personal_info, skills, languages, sum_text, work_experience, education, awards, font): pdf = FPDF() pdf.add_page() '''HEADER''' pdf.set_font("Times", size=25, style="B") pdf.set_fill_color(16, 78, 139) pdf.set_text_color(255, 255, 255) pdf.cell(0, 10, " " + personal_info[0], fill=True, ln=1) pdf.set_font("courier", size=15, style="B") pdf.set_text_color(255, 255, 255) pdf.cell(0, 10, " " + personal_info[1], fill=True, ln=2) '''PERSONAL INFO''' pdf.set_xy(140, 30) pdf.set_font("arial", size=18, style="B") pdf.set_text_color(28, 28, 28) pdf.set_fill_color(141, 238, 238) pdf.cell(0, 15, "Personal Info", fill=True, ln=1) pdf.set_draw_color(128, 128, 128) pdf.line(140, 42, 190, 42) pdf.set_xy(140, pdf.get_y()) pdf.set_font("arial", size=14, style="B") pdf.set_text_color(0, 0, 0) pdf.set_fill_color(141, 238, 238) pdf.cell(0, 10, "Address", fill=True, ln=1) pdf.set_xy(140, pdf.get_y()) pdf.set_font("arial", size=12) pdf.set_text_color(99, 99, 99) pdf.cell(0, 6, personal_info[2][0] + "_" + personal_info[2][1], fill=True, ln=1) pdf.set_xy(140, pdf.get_y()) pdf.cell(0, 6, personal_info[2][2], fill=True, ln=1) pdf.set_xy(140, pdf.get_y()) pdf.cell(0, 6, personal_info[2][3], fill=True, ln=1) pdf.set_xy(140, pdf.get_y()) pdf.set_font("arial", size=14, style="B") pdf.set_text_color(0, 0, 0) pdf.set_fill_color(141, 238, 238) pdf.cell(0, 10, "Phone", fill=True, ln=1) pdf.set_xy(140, pdf.get_y()) pdf.set_font("arial", size=12) pdf.set_text_color(99, 99, 99) pdf.cell(0, 6, personal_info[3], fill=True, ln=1) pdf.set_xy(140, pdf.get_y()) pdf.set_font("arial", size=14, style="B") pdf.set_text_color(0, 0, 0) pdf.set_fill_color(141, 238, 238) pdf.cell(0, 10, "E_mail", fill=True, ln=1) pdf.set_xy(140, pdf.get_y()) pdf.set_font("arial", size=12) pdf.set_text_color(99, 99, 99) pdf.cell(0, 6, personal_info[4], fill=True, ln=1) pdf.set_xy(140, pdf.get_y()) pdf.set_font("arial", size=14, style="B") pdf.set_text_color(0, 0, 0) pdf.set_fill_color(141, 238, 238) pdf.cell(0, 10, "Github", fill=True, ln=1) for i in range(len(personal_info[5]) - 1): link = "http://github/" + personal_info[5][0] + "/" + personal_info[5][ i + 1] pdf.set_xy(140, pdf.get_y()) pdf.set_font("arial", size=12) pdf.set_text_color(99, 99, 99) pdf.cell(0, 6, personal_info[5][i + 1], fill=True, ln=1, link=link) '''SKILLS''' pdf.set_xy(140, pdf.get_y()) pdf.set_font("arial", size=18, style="B") pdf.set_text_color(28, 28, 28) pdf.set_fill_color(141, 238, 238) pdf.cell(0, 15, "Skills", fill=True, ln=1) pdf.set_draw_color(128, 128, 128) pdf.line(140, pdf.get_y() - 4, 190, pdf.get_y() - 4) for i in range(len(skills[0])): pdf.set_fill_color(141, 238, 238) pdf.set_xy(140, pdf.get_y()) pdf.set_font("arial", size=14) pdf.set_text_color(99, 99, 99) pdf.cell(0, 15, skills[0][i], fill=True, ln=1) x = 170 for j in range(5): if j < skills[1][i]: pdf.set_fill_color(0, 0, 139) pdf.ellipse(x, pdf.get_y() - 5, 4, 4, style="F") else: pdf.set_fill_color(255, 255, 255) pdf.ellipse(x, pdf.get_y() - 5, 4, 4, style="F") x = x + 5 '''LANGUAGES''' pdf.set_xy(140, pdf.get_y()) pdf.set_font("arial", size=18, style="B") pdf.set_text_color(28, 28, 28) pdf.set_fill_color(141, 238, 238) pdf.cell(0, 15, "Languages", fill=True, ln=1) pdf.set_draw_color(128, 128, 128) pdf.line(140, pdf.get_y() - 3, 190, pdf.get_y() - 3) for i in range(len(languages[0])): pdf.set_fill_color(141, 238, 238) pdf.set_xy(140, pdf.get_y()) pdf.set_font("arial", size=14) pdf.set_text_color(99, 99, 99) pdf.cell(0, 15, languages[0][i], fill=True, ln=1) x = 170 for j in range(5): if j < languages[1][i]: pdf.set_fill_color(0, 0, 139) pdf.ellipse(x, pdf.get_y() - 5, 4, 4, style="F") else: pdf.set_fill_color(255, 255, 255) pdf.ellipse(x, pdf.get_y() - 5, 4, 4, style="F") x = x + 5 pdf.set_xy(140, pdf.get_y()) pdf.set_fill_color(141, 238, 238) pdf.cell(0, 15, "", fill=True, ln=1) '''SUMMARY TEXT''' x = 10 y = 34 pdf.set_font(font[0], size=font[1]) pdf.set_text_color(128, 128, 128) for i in range(len(sum_text)): if i == 0: pass else: if x + pdf.get_string_width(sum_text[i]) > 115: x = 10 y = y + font[1] / 2 else: x = x + pdf.get_string_width(sum_text[i - 1]) + 2 pdf.set_xy(x, y) pdf.cell( pdf.get_string_width(sum_text[i]) + 1, 5, sum_text[i], 0, 1, "C") '''WORK EXPERIENCE''' pdf.set_xy(10, pdf.get_y()) pdf.set_font("arial", size=16) pdf.set_text_color(0, 0, 0) pdf.cell(20, 20, "Work Experience", fill=False, ln=1) pdf.set_draw_color(128, 128, 128) pdf.line(10, pdf.get_y() - 5, 130, pdf.get_y() - 5) for i in range(len(work_experience[1])): pdf.set_xy(10, pdf.get_y()) pdf.set_font(font[0], size=font[1], style="B") pdf.set_text_color(0, 0, 0) pdf.cell(20, 10, work_experience[0][i], fill=False, ln=1) pdf.set_xy(40, pdf.get_y() - 10) pdf.cell(20, 10, work_experience[1][i], fill=False, ln=1) x = 40 y = pdf.get_y() pdf.set_font(font[0], size=font[1]) pdf.set_text_color(128, 128, 128) for j in range(len(work_experience[2][i])): if j == 0: pass else: if x + pdf.get_string_width(work_experience[2][i][j]) > 115: x = 40 y = y + font[1] / 2 else: x = x + pdf.get_string_width( work_experience[2][i][j - 1]) + 2 pdf.set_xy(x, y) pdf.cell( pdf.get_string_width(work_experience[2][i][j]) + 1, 5, work_experience[2][i][j], 0, 1, "C") '''EDUCATION''' pdf.set_xy(10, pdf.get_y()) pdf.set_font("arial", size=16) pdf.set_text_color(0, 0, 0) pdf.cell(20, 20, "Education", fill=False, ln=1) pdf.set_draw_color(128, 128, 128) pdf.line(10, pdf.get_y() - 5, 130, pdf.get_y() - 5) for i in range(len(education[1])): pdf.set_xy(10, pdf.get_y()) pdf.set_font(font[0], size=font[1], style="B") pdf.set_text_color(0, 0, 0) pdf.cell(20, 10, education[0][i], fill=False, ln=1) pdf.set_xy(40, pdf.get_y() - 10) pdf.cell(20, 10, education[1][i], fill=False, ln=1) pdf.set_xy(40, pdf.get_y() - 3) pdf.cell(20, 10, "GPA " + education[2][i], fill=False, ln=1) x = 40 y = pdf.get_y() pdf.set_font(font[0], size=font[1]) pdf.set_text_color(128, 128, 128) for j in range(len(education[3][i])): if j == 0: pass else: if x + pdf.get_string_width(education[3][i][j]) > 115: x = 40 y = y + font[1] / 2 else: x = x + pdf.get_string_width(education[3][i][j - 1]) + 2 pdf.set_xy(x, y) pdf.cell( pdf.get_string_width(education[3][i][j]) + 1, 5, education[3][i][j], 0, 1, "C") '''AWARDS AND HONORS''' pdf.set_xy(10, pdf.get_y()) pdf.set_font("arial", size=16) pdf.set_text_color(0, 0, 0) pdf.cell(20, 20, "Awards and Honors", fill=False, ln=1) pdf.set_draw_color(128, 128, 128) pdf.line(10, pdf.get_y() - 5, 130, pdf.get_y() - 5) for i in range(len(awards[1])): pdf.set_xy(10, pdf.get_y()) pdf.set_font(font[0], size=font[1], style="B") pdf.set_text_color(0, 0, 0) pdf.cell(20, 5, awards[0][i], fill=False, ln=1) pdf.set_font(font[0], size=font[1]) pdf.set_text_color(128, 128, 128) pdf.set_xy(40, pdf.get_y() - 5) pdf.cell(20, 5, awards[1][i], fill=False, ln=1) pdf.set_display_mode("fullpage") pdf.output(f"{name}_form1.pdf")
border=1) # Gear Front View # Gear Drawing x_center = 110 y_center = 100 x, y = poly.exterior.coords.xy x, y = Scale(x, y, args.scale) x, y = Translate(x, y, x_center, y_center) for i in range(0, len(x) - 2): pdwg.line(x[i], y[i], x[i + 1], y[i + 1]) # Hole circle Xcorner, Ycorner, w, h = FindCircleCorner( x_center, y_center, args.hole_diameter * args.scale / 2) pdwg.ellipse(Xcorner, Ycorner, w, h, style='') # Hub Circle if (args.Projection == 'third_angle'): Xcorner, Ycorner, w, h = FindCircleCorner( x_center, y_center, args.hub_diameter * args.scale / 2) pdwg.ellipse(Xcorner, Ycorner, w, h, style='') else: dashline_specs = [50, 20, 50, 20] steps = 1000 th_inc = 2 * numpy.pi / steps xPitch_circle = [] yPitch_circle = [] for i in range(0, steps): xPitch_circle.append(args.hub_diameter * numpy.cos(i * th_inc) / 2) yPitch_circle.append(args.hub_diameter * numpy.sin(i * th_inc) / 2)
class MakePDF(FPDF): def __init__(self, result_dict: dict, filename: str): super().__init__() # try: self._result = SelectIndividual(result_dict) self._result_dict = self._result.get_result_dict() self.annotation = "Даний підбір виконано автоматично. Для підтвердження підбору зверніться у проектну організацію" self.title1 = "З/б балка Б-1. Опалубне креслення" self.title2 = "З/б балка Б-1. Армування" self.title3 = "Специфікація" if int(self._result_dict["Б-1"][2]) < 2500 and int(self._result_dict["Б-1"][3]) < 400: self.scale = 10 else: self.scale = 20 self.count_of_lines = 11 self.form3 = FPDF(orientation="L", unit="mm", format="A3") self.form3.add_page() self.form3.add_font("iso", "", "static/ISOCPEUR/ISOCPEUR.ttf", uni=True) self._draw_form_3() self._draw_specification(self._result_dict, 20, 184, self.title3) self._make() self.form3.output(f"static/{filename}") # except: # self.make_error() # def _initial_scale_dimension(self): # self.scale = 10 # self.l = (int(self._result_dict["Б-1"][2]) + 500) / self.scale # self.h = int(self._result_dict["Б-1"][3]) / self.scale # self.b = int(self._result_dict["Б-1"][4]) / self.scale # diam_pos1 = self._result_dict["1"][1] / self.scale # diam_pos2 = self._result_dict["2"][1] / self.scale # diam_pos3 = self._result_dict["3"][1] / self.scale # diam_pos4 = self._result_dict["4"][1] / self.scale # self.a = diam_pos1 / 2 + 20 / self.scale def make_error(self): return "Помилка! З даними параметрами неможливо виконати розрахунок. Збільшіть висоту перерізу." def _make(self): self._draw_beam(36, 30) self._draw_rainforcment(36, 110) def _draw_beam(self, x, y): x0 = x y0 = y l = (int(self._result_dict["Б-1"][2]) + 500) / self.scale h = int(self._result_dict["Б-1"][3]) / self.scale b = int(self._result_dict["Б-1"][4]) / self.scale self.form3.set_font("iso", "", 14) self.form3.text(x0 + l / 2.5, y0 - 5, self.title1) self.form3.set_line_width(0.5) self.form3.rect(x0, y0, l, h) self._dim_h(x0, y0 + h, l) self._dim_v(x0, y0, h) if l > 250: self.form3.rect(x0 + l + 16, y0, b, h) self._dim_h(x0 + l + 16, y0 + h, b) else: self.form3.rect(x0 + l + 30, y0, b, h) self._dim_h(x0 + l + 30, y0 + h, b) def _draw_rainforcment(self, x, y): x0 = x y0 = y l = (int(self._result_dict["Б-1"][2]) + 500) / self.scale h = int(self._result_dict["Б-1"][3]) / self.scale b = int(self._result_dict["Б-1"][4]) / self.scale self.form3.set_font("iso", "", 14) self.form3.text(x0 + l / 2.35, y0 - 5, self.title2) diam_pos1 = self._result_dict["1"][1] / self.scale diam_pos2 = self._result_dict["2"][1] / self.scale diam_pos3 = self._result_dict["3"][1] / self.scale diam_pos4 = self._result_dict["4"][1] / self.scale a = diam_pos1 / 2 + 20 / self.scale self.form3.set_line_width(0.05) self.form3.rect(x0, y0, l, h) pos1_l = int(self._result_dict["1"][3] / self.scale * 1000) pos2_l = int(self._result_dict["2"][3] / self.scale * 1000) self.form3.set_line_width(0.5) self.form3.line(x0 + 30 / self.scale, y0 + h - a, x0 + 30 / self.scale + pos1_l, y0 + h - 30 / self.scale) self.form3.line(x0 + 30 / self.scale, y0 + a, x0 + 30 / self.scale + pos2_l, y0 + 30 / self.scale) pos3_data = self._result.get_distance_position_3_4() def draw_pos3(x, y): self.form3.line( x, y + a - diam_pos2 / 2 - diam_pos3 / 2, x, y + h - a + diam_pos2 / 2 + diam_pos3 / 2, ) draw_pos3(x0 + (30 + 50) / self.scale, y0) draw_pos3(x0 + (30 + 50) / self.scale + pos3_data[1] * 1000 / self.scale, y0) draw_pos3(x0 + l - (30 + 50) / self.scale - pos3_data[1] * 1000 / self.scale, y0) draw_pos3(x0 + l - (30 + 50) / self.scale, y0) mid_dist_temp = round((pos2_l * self.scale - (50 + pos3_data[1] * 1000) * 2 - pos3_data[3] * 1000) / 2) mid_dist = mid_dist_temp / self.scale draw_pos3(x0 + 30 / self.scale + (50 + pos3_data[1] * 1000) / self.scale + mid_dist, y0) draw_pos3(x0 + 30 / self.scale + (50 + pos3_data[1] * 1000 + pos3_data[3] * 1000) / self.scale + mid_dist, y0) s = (b - 2 * a) / (self._result_dict["1"][0] - 1) if l > 250: self.form3.set_line_width(0.05) self.form3.rect(x0 + l + 16, y0, b, h) self.form3.set_line_width(0.5) self.form3.line( x0 + l + 16 + a - (diam_pos3 + diam_pos1) / 2, y0 + 10 / self.scale, x0 + l + 16 + a - (diam_pos3 + diam_pos1) / 2, y0 + h - 10 / self.scale ) self.form3.line( x0 + l + 16 + b - a + (diam_pos3 + diam_pos1) / 2, y0 + 10 / self.scale, x0 + l + 16 + b - a + (diam_pos3 + diam_pos1) / 2, y0 + h - 10 / self.scale ) self.form3.line( x0 + l + 16 + 10 / self.scale, y0 + a - (diam_pos3 + diam_pos2) / 2, x0 + l + 16 + b - 10 / self.scale, y0 + a - (diam_pos3 + diam_pos2) / 2 ) self.form3.line( x0 + l + 16 + 10 / self.scale, y0 + h - a + (diam_pos3 + diam_pos1) / 2, x0 + l + 16 + b - 10 / self.scale, y0 + h - a + (diam_pos3 + diam_pos1) / 2 ) self.form3.set_line_width(0.05) self.form3.ellipse(x0 + l + 16 + a - diam_pos1 / 2, y0 + a - diam_pos2 / 2, diam_pos2, diam_pos2, "FD") self.form3.ellipse(x0 + l + 16 - a + diam_pos1 / 2 + b - diam_pos2, y0 + a - diam_pos2 / 2, diam_pos2, diam_pos2, "FD") for i in range(self._result_dict["1"][0]): self.form3.ellipse(x0 + l + 16 + a - diam_pos1 / 2 + s * i, y0 + h - a - diam_pos1 / 2, diam_pos1, diam_pos1, "FD") else: self.form3.set_line_width(0.05) self.form3.rect(x0 + l + 30, y0, b, h) self.form3.set_line_width(0.5) self.form3.line( x0 + l + 30 + a - (diam_pos3 + diam_pos1) / 2, y0 + 10 / self.scale, x0 + l + 30 + a - (diam_pos3 + diam_pos1) / 2, y0 + h - 10 / self.scale ) self.form3.line( x0 + l + 30 + b - a + (diam_pos3 + diam_pos1) / 2, y0 + 10 / self.scale, x0 + l + 30 + b - a + (diam_pos3 + diam_pos1) / 2, y0 + h - 10 / self.scale ) self.form3.line( x0 + l + 30 + 10 / self.scale, y0 + a - (diam_pos3 + diam_pos2) / 2, x0 + l + 30 + b - 10 / self.scale, y0 + a - (diam_pos3 + diam_pos2) / 2 ) self.form3.line( x0 + l + 30 + 10 / self.scale, y0 + h - a + (diam_pos3 + diam_pos1) / 2, x0 + l + 30 + b - 10 / self.scale, y0 + h - a + (diam_pos3 + diam_pos1) / 2 ) self.form3.set_line_width(0.05) self.form3.ellipse(x0 + l + 30 + a - diam_pos1 / 2, y0 + a - diam_pos2 / 2, diam_pos2, diam_pos2, "FD") self.form3.ellipse(x0 + l + 30 - a + diam_pos1 / 2 + b - diam_pos2, y0 + a - diam_pos2 / 2, diam_pos2, diam_pos2, "FD") for i in range(self._result_dict["1"][0]): self.form3.ellipse(x0 + l + 30 + a - diam_pos1 / 2 + s * i, y0 + h - a - diam_pos1 / 2, diam_pos1, diam_pos1, "FD") self._dim_h(x0, y0 + h, 30 / self.scale, -3.5) self._dim_h(x0 + 30 / self.scale, y0 + h, 50 / self.scale, 5) self._dim_h( x0 + 30 / self.scale + 50 / self.scale, y0 + h, pos3_data[1] * 1000 / self.scale, -5, f"{pos3_data[0] - 1}x100={(pos3_data[0] - 1) * 100}" ) self._dim_h( x0 + 30 / self.scale + 50 / self.scale + pos3_data[1] * 1000 / self.scale, y0 + h, mid_dist ) self._dim_h( x0 + 30 / self.scale + 50 / self.scale + pos3_data[1] * 1000 / self.scale + mid_dist, y0 + h, pos3_data[3] * 1000 / self.scale, -5, f"{pos3_data[2] - 1}x200={(pos3_data[2] - 1) * 200}" ) self._dim_h( x0 + 30 / self.scale + 50 / self.scale + pos3_data[1] * 1000 / self.scale + mid_dist + pos3_data[3] * 1000 / self.scale, y0 + h, mid_dist ) self._dim_h( x0 + 30 / self.scale + 50 / self.scale + pos3_data[1] * 1000 / self.scale + 2 * mid_dist + pos3_data[3] * 1000 / self.scale, y0 + h, pos3_data[1] * 1000 / self.scale, -5, f"{pos3_data[0] - 1}x100={(pos3_data[0] - 1) * 100}" ) self._dim_h( x0 + 30 / self.scale + 50 / self.scale + 2 * pos3_data[1] * 1000 / self.scale + 2 * mid_dist + pos3_data[3] * 1000 / self.scale, y0 + h, 50 / self.scale, -4.5 ) self._dim_h( x0 + 30 / self.scale + 2 * 50 / self.scale + 2 * pos3_data[1] * 1000 / self.scale + 2 * mid_dist + pos3_data[3] * 1000 / self.scale, y0 + h, 30 / self.scale, 4 ) self._dim_v(x0, y0, a, 3) self._dim_v(x0, y0 + a, h - 2 * a) self._dim_v(x0, y0 - a + h, a, -3) if l > 250: self._dim_h(x0 + l + 16, y0 + h, a, -3) if self._result_dict['1'][0] > 2: self._dim_h( x0 + l + 16 + a, y0 + h, b - 2 * a, -1, f" " ) self.form3.set_line_width(0.05) self.form3.line(x0 + l + 16 + b / 2, y0 + h + 8, x0 + l + 16 + b / 2, y0 + h + 13) self.form3.line(x0 + l + 16 + b / 2, y0 + h + 13, x0 + l + 16 + b / 2 + 15, y0 + h + 13) self.form3.text( x0 + l + 16 + b / 2 + 1, y0 + h + 12.5, f"{self._result_dict['1'][0] - 1}x" f"{int(round((b - 2 * a) * self.scale / (self._result_dict['1'][0] - 1), 0))}=" f"{int(round((b - 2 * a) * self.scale, 0))}") else: self._dim_h( x0 + l + 16 + a, y0 + h, b - 2 * a, -1, f"{int(round((b - 2 * a) * self.scale / (self._result_dict['1'][0] - 1), 0))}" ) self._dim_h(x0 + l + 16 - a + b, y0 + h, a, 3.5) self._dim_v(x0 + l + 16, y0, a, 3) self._dim_v(x0 + l + 16, y0 + a, h - 2 * a) self._dim_v(x0 + l + 16, y0 - a + h, a, -3) else: self._dim_h(x0 + l + 30, y0 + h, a, -3) if self._result_dict['1'][0] > 2: self._dim_h( x0 + l + 30 + a, y0 + h, b - 2 * a, -1, " " #f"{self._result_dict['1'][0] - 1}x{int(round((b - 2 * a) * self.scale / (self._result_dict['1'][0] - 1), 0))}" ) self.form3.set_line_width(0.05) self.form3.line(x0 + l + 30 + b / 2, y0 + h + 8, x0 + l + 30 + b / 2, y0 + h + 13) self.form3.line(x0 + l + 30 + b / 2, y0 + h + 13, x0 + l + 30 + b / 2 + 15, y0 + h + 13) self.form3.text( x0 + l + 30 + b / 2 + 1, y0 + h + 12.5, f"{self._result_dict['1'][0] - 1}x" f"{int(round((b - 2 * a) * self.scale / (self._result_dict['1'][0] - 1), 0))}=" f"{int(round((b - 2 * a) * self.scale, 0))}") else: self._dim_h( x0 + l + 30 + a, y0 + h, b - 2 * a, 0, f"{int(round((b - 2 * a) * self.scale / (self._result_dict['1'][0] - 1), 0))}" ) self._dim_h(x0 + l + 30 - a + b, y0 + h, a, 3.5) self._dim_v(x0 + l + 30, y0, a, 3) self._dim_v(x0 + l + 30, y0 + a, h - 2 * a) self._dim_v(x0 + l + 30, y0 - a + h, a, -3) self.form3.set_line_width(0.05) self.form3.set_font("iso", "", 11) self.form3.line(x0 + l / 2 + 5, y0 + a, x0 + l / 2 + 5, y0 + a + 5) self.form3.line(x0 + l / 2 + 5, y0 + a + 5, x0 + l / 2 + 8, y0 + a + 5) self.form3.text(x0 + l / 2 + 6, y0 + a + 4.5, "2") self.form3.line(x0 + l / 2 - 5, y0 + h - a, x0 + l / 2 - 5, y0 + h - a - 5) self.form3.line(x0 + l / 2 - 5, y0 + h - a - 5, x0 + l / 2 - 2, y0 + h - a - 5) self.form3.text(x0 + l / 2 - 4, y0 + h - a - 5.5, "1") self.form3.line(x0 + 80 / self.scale, y0 + h / 2, x0 + 80 / self.scale + 8, y0 + h / 2) self.form3.text(x0 + 80 / self.scale + 6, y0 + h / 2 - 0.5, "3") self.form3.line( x0 + (80 + pos3_data[1] * 1000) / self.scale, y0 + h / 2, x0 + (80 + pos3_data[1] * 1000) / self.scale - 8, y0 + h / 2 ) self.form3.text(x0 + (80 + pos3_data[1] * 1000) / self.scale - 7, y0 + h / 2 - 0.5, "3") self.form3.line( x0 + (80 + pos3_data[1] * 1000) / self.scale + mid_dist, y0 + h / 2, x0 + (80 + pos3_data[1] * 1000) / self.scale + mid_dist + 8, y0 + h / 2 ) self.form3.text(x0 + (80 + pos3_data[1] * 1000) / self.scale + mid_dist + 6, y0 + h / 2 - 0.5, "3") self.form3.line( x0 + (80 + pos3_data[1] * 1000 + pos3_data[3] * 1000) / self.scale + mid_dist, y0 + h / 2, x0 + (80 + pos3_data[1] * 1000 + pos3_data[3] * 1000) / self.scale + mid_dist - 8, y0 + h / 2 ) self.form3.text(x0 + (80 + pos3_data[1] * 1000 + pos3_data[3] * 1000) / self.scale + mid_dist -7, y0 + h / 2 - 0.5, "3") self.form3.line( x0 + (80 + pos3_data[1] * 1000 + pos3_data[3] * 1000) / self.scale + 2 * mid_dist, y0 + h / 2, x0 + (80 + pos3_data[1] * 1000 + pos3_data[3] * 1000) / self.scale + 2 * mid_dist + 8, y0 + h / 2 ) self.form3.text(x0 + (80 + pos3_data[1] * 1000 + pos3_data[3] * 1000) / self.scale + 2 * mid_dist + 6, y0 + h / 2 - 0.5, "3") self.form3.line( x0 + (80 + 2 * pos3_data[1] * 1000 + pos3_data[3] * 1000) / self.scale + 2 * mid_dist, y0 + h / 2, x0 + (80 + 2 * pos3_data[1] * 1000 + pos3_data[3] * 1000) / self.scale + 2 * mid_dist - 8, y0 + h / 2 ) self.form3.text(x0 + (80 + 2 * pos3_data[1] * 1000 + pos3_data[3] * 1000) / self.scale + 2 * mid_dist - 7, y0 + h / 2 - 0.5, "3") if l > 250: for i in range(self._result_dict["1"][0]): self.form3.line( x0 + l + 16 + a + s * i, y0 + h - a, x0 + l + 16 + a + 2, y0 + h - a - 5 ) self.form3.line( x0 + l + 16 + a + 2, y0 + h - a - 5, x0 + l + 16 + a + 5, y0 + h - a - 5 ) self.form3.text(x0 + l + 16 + a + 3, y0 + h - a - 5.5, "1") self.form3.line( x0 + l + 16 + a - diam_pos2 / 2, y0 + a, x0 + l + 16 + a - diam_pos2 / 2 - 2, y0 + a - 5 ) self.form3.line( x0 + l + 16 + a - diam_pos2 / 2 - 2, y0 + a - 5, x0 + l + 16 + a - diam_pos2 / 2 - 5, y0 + a - 5 ) self.form3.text(x0 + l + 16 + a - diam_pos2 / 2 - 4, y0 + a - 5.5, "2") self.form3.line( x0 + l + 16 - a + b - diam_pos2 / 2 + diam_pos1 / 2, y0 + a, x0 + l + 16 - a + b - diam_pos2 / 2 + diam_pos1 / 2 + 2, y0 + a - 5 ) self.form3.line( x0 + l + 16 - a + b - diam_pos2 / 2 + diam_pos1 / 2 + 2, y0 + a - 5, x0 + l + 16 - a + b - diam_pos2 / 2 + diam_pos1 / 2 + 5, y0 + a - 5 ) self.form3.text(x0 + l + 16 - a + b - diam_pos2 / 2 + diam_pos1 / 2 + 3, y0 + a - 5.5, "2") self.form3.line( x0 + l + 16 + a - (diam_pos3 / 2 + diam_pos1 / 2), y0 + h / 2, x0 + l + 16 + a - (diam_pos3 / 2 + diam_pos1 / 2) - 6, y0 + h / 2 ) self.form3.text(x0 + l + 16 + a - (diam_pos3 / 2 + diam_pos1 / 2) - 5, y0 + h / 2 - 0.5, "3") self.form3.line( x0 + l + 16 - a + (diam_pos3 / 2 + diam_pos1 / 2) + b, y0 + h / 2, x0 + l + 16 - a + (diam_pos3 / 2 + diam_pos1 / 2) + b + 8, y0 + h / 2 ) self.form3.text(x0 + l + 16 - a + (diam_pos3 + diam_pos1) / 2 + b + 6, y0 + h / 2 - 0.5, "3") self.form3.line( x0 + l + 16 + b / 2, y0 + a - (diam_pos4 + diam_pos2) / 2, x0 + l + 16 + b / 2 - 2, y0 + a - (diam_pos4 + diam_pos2) / 2 - 5 ) self.form3.line(x0 + l + 16 + b / 2 - 2, y0 + a - (diam_pos4 + diam_pos2) / 2 - 5, x0 + l + 16 + b / 2 + 1, y0 + a - (diam_pos4 + diam_pos2) / 2 - 5) self.form3.text(x0 + l + 16 + b / 2 - 1, y0 + a - (diam_pos4 + diam_pos2) / 2 - 5.5, "4") self.form3.line( x0 + l + 16 + 3, y0 + h - a + (diam_pos4 + diam_pos1) / 2, x0 + l + 16 - 2, y0 + h - a + (diam_pos4 + diam_pos1) / 2 + 5 ) self.form3.line( x0 + l + 16 - 2, y0 + h - a + (diam_pos4 + diam_pos1) / 2 + 5, x0 + l + 16 - 5, y0 + h - a + (diam_pos4 + diam_pos1) / 2 + 5 ) self.form3.text(x0 + l + 16 - 4, y0 + h - a + (diam_pos4 + diam_pos1) / 2 + 4.5, "4") else: for i in range(self._result_dict["1"][0]): self.form3.line( x0 + l + 30 + a + s * i, y0 + h - a, x0 + l + 30 + a + 2, y0 + h - a - 5 ) self.form3.line( x0 + l + 30 + a + 2, y0 + h - a - 5, x0 + l + 30 + a + 5, y0 + h - a - 5 ) self.form3.text(x0 + l + 30 + a + 3, y0 + h - a - 5.5, "1") self.form3.line( x0 + l + 30 + a - diam_pos2 / 2, y0 + a, x0 + l + 30 + a - diam_pos2 / 2 - 2, y0 + a - 5 ) self.form3.line( x0 + l + 30 + a - diam_pos2 / 2 - 2, y0 + a - 5, x0 + l + 30 + a - diam_pos2 / 2 - 5, y0 + a - 5 ) self.form3.text(x0 + l + 30 + a - diam_pos2 / 2 - 4, y0 + a - 5.5, "2") self.form3.line( x0 + l + 30 - a + b - diam_pos2 / 2 + diam_pos1 / 2, y0 + a, x0 + l + 30 - a + b - diam_pos2 / 2 + diam_pos1 / 2 + 2, y0 + a - 5 ) self.form3.line( x0 + l + 30 - a + b - diam_pos2 / 2 + diam_pos1 / 2 + 2, y0 + a - 5, x0 + l + 30 - a + b - diam_pos2 / 2 + diam_pos1 / 2 + 5, y0 + a - 5 ) self.form3.text(x0 + l + 30 - a + b - diam_pos2 / 2 + diam_pos1 / 2 + 3, y0 + a - 5.5, "2") self.form3.line( x0 + l + 30 + a - (diam_pos3 / 2 + diam_pos1 / 2), y0 + h / 2, x0 + l + 30 + a - (diam_pos3 / 2 + diam_pos1 / 2) - 6, y0 + h / 2 ) self.form3.text(x0 + l + 30 + a - (diam_pos3 / 2 + diam_pos1 / 2) - 5, y0 + h / 2 - 0.5, "3") self.form3.line( x0 + l + 30 - a + (diam_pos3 / 2 + diam_pos1 / 2) + b, y0 + h / 2, x0 + l + 30 - a + (diam_pos3 / 2 + diam_pos1 / 2) + b + 8, y0 + h / 2 ) self.form3.text(x0 + l + 30 - a + (diam_pos3 + diam_pos1) / 2 + b + 6, y0 + h / 2 - 0.5, "3") self.form3.line( x0 + l + 30 + b / 2, y0 + a - (diam_pos4 + diam_pos2) / 2, x0 + l + 30 + b / 2 - 2, y0 + a - (diam_pos4 + diam_pos2) / 2 - 5 ) self.form3.line(x0 + l + 30 + b / 2 - 2, y0 + a - (diam_pos4 + diam_pos2) / 2 - 5, x0 + l + 30 + b / 2 + 1, y0 + a - (diam_pos4 + diam_pos2) / 2 - 5) self.form3.text(x0 + l + 30 + b / 2 - 1, y0 + a - (diam_pos4 + diam_pos2) / 2 - 5.5, "4") self.form3.line( x0 + l + 30 + 3, y0 + h - a + (diam_pos4 + diam_pos1) / 2, x0 + l + 30 - 2, y0 + h - a + (diam_pos4 + diam_pos1) / 2 + 5 ) self.form3.line( x0 + l + 30 - 2, y0 + h - a + (diam_pos4 + diam_pos1) / 2 + 5, x0 + l + 30 - 5, y0 + h - a + (diam_pos4 + diam_pos1) / 2 + 5 ) self.form3.text(x0 + l + 30 - 4, y0 + h - a + (diam_pos4 + diam_pos1) / 2 + 4.5, "4") def _dim_h(self, x, y, l, x_text=0.0, text=""): x0 = x y0 = y x_t = x0 + x_text + l / 2 - 2 if len(text) == 0: dim_text = str(int(l * self.scale)) else: dim_text = text self.form3.set_line_width(0.05) self.form3.line(x0 - 2, y0 + 8, x0 + l + 2, y0 + 8) self.form3.line(x0, y0 + 2, x0, y0 + 10) self.form3.line(x0 + l, y0 + 2, x0 + l, y0 + 10) self.form3.set_line_width(0.5) self.form3.line(x0 - 0.9, y0 + 8.9, x0 + 0.9, y0 + 7.1) self.form3.line(x0 + l - 0.9, y0 + 8.9, x0 + l + 0.9, y0 + 7.1) self.form3.set_font("iso", "", 11) self.form3.text(x_t, y0 + 7.5, dim_text) def _dim_v(self, x, y, l, x_text=0.0, text=""): x0 = x y0 = y x_t = x0 + x_text - l / 2 - 2 self.form3.rotate(90, x0, y0) if len(text) == 0: dim_text = str(int(l * self.scale)) else: dim_text = text self.form3.set_line_width(0.05) self.form3.line(x0 + 2, y0 - 8, x0 - l - 2, y0 - 8) self.form3.line(x0, y0 - 2, x0, y0 - 10) self.form3.line(x0 - l, y0 - 2, x0 - l, y0 - 10) self.form3.set_line_width(0.5) self.form3.line(x0 + 0.9, y0 - 8.9, x0 - 0.9, y0 - 7.1) self.form3.line(x0 - l + 0.9, y0 - 8.9, x0 - l - 0.9, y0 - 7.1) self.form3.set_font("iso", "", 11) self.form3.text(x_t, y0 - 8.5, dim_text) self.form3.rotate(0) def _draw_form_3(self, y=0): y0 = y self.form3.set_line_width(0.5) self.form3.rect(20, y0 + 10, 390, y0 + 277) self.form3.rect(230, y0 + 232, 180, y0 + 55) self.form3.line(240, y0 + 232, 240, y0 + 257) self.form3.line(250, y0 + 232, 250, y0 + 287) self.form3.line(260, y0 + 232, 260, y0 + 257) self.form3.line(270, y0 + 232, 270, y0 + 287) self.form3.line(285, y0 + 232, 285, y0 + 287) self.form3.line(295, y0 + 232, 295, y0 + 287) self.form3.line(365, y0 + 257, 365, y0 + 287) self.form3.line(380, y0 + 257, 380, y0 + 272) self.form3.line(395, y0 + 257, 395, y0 + 272) self.form3.line(295, y0 + 242, 410, y0 + 242) self.form3.line(230, y0 + 252, 295, y0 + 252) self.form3.line(230, y0 + 257, 410, y0 + 257) self.form3.line(365, y0 + 262, 410, y0 + 262) self.form3.line(295, y0 + 272, 410, y0 + 272) self.form3.set_line_width(0.05) self.form3.line(230, y0 + 237, 295, y0 + 237) self.form3.line(230, y0 + 242, 295, y0 + 242) self.form3.line(230, y0 + 247, 295, y0 + 247) self.form3.line(230, y0 + 262, 295, y0 + 262) self.form3.line(230, y0 + 267, 295, y0 + 267) self.form3.line(230, y0 + 272, 295, y0 + 272) self.form3.line(230, y0 + 277, 295, y0 + 277) self.form3.line(230, y0 + 282, 295, y0 + 282) self.form3.set_font("iso", "", 11) self.form3.text(233, y0 + 255.75, "Зм.") self.form3.text(240.75, y0 + 255.75, "Кільк.") self.form3.text(252, y0 + 255.75, "Арк.") self.form3.text(260.5, y0 + 255.75, "№док.") self.form3.text(273, y0 + 255.75, "Підпис") self.form3.text(286, y0 + 255.75, "Дата") self.form3.text(231, y0 + 260.75, "Виконав") self.form3.text(251, y0 + 260.75, "Бережний") self.form3.text(367, y0 + 260.75, "Стадія") self.form3.text(382.5, y0 + 260.75, "Аркуш") self.form3.text(396.25, y0 + 260.75, "Аркушів") self.form3.text(296, y0 + 275.75, self.title1) self.form3.text(296, y0 + 280.75, self.title2) self.form3.text(296, y0 + 285.75, self.title3) self.form3.set_font("iso", "", 14) self.form3.text(370, y0 + 268.75, "ЕП") self.form3.text(386.5, y0 + 268.75, "1") self.form3.text(401.5, y0 + 268.75, "1") self.form3.text(336, y0 + 238.25, str(datetime.utcnow().strftime("%Y—%m—%d %H:%M"))) self.form3.image("static/images/logo_dark.png", 366.25, y0 + 273.25, 42.5, 12.5) def _draw_specification(self, result_dict: dict, x=230, y=30, title: str = "Специфікація"): x0 = x y0 = y self.form3.set_line_width(0.5) self.form3.line(x0 + 0, y0 + 0, x0 + 180, y0 + 0) self.form3.line(x0 + 0, y0 + 15, x0 + 180, y0 + 15) self.form3.line(x0 + 0, y0 + 0, x0 + 0, y0 + 15 + self.count_of_lines * 8) self.form3.line(x0 + 15, y0 + 0, x0 + 15, y0 + 15 + self.count_of_lines * 8) self.form3.line(x0 + 75, y0 + 0, x0 + 75, y0 + 15 + self.count_of_lines * 8) self.form3.line(x0 + 135, y0 + 0, x0 + 135, y0 + 15 + self.count_of_lines * 8) self.form3.line(x0 + 145, y0 + 0, x0 + 145, y0 + 15 + self.count_of_lines * 8) self.form3.line(x0 + 160, y0 + 0, x0 + 160, y0 + 15 + self.count_of_lines * 8) self.form3.line(x0 + 180, y0 + 0, x0 + 180, y0 + 15 + self.count_of_lines * 8) y = y0 + 23 self.form3.set_line_width(0.05) i = 0 while i < self.count_of_lines: self.form3.set_font("iso", "", 11) self.form3.line(x0 + 0, y, x0 + 180, y) i += 1 y += 8 self.form3.set_font("iso", "", 14) self.form3.text(x0 + 85, y0 - 5, title) self.form3.set_font("iso", "", 11) self.form3.text(x0 + 5, y0 + 9.25, "Поз.") self.form3.text(x0 + 35, y0 + 9.25, "Позначення") self.form3.text(x0 + 94, y0 + 9.25, "Найменування") self.form3.text(x0 + 135.5, y0 + 9.25, "Кільк.") self.form3.text(x0 + 145.3, y0 + 7.25, "Маса од.,") self.form3.text(x0 + 151, y0 + 11, "кг") self.form3.text(x0 + 163, y0 + 9.25, "Примітка") self.form3.set_font("iso", "U", 11) self.form3.text(x0 + 88, y0 + 20.25 + 0 * 8, "Залізобетонні вироби") self.form3.text(x0 + 90, y0 + 20.25 + 2 * 8, "Арматурні вироби") self.form3.text(x0 + 96, y0 + 20.25 + 7 * 8, "Матеріали") self.form3.set_font("iso", "", 11) mark = [] for key in result_dict.keys(): mark.append(key) text0 = f"Залізобетонна балка {mark[0]}" mass = (int(self._result_dict[mark[0]][2]) + 500) * int(self._result_dict[mark[0]][3]) * int(self._result_dict[mark[0]][4]) * 2500 / 1e9 self.form3.text(x0 + 4, y0 + 20.25 + 1 * 8, mark[0]) self.form3.text(x0 + 76, y0 + 20.25 + 1 * 8, text0) self.form3.text(x0 + 139, y0 + 20.25 + 1 * 8, '1') self.form3.text(x0 + 148.5, y0 + 20.25 + 1 * 8, str(mass)) i = 3 for p in mark[1:]: diameter = self._result_dict[p][1] cl = self._result_dict[p][2] length = int(self._result_dict[p][3] * 1000) quantity = self._result_dict[p][0] text1 = f"∅{diameter}{cl}; L={length}" mass = round(pi * (diameter / 1000) ** 2 / 4 * 7850 * length / 1000, 3) total_mass = f"{round(mass * quantity, 3)} кг" self.form3.text(x0 + 6.5, y0 + 20.25 + i * 8, p) self.form3.text(x0 + 16, y0 + 20.25 + i * 8, "ДСТУ 3760:2019") self.form3.text(x0 + 76, y0 + 20.25 + i * 8, text1) self.form3.text(x0 + 139, y0 + 20.25 + i * 8, f"{quantity}") self.form3.text(x0 + 148.5, y0 + 20.25 + i * 8, f"{mass}") self.form3.text(x0 + 162.5, y0 + 20.25 + i * 8, f"{total_mass}") i += 1 volume = (int(self._result_dict[mark[0]][2]) + 500) * int(self._result_dict[mark[0]][3]) * int(self._result_dict[mark[0]][4]) / 1e9 self.form3.text(x0 + 16, y0 + 20.25 + 8 * 8, "ДСТУ Б В.2.7-176:2008") self.form3.text(x0 + 76, y0 + 20.25 + 8 * 8, "Бетон класу С20/25") self.form3.text(x0 + 162.5, y0 + 20.25 + 8 * 8, f"{volume}") self.form3.text(x0 + 171, y0 + 20.25 + 8 * 8, f"м") self.form3.set_font("iso", "", 7) self.form3.text(x0 + 173, y0 + 19.25 + 8 * 8, "3")
cut_image = image.crop((x*(cut_width-overlap)*pixel_per_inch,y*(cut_height-overlap)*pixel_per_inch,cut_right,cut_bottom)) cut_image.save(outfile) # place image in PDF pdf.add_page() pdf.image(outfile,x=margin, y=margin, w=min(page_width-2*margin, cut_image.size[0]/pixel_per_inch), h=min(page_height-2*margin, cut_image.size[1]/pixel_per_inch)) # place holes on PDF pdf.set_draw_color(r=0) pdf.set_fill_color(r=255) left_dot = margin+hole_offset right_dot = cut_image.size[0]/pixel_per_inch-hole_size+margin/2 top_dot = margin+hole_offset bottom_dot = cut_image.size[1]/pixel_per_inch-hole_size+margin/2 if x != 0 or y !=0: pdf.ellipse(x=left_dot, y=top_dot, w=hole_size, h=hole_size, style='DF') if x != 0 or y != y_pages-1: pdf.ellipse(x=left_dot, y=bottom_dot, w=hole_size, h=hole_size, style='DF') if x != x_pages-1 or y !=0: pdf.ellipse(x=right_dot, y=top_dot, w=hole_size, h=hole_size, style='DF') if x != x_pages-1 or y != y_pages-1: pdf.ellipse(x=right_dot, y=bottom_dot, w=hole_size, h=hole_size, style='DF') # place descriptive text in the corner of the page pdf.set_font(family='Arial', style='B', size=text_size) pdf.text(x=left_dot+3/2*hole_size, y=bottom_dot+hole_size, txt='%dx%d' % (x, y)) # save PDf pdf.output("%s.pdf"%output_name) # remove temp files
pdf.dashed_line(page_size['left'] + 1, header_y, page_size['end_x'] + 1, header_y, 1, 1) pdf.ln(2) # about section pdf.set_font(title_font, '', font_size['section_title']) pdf.cell(1, line_height['section'] - 1, data['sections']['about'], ln=2) pdf.set_font(text_font, '', font_size['text']) col_1_count = len(data['about']['introduction']) / 2 desc_y = pdf.get_y() for idx, desc in enumerate(data['about']['introduction']): if idx == col_1_count: pdf.set_y(desc_y) if idx < col_1_count: pdf.set_x(page_size['left'] + page_size['section_indent']) else: pdf.set_x(page_size['middle_x']) pdf.ellipse(pdf.get_x(), pdf.get_y() + 1.1, ellipse['size'], ellipse['size'], 'F') pdf.cell(ellipse['margin']) pdf.cell(1, line_height['text'] - 1, desc, ln=2) pdf.ln(page_size['section_margin']) # education section pdf.set_x(page_size['left']) pdf.set_font(title_font, '', font_size['section_title']) pdf.cell(1, line_height['section'] - 1, data['sections']['education'], ln=2) pdf.set_font(text_font, '', font_size['text']) for univ in data['education']['universities']: pdf.set_x(page_size['left'] + page_size['section_indent']) univ_y = pdf.get_y() pdf.set_font_size(font_size['text'] + 1) pdf.set_text_color(*brown) pdf.cell(1, line_height['text'], univ['name'], ln=2) pdf.set_font_size(font_size['text'])
def create_form2(personal_info, education, work_experience, languages, software, font): pdf = FPDF() pdf.add_page() pdf.image(personal_info[0], w=40, h=40) '''NAME AND FIELD''' pdf.set_xy(120, 20) pdf.set_font("Times", size=25, style="B") pdf.set_text_color(0, 0, 0) pdf.set_fill_color(255, 255, 255) pdf.cell(20, 10, personal_info[1], fill=True, ln=1) pdf.set_xy(120, 30) pdf.set_font("courier", size=15, style="B") pdf.cell(0, 10, personal_info[2], fill=True, ln=1, align="L") '''PERSONAL DETAILS''' pdf.set_xy(10, 55) pdf.set_font("arial", size=15, style="B") pdf.set_text_color(0, 0, 0) pdf.set_fill_color(255, 255, 255) pdf.cell(20, 10, "PERSONAL DETAILS", fill=True, ln=1) pdf.set_line_width(1) pdf.set_draw_color(0, 0, 0) pdf.line(10, 63, 200, 63) pdf.set_xy(20, 68) pdf.set_font("times", size=15) pdf.set_text_color(91, 91, 91) pdf.set_fill_color(255, 255, 255) pdf.cell(20, 5, "Birth", fill=True, ln=1) pdf.set_xy(50, pdf.get_y() - 5) pdf.cell(20, 5, personal_info[3], fill=True, ln=1) pdf.set_xy(20, pdf.get_y() + 3) pdf.set_font("times", size=15) pdf.set_text_color(91, 91, 91) pdf.set_fill_color(255, 255, 255) pdf.cell(20, 5, "Address", fill=True, ln=1) pdf.set_xy(50, pdf.get_y() - 5) pdf.cell(20, 5, personal_info[4], fill=True, ln=1) pdf.set_xy(20, pdf.get_y() + 3) pdf.set_font("times", size=15) pdf.set_text_color(91, 91, 91) pdf.set_fill_color(255, 255, 255) pdf.cell(20, 5, "phone", fill=True, ln=1) pdf.set_xy(50, pdf.get_y() - 5) pdf.cell(20, 5, personal_info[5], fill=True, ln=1) pdf.set_xy(20, pdf.get_y() + 3) pdf.set_font("times", size=15) pdf.set_text_color(91, 91, 91) pdf.set_fill_color(255, 255, 255) pdf.cell(20, 5, "E-Mail", fill=True, ln=1) pdf.set_xy(50, pdf.get_y() - 5) pdf.cell(20, 5, personal_info[6], fill=True, ln=1) '''EDUCATION''' pdf.set_xy(10, pdf.get_y()) pdf.set_font("arial", size=15, style="B") pdf.set_text_color(0, 0, 0) pdf.set_fill_color(255, 255, 255) pdf.cell(20, 12, "EDUCATION", fill=True, ln=1) pdf.set_line_width(1) pdf.set_draw_color(0, 0, 0) pdf.line(10, pdf.get_y() - 3, 200, pdf.get_y() - 3) for i in range(len(education[1])): pdf.set_xy(10, pdf.get_y()) pdf.set_font(font[0], size=font[1] + 2, style="B") pdf.set_text_color(0, 0, 0) pdf.cell(20, 10, education[1][i], fill=False, ln=1) pdf.set_xy(150, pdf.get_y() - 8) pdf.set_font(font[0], size=font[1]) pdf.set_text_color(255, 255, 255) pdf.set_fill_color(0, 0, 0) pdf.cell(25, 5, education[0][i], fill=True, ln=1) pdf.set_xy(10, pdf.get_y()) pdf.set_text_color(128, 128, 128) pdf.set_font(font[0], size=font[1]) pdf.set_text_color(0, 0, 0) pdf.cell(20, 6, education[2][i], fill=False, ln=1) x = 40 y = pdf.get_y() pdf.set_font(font[0], size=font[1]) for j in range(len(education[3][i])): if j == 0: pass else: if x + pdf.get_string_width(education[3][i][j]) > 115: x = 40 y = y + font[1] / 2 else: x = x + pdf.get_string_width(education[3][i][j - 1]) + 2 pdf.set_xy(x, y) pdf.cell( pdf.get_string_width(education[3][i][j]) + 1, 5, education[3][i][j], 0, 1, "C") '''WORK EXPERIENCE''' pdf.set_xy(10, pdf.get_y()) pdf.set_font("arial", size=15, style="B") pdf.set_text_color(0, 0, 0) pdf.set_fill_color(255, 255, 255) pdf.cell(20, 12, "WORK EXPERIENCE", fill=True, ln=1) pdf.set_line_width(1) pdf.set_draw_color(0, 0, 0) pdf.line(10, pdf.get_y() - 3, 200, pdf.get_y() - 3) for i in range(len(work_experience[1])): pdf.set_xy(10, pdf.get_y()) pdf.set_font(font[0], size=font[1] + 2, style="B") pdf.set_text_color(0, 0, 0) pdf.cell(20, 10, work_experience[1][i], fill=False, ln=1) pdf.set_xy(150, pdf.get_y() - 8) pdf.set_font(font[0], size=font[1]) pdf.set_text_color(255, 255, 255) pdf.set_fill_color(0, 0, 0) pdf.cell(25, 5, work_experience[0][i], fill=True, ln=1) pdf.set_xy(10, pdf.get_y()) pdf.set_text_color(128, 128, 128) pdf.set_font(font[0], size=font[1]) pdf.set_text_color(0, 0, 0) pdf.cell(20, 6, work_experience[2][i], fill=False, ln=1) x = 40 y = pdf.get_y() pdf.set_font(font[0], size=font[1]) for j in range(len(work_experience[3][i])): if j == 0: pass else: if x + pdf.get_string_width(work_experience[3][i][j]) > 115: x = 40 y = y + font[1] / 2 else: x = x + pdf.get_string_width( work_experience[3][i][j - 1]) + 2 pdf.set_xy(x, y) pdf.cell( pdf.get_string_width(work_experience[3][i][j]) + 1, 5, work_experience[3][i][j], 0, 1, "C") '''SKILLS''' pdf.set_xy(10, pdf.get_y()) pdf.set_font("arial", size=15, style="B") pdf.set_text_color(0, 0, 0) pdf.set_fill_color(255, 255, 255) pdf.cell(20, 12, "SKILLS", fill=True, ln=1) pdf.set_line_width(1) pdf.set_draw_color(0, 0, 0) pdf.line(10, pdf.get_y() - 3, 200, pdf.get_y() - 3) pdf.set_xy(10, pdf.get_y()) pdf.set_font(font[0], size=font[1] + 2, style="B") pdf.set_text_color(0, 0, 0) pdf.cell(20, 10, "Languages", fill=False, ln=1) pdf.set_xy(120, pdf.get_y() - 10) pdf.set_font(font[0], size=font[1] + 2, style="B") pdf.set_text_color(0, 0, 0) pdf.cell(20, 10, "Software", fill=False, ln=1) y = pdf.get_y() for i in range(len(languages[0])): pdf.set_xy(10, pdf.get_y()) pdf.set_text_color(128, 128, 128) pdf.set_font(font[0], size=font[1]) pdf.set_text_color(0, 0, 0) pdf.cell(20, 6, languages[0][i], fill=False, ln=1) x = 40 for j in range(5): if j < languages[1][i]: pdf.set_fill_color(0, 0, 139) pdf.ellipse(x, pdf.get_y() - 5, 4, 4, style="F") else: pdf.set_fill_color(128, 128, 128) pdf.ellipse(x, pdf.get_y() - 5, 4, 4, style="F") x = x + 5 pdf.set_y(y) for i in range(len(software[0])): pdf.set_xy(120, pdf.get_y()) pdf.set_text_color(128, 128, 128) pdf.set_font(font[0], size=font[1]) pdf.set_text_color(0, 0, 0) pdf.cell(20, 6, software[0][i], fill=False, ln=1) x = 150 for j in range(5): if j < software[1][i]: pdf.set_fill_color(0, 0, 139) pdf.ellipse(x, pdf.get_y() - 5, 4, 4, style="F") else: pdf.set_fill_color(128, 128, 128) pdf.ellipse(x, pdf.get_y() - 5, 4, 4, style="F") x = x + 5 pdf.set_display_mode("fullpage") pdf.output(f"{name}_form2.pdf")
pdf = FPDF() # Set Author Name of the PDF pdf.set_author("@NavonilDas") # Set Subject of The PDF pdf.set_subject("python") # Set the Title of the PDF pdf.set_title("Generating PDF with Python") pdf.add_page() # Set Font family Courier with font size 28 pdf.set_font("Courier", "", 18) # Add Text at (0,50) pdf.text(0, 50, "Example to generate PDF in python.") # Set Font Family Courier with italic and font size 28 pdf.set_font("Courier", "i", 28) pdf.text(0, 60, "This is an italic text") # Write text at 0,60 # Draw a Rectangle at (10,100) with Width 60,30 pdf.rect(10, 100, 60, 30, "D") # Set Fill color pdf.set_fill_color(255, 0, 0) # Red = (255,0,0) # Draw a Circle at (10,135) with diameter 50 pdf.ellipse(10, 135, 50, 50, "F") # Save the Output at Local File pdf.output("output.pdf", "F")