def test_write_document(self): # create output directory if it does not exist yet if not self.output_dir.exists(): self.output_dir.mkdir() # create document pdf = Document() # add page page = Page() pdf.append_page(page) layout = SingleColumnLayout(page) t = Table(number_of_rows=10, number_of_columns=4) t.add( Paragraph( "lowercase", font_color=X11Color("YellowGreen"), horizontal_alignment=Alignment.CENTERED, )) t.add( Paragraph( "uppercase", font_color=X11Color("YellowGreen"), horizontal_alignment=Alignment.CENTERED, )) t.add( Paragraph( "lowercase acute", font_color=X11Color("YellowGreen"), horizontal_alignment=Alignment.CENTERED, )) t.add( Paragraph( "uppercase acute", font_color=X11Color("YellowGreen"), horizontal_alignment=Alignment.CENTERED, )) # A font: Font = TrueTypeFont.true_type_font_from_file( Path(__file__).parent / "Pacifico.ttf") t.add(Paragraph("a", font=font)) t.add(Paragraph("A", font=font)) t.add(Paragraph("á", font=font)) t.add(Paragraph("Á", font=font)) # B t.add(Paragraph("b", font=font)) t.add(Paragraph("B", font=font)) t.add(Paragraph("-", font=font)) t.add(Paragraph("-", font=font)) # C t.add(Paragraph("c", font=font)) t.add(Paragraph("C", font=font)) t.add(Paragraph("-", font=font)) t.add(Paragraph("-", font=font)) # D t.add(Paragraph("d", font=font)) t.add(Paragraph("D", font=font)) t.add(Paragraph("-", font=font)) t.add(Paragraph("-", font=font)) # E t.add(Paragraph("e", font=font)) t.add(Paragraph("E", font=font)) t.add(Paragraph("é", font=font)) t.add(Paragraph("É", font=font)) # F t.add(Paragraph("f", font=font)) t.add(Paragraph("F", font=font)) t.add(Paragraph("-", font=font)) t.add(Paragraph("-", font=font)) # G t.add(Paragraph("g", font=font)) t.add(Paragraph("G", font=font)) t.add(Paragraph("-", font=font)) t.add(Paragraph("-", font=font)) # .. t.add( Paragraph( "...", font_color=X11Color("LightGray"), horizontal_alignment=Alignment.CENTERED, )) t.add( Paragraph( "...", font_color=X11Color("LightGray"), horizontal_alignment=Alignment.CENTERED, )) t.add( Paragraph( "...", font_color=X11Color("LightGray"), horizontal_alignment=Alignment.CENTERED, )) t.add( Paragraph( "...", font_color=X11Color("LightGray"), horizontal_alignment=Alignment.CENTERED, )) # Z t.add(Paragraph("z", font=font)) t.add(Paragraph("Z", font=font)) t.add(Paragraph("-", font=font)) t.add(Paragraph("-", font=font)) t.set_border_width_on_all_cells(Decimal(0.2)) t.set_padding_on_all_cells(Decimal(5), Decimal(5), Decimal(5), Decimal(5)) layout.add(t) layout.add( Paragraph( text= "**These are the characters pText can currently render in a PDF", font_size=Decimal(8), font_color=X11Color("Gray"), horizontal_alignment=Alignment.RIGHT, )) # determine output location out_file = self.output_dir / ("output.pdf") # attempt to store PDF with open(out_file, "wb") as in_file_handle: PDF.dumps(in_file_handle, pdf) # attempt to re-open PDF with open(out_file, "rb") as in_file_handle: PDF.loads(in_file_handle)
def test_write_document(self): # create output directory if it does not exist yet if not self.output_dir.exists(): self.output_dir.mkdir() # create document pdf = Document() # add page page = Page() pdf.append_page(page) # set layout layout = SingleColumnLayout(page) my_dict = { " ": ["A Error", "B Error", "C Error", "D Error"], "lab1": [0.34, 0.23, 0.80, 0.79], "lab2": [0.53, 0.38, 0.96, 1.25], "lab3": [0.40, 0.27, 0.68, 0.93], } colors = { 0: X11Color("Green"), 0.25: X11Color("Yellow"), 0.5: X11Color("Orange"), 0.75: X11Color("Red"), } table = Table(number_of_rows=4, number_of_columns=5) table.add(Paragraph(" ", respect_spaces_in_text=True)) for h in my_dict[" "]: table.add( Paragraph(text=h, font="Helvetica-Bold", font_size=Decimal(12))) for name, row in [(k, v) for k, v in my_dict.items() if k != " "]: table.add(Paragraph(name)) for v in row: c = X11Color("Green") for b, bc in colors.items(): if v > b: c = bc table.add( Paragraph(str(v), font_color=c, horizontal_alignment=Alignment.CENTERED)) # set border table.set_border_width_on_all_cells(Decimal(0.2)) # set padding table.set_padding_on_all_cells(Decimal(5), Decimal(5), Decimal(5), Decimal(5)) # add to layout layout.add( Paragraph( "This table contains all measurands for 3 lab-sessions:")) layout.add(table) # determine output location out_file = self.output_dir / ("output.pdf") # attempt to store PDF with open(out_file, "wb") as in_file_handle: PDF.dumps(in_file_handle, pdf) # attempt to re-open PDF with open(out_file, "rb") as in_file_handle: PDF.loads(in_file_handle)
def test_write_document(self): # create output directory if it does not exist yet if not self.output_dir.exists(): self.output_dir.mkdir() # create document pdf = Document() # add page page = Page() pdf.append_page(page) t = Table(number_of_rows=5, number_of_columns=3) t.add(Paragraph(" ", respect_spaces_in_text=True)) t.add( Paragraph( "Close-up", font_color=X11Color("SteelBlue"), font_size=Decimal(20), horizontal_alignment=Alignment.CENTERED, )) t.add( Paragraph( "Panoramic", font_color=X11Color("SteelBlue"), font_size=Decimal(20), horizontal_alignment=Alignment.CENTERED, )) t.add(Paragraph("Nature")) self._add_image_to_table( "https://images.unsplash.com/photo-1520860560195-0f14c411476e?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw", t, ) self._add_image_to_table( "https://images.unsplash.com/photo-1613480123595-c5582aa551b9?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw", t, ) t.add(Paragraph("Architecture")) self._add_image_to_table( "https://images.unsplash.com/photo-1611321569296-1305a38ebd74?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw", t, ) self._add_image_to_table( "https://images.unsplash.com/photo-1613262666714-acebcc37f11e?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw", t, ) t.set_border_width_on_all_cells(Decimal(0.2)) t.set_padding_on_all_cells(Decimal(5), Decimal(5), Decimal(5), Decimal(5)) layout = SingleColumnLayout(page) layout.add(t) # determine output location out_file = self.output_dir / ("output.pdf") # attempt to store PDF with open(out_file, "wb") as in_file_handle: PDF.dumps(in_file_handle, pdf) # attempt to re-open PDF with open(out_file, "rb") as in_file_handle: PDF.loads(in_file_handle)
def test_write_document(self): # create output directory if it does not exist yet if not self.output_dir.exists(): self.output_dir.mkdir() # create document pdf = Document() # add page page = Page() pdf.append_page(page) t = Table(number_of_rows=5, number_of_columns=3) t.add( TableCell( Paragraph(" ", respect_spaces_in_text=True), border_top=False, border_left=False, ) ) t.add( Paragraph( "Language", font_color=X11Color("SteelBlue"), font_size=Decimal(20) ) ) t.add( Paragraph( "Nof. Questions", font_color=X11Color("SteelBlue"), font_size=Decimal(20), ) ) t.add( TableCell( Paragraph("front-end", font_color=X11Color("SteelBlue")), row_span=2 ) ) t.add(Paragraph("Javascript")) t.add(Paragraph("2,167,178")) t.add(Paragraph("Php")) t.add(Paragraph("1,391,524")) t.add( TableCell( Paragraph("back-end", font_color=X11Color("SteelBlue")), row_span=2 ) ) t.add(Paragraph("C++")) t.add(Paragraph("711,944")) t.add(Paragraph("Java")) t.add(Paragraph("1,752,877")) t.set_border_width_on_all_cells(Decimal(0.2)) t.set_padding_on_all_cells(Decimal(5), Decimal(5), Decimal(5), Decimal(5)) table_rect = t.layout( page, bounding_box=Rectangle( Decimal(20), Decimal(600), Decimal(500), Decimal(200) ), ) Paragraph( text="**Data gathered from Stackoverflow.com on 10th of february 2021", font_size=Decimal(8), font_color=X11Color("Gray"), ).layout( page, bounding_box=Rectangle( Decimal(20), table_rect.y - 40, table_rect.width, Decimal(20) ), ) # determine output location out_file = self.output_dir / ("output.pdf") # attempt to store PDF with open(out_file, "wb") as in_file_handle: PDF.dumps(in_file_handle, pdf) # attempt to re-open PDF with open(out_file, "rb") as in_file_handle: PDF.loads(in_file_handle)