Python reportlab.platypus.Image() Examples
The following are 14
code examples of reportlab.platypus.Image().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
reportlab.platypus
, or try the search function
.
Example #1
Source File: report.py From flask-restful-example with MIT License | 10 votes |
def table_model(): """ 添加表格 :return: """ template_path = current_app.config.get("REPORT_TEMPLATES") image_path = os.path.join(template_path, 'test.jpg') new_img = Image(image_path, width=300, height=300) base = [ [new_img, ""], ["大类", "小类"], ["WebFramework", "django"], ["", "flask"], ["", "web.py"], ["", "tornado"], ["Office", "xlsxwriter"], ["", "openpyxl"], ["", "xlrd"], ["", "xlwt"], ["", "python-docx"], ["", "docxtpl"], ] style = [ # 设置字体 ('FONTNAME', (0, 0), (-1, -1), 'SimSun'), # 合并单元格 (列,行) ('SPAN', (0, 0), (1, 0)), ('SPAN', (0, 2), (0, 5)), ('SPAN', (0, 6), (0, 11)), # 单元格背景 ('BACKGROUND', (0, 1), (1, 1), HexColor('#548DD4')), # 字体颜色 ('TEXTCOLOR', (0, 1), (1, 1), colors.white), # 对齐设置 ('VALIGN', (0, 0), (-1, -1), 'MIDDLE'), ('ALIGN', (0, 0), (-1, -1), 'CENTER'), # 单元格框线 ('GRID', (0, 0), (-1, -1), 0.5, colors.grey), ('BOX', (0, 0), (-1, -1), 0.5, colors.black), ] component_table = Table(base, style=style) return component_table
Example #2
Source File: report.py From nanopype with MIT License | 6 votes |
def add_section_sequences(self, plots=[], stats=None): section = self.get_section_number() subsection = itertools.count(1) if stats is not None: self.story.append(Paragraph("{:d} Basecalling".format(section), self.heading_style)) self.story.append(Spacer(1, 0)) self.story.append(Paragraph("{:d}.{:d} Summary".format(section, next(subsection)), self.heading2_style)) #['Tag', 'Basecalling', 'Sum', 'Mean', 'Median', 'N50', 'Maximum'] header = ['', ''] + list(stats.columns.values[2:]) table_data = [header] + [[y if isinstance(y, str) else '{:.0f}'.format(y) for y in x] for x in stats.values] table_style = [ ('FONTSIZE', (0,0), (-1, -1), 10), ('LINEABOVE', (0,1), (-1,1), 0.5, colors.black), ('LINEBEFORE', (2,0), (2,-1), 0.5, colors.black), ('ALIGN', (0,0), (1,-1), 'LEFT'), ('ALIGN', (2,0), (-1,-1), 'RIGHT')] self.story.append(Table(table_data, style=table_style)) self.story.append(Spacer(1, 0)) for key, group in itertools.groupby(plots, lambda x : x[1].basecalling): self.story.append(Paragraph('{:d}.{:d} {}:'.format(section, next(subsection), key.capitalize()), self.heading2_style)) for plot_file, plot_wildcards in sorted(list(group), key=lambda x : x[1].i): im = svg2rlg(plot_file) im = Image(im, width=im.width * self.plot_scale, height=im.height * self.plot_scale) im.hAlign = 'CENTER' self.story.append(im) self.story.append(Spacer(1, 0)) self.story.append(Spacer(1, 0.5*cm))
Example #3
Source File: mangascrapper.py From MangaScrapper with Apache License 2.0 | 6 votes |
def _create_pdf_(chap_save_loc): img_list = natsorted(os.listdir(chap_save_loc)) pdf_save_loc = chap_save_loc + ".pdf" doc = SimpleDocTemplate(pdf_save_loc, pagesize=A2) parts = [Image(os.path.join(chap_save_loc, img)) for img in img_list] try: doc.build(parts) except PermissionError: logging.error("Missing Permission to write. File open in system editor or missing " "write permissions.")
Example #4
Source File: base.py From testplan with Apache License 2.0 | 6 votes |
def get_row_data(self, source, depth, row_idx): """ Load the Matplotlib graph from the saved image, set its height and width and add it to the row. """ header = self.get_header(source, depth, row_idx) styles = [ RowStyle( font=(constants.FONT, constants.FONT_SIZE_SMALL), left_padding=constants.INDENT * (depth + 1), text_color=colors.black, ) ] img = Image(source["source_path"]) img.drawWidth = source["width"] * inch img.drawHeight = source["height"] * inch return header + RowData( content=[img, "", "", ""], start=header.end, style=styles )
Example #5
Source File: baseUtils.py From testplan with Apache License 2.0 | 6 votes |
def export_plot_to_image(graph_plot): """Convert a MatPlot plot into an image readable in the pdf.""" filename = "{}.png".format(uuid.uuid4()) temp_path = tempfile.gettempdir() image_pathname = os.path.join(temp_path, filename) graph_plot.savefig(image_pathname) image = Image(image_pathname) return image
Example #6
Source File: api.py From callisto-core with GNU Affero General Public License v3.0 | 6 votes |
def get_cover_page(self, report_id, recipient): # title = f"{self.report_title} No.: {report_id}" styles = getSampleStyleSheet() headline_style = styles["Heading1"] headline_style.alignment = TA_CENTER headline_style.fontSize = 48 subtitle_style = styles["Heading2"] subtitle_style.fontSize = 24 subtitle_style.leading = 26 subtitle_style.alignment = TA_CENTER CoverPage = [] logo = os.path.join(settings.BASE_DIR, self.logo_path) image = Image(logo, 3 * inch, 3 * inch) CoverPage.append(image) CoverPage.append(Spacer(1, 18)) CoverPage.append(Paragraph("CONFIDENTIAL", headline_style)) # paragraph = Paragraph( # f"Intended for: {recipient}, Title IX Coordinator", subtitle_style) # CoverPage.append(paragraph) CoverPage.append(PageBreak()) return CoverPage # entrypoints
Example #7
Source File: QRCodePrinter.py From Food-Pantry-Inventory with MIT License | 6 votes |
def place_label(self, file_name: str, label_name: str, pos: int): """ Place the label in the appropriate location on the page. :param file_name: :param label_name: :param pos: :return: """ box_info = self.label_locations[pos] # place image on page im = Image(file_name, LABEL_SIZE.x, LABEL_SIZE.y) im.drawOn(self.pdf, box_info.image_start.x, box_info.image_start.y) # place title above image self.pdf.setFont('Helvetica-Bold', 12) self.pdf.drawCentredString( box_info.title_start.x + TITLE_ADJUSTMENT.x, box_info.title_start.y + TITLE_ADJUSTMENT.y, label_name ) return
Example #8
Source File: report.py From nanopype with MIT License | 5 votes |
def add_section_alignments(self, counts=[], bases=[], identity=[], coverage=[]): section = self.get_section_number() subsection = itertools.count(1) self.story.append(Paragraph("{:d} Alignments".format(section), self.heading_style)) self.story.append(Spacer(1, 0)) if bases: self.story.append(Paragraph("{:d}.{:d} Mapped bases (primary alignments)".format(section, next(subsection)), self.heading2_style)) for b, label in bases: im = svg2rlg(b) im = Image(im, width=im.width * self.plot_scale, height=im.height * self.plot_scale) im.hAlign = 'CENTER' self.story.append(Paragraph(label, self.normal_style)) self.story.append(im) self.story.append(Spacer(1, 0)) if counts: self.story.append(Paragraph("{:d}.{:d} Mapped reads".format(section, next(subsection)), self.heading2_style)) for c, label in counts: im = svg2rlg(c) im = Image(im, width=im.width * self.plot_scale, height=im.height * self.plot_scale) im.hAlign = 'CENTER' self.story.append(Paragraph(label, self.normal_style)) self.story.append(im) self.story.append(Spacer(1, 0)) if identity: self.story.append(Paragraph("{:d}.{:d} Read identity (primary alignments, all aligners)".format(section, next(subsection)), self.heading2_style)) for b, label in identity: im = svg2rlg(b) im = Image(im, width=im.width * self.plot_scale, height=im.height * self.plot_scale) im.hAlign = 'CENTER' self.story.append(Paragraph(label, self.normal_style)) self.story.append(im) self.story.append(Spacer(1, 0)) if coverage: self.story.append(Paragraph("{:d}.{:d} Coverage".format(section, next(subsection)), self.heading2_style)) im = svg2rlg(coverage[0]) im = Image(im, width=im.width * self.plot_scale, height=im.height * self.plot_scale) im.hAlign = 'CENTER' self.story.append(im) self.story.append(Spacer(1, 0)) self.story.append(Spacer(1, 0.5*cm))
Example #9
Source File: report.py From nanopype with MIT License | 5 votes |
def add_section_methylation(self, coverage=[]): section = self.get_section_number() subsection = itertools.count(1) self.story.append(Paragraph("{:d} Methylation".format(section), self.heading_style)) self.story.append(Spacer(1, 0)) if coverage: self.story.append(Paragraph("{:d}.{:d} CpG coverage".format(section, next(subsection)), self.heading2_style)) for f, label in coverage: im = svg2rlg(f) im = Image(im, width=im.width * self.plot_scale, height=im.height * self.plot_scale) im.hAlign = 'CENTER' self.story.append(Paragraph(label, self.normal_style)) self.story.append(im) self.story.append(Spacer(1, 0))
Example #10
Source File: generatereport.py From kobo-predict with BSD 2-Clause "Simplified" License | 5 votes |
def _header_footer(self, canvas, doc): # Save the state of our canvas so we can draw on it canvas.saveState() style_right = ParagraphStyle(name='right', parent=self.bodystyle, fontName='arialuni', fontSize=10, alignment=TA_RIGHT) fieldsight_logo = Image('http://' + self.base_url +'/static/images/fs1.jpg') fieldsight_logo._restrictSize(1.5 * inch, 1.5 * inch) # headerleft = Paragraph("FieldSight", self.bodystyle) headerright = Paragraph(self.project_name, style_right) # w1, h1 = headerleft.wrap(doc.width, doc.topMargin) w2, h2 = headerright.wrap(doc.width, doc.topMargin) textWidth = stringWidth(self.project_name, fontName='arialuni', fontSize=10) fieldsight_logo.drawOn(canvas, doc.leftMargin, doc.height + doc.topMargin + 12) headerright.drawOn(canvas, doc.leftMargin, doc.height + doc.topMargin + 20) try: project_logo = Image(self.project_logo) project_logo._restrictSize(0.4 * inch, 0.4 * inch) project_logo.drawOn(canvas, headerright.width + doc.leftMargin -0.5 * inch - textWidth, doc.height + doc.topMargin + 10) except: pass # header.drawOn(canvas, doc.leftMargin + doc.width, doc.height + doc.topMargin +20) # Footer footer = Paragraph('Page no. '+str(canvas._pageNumber), style_right) w, h = footer.wrap(doc.width, doc.bottomMargin) footer.drawOn(canvas, doc.leftMargin, h + 40) # Release the canvas canvas.restoreState()
Example #11
Source File: MyPDFDocument.py From FAE with GNU General Public License v3.0 | 5 votes |
def image(self, image_path, width=8 * cm, style=None): img = imread(image_path) x, y = img.shape[:2] image = Image(image_path, width=width, height=width * x / y) self.story.append(image)
Example #12
Source File: report.py From flask-restful-example with MIT License | 5 votes |
def image_model(): """ 添加图片 :return: """ template_path = current_app.config.get("REPORT_TEMPLATES") image_path = os.path.join(template_path, 'test.jpg') new_img = Image(image_path, width=300, height=300) return new_img
Example #13
Source File: fd_api_doc.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def create_img_table(self, dir): item_tbl_data = [] item_tbl_row = [] for i, file in enumerate(os.listdir(dir)): last_item = len(os.listdir(dir)) - 1 if ".png" in file: img = Image(os.path.join(dir, file), inch, inch) img_name = file.replace(".png", "") if len(item_tbl_row) == 4: item_tbl_data.append(item_tbl_row) item_tbl_row = [] elif i == last_item: item_tbl_data.append(item_tbl_row) i_tbl = Table([[img], [Paragraph(img_name, ParagraphStyle("item name style", wordWrap='CJK'))]]) item_tbl_row.append(i_tbl) if len(item_tbl_data) > 0: item_tbl = Table(item_tbl_data, colWidths=125) self.elements.append(item_tbl) self.elements.append(Spacer(1, inch * 0.5))
Example #14
Source File: generatereport.py From kobo-predict with BSD 2-Clause "Simplified" License | 4 votes |
def create_logo(self, absolute_path): try: image = Image(absolute_path) image._restrictSize(2.5 * inch, 2.5 * inch) except: image = Image('http://' + self.base_url +'/static/images/img-404.jpg') image._restrictSize(1.5 * inch, 1.5 * inch) return image