def addVerticalLine(self, col, color="blue"): """ Adds vertical lines only. Apply after inserting all data. :param col: the number of the column after which the vertical line is inserted :type col: int :param color: the color of the horizontal line :type color: str """ self.addTableStyleCommand( ("LINEAFTER", (col + self.offsetCol, 0), (col + self.offsetCol, -1), 0.4, color_dict().get(color)))
def addHorizontalLines(self, color="blue", offsetCol=None, exclude=[]): """ Adds horizontal lines only. Apply after inserting all data and after inserting the header line. If no header line exists also a top line is included. :param color: the color of the horizontal line :type color: str """ if offsetCol is None: offsetCol = self.offsetCol color = color_dict().get(color) for ri in range(self.headerRow, self.linesCount()): if ri in exclude: continue self.addTableStyleCommand( ("LINEBELOW", (offsetCol, ri), (-1, ri), 0.4, color)) if self.headerRow == 0: self.addTableStyleCommand( ("LINEABOVE", (offsetCol, 0), (-1, 0), 0.4, color))
def __init__(self, gridded=False, leftTablePadding=0, hTableAlignment=None, colWidths=None): """ :param gridded: if True, the table style is gridded, default is False :type gridded: bool :param leftTablePadding: if a number > 0 is inserted, the table gets a left empty column to be like left-padded :type leftTablePadding: int """ self.hTableAlignment = hTableAlignment or TA_CENTER self.colWidths = colWidths self.rightPadding = 0 self.spaceBefore = 0 self.spaceAfter = 0 self.tableData = list() self.tableStyleCommands = list() # for finalizing specific cell formats self.tableExtraStyleCommands = list() self.fontsize = 10 self.font = getFont(base_fonts()["normal"]) self.addTableStyleCommand( ('FONT', (0, 0), (-1, -1), base_fonts()["normal"])) if gridded: self.addTableStyleCommand( ("GRID", (0, 0), (-1, -1), 0.5, color_dict().get("black"))) if leftTablePadding: self.offsetCol = 1 self.leftTablePadding = leftTablePadding else: self.offsetCol = 0 self.leftTablePadding = 0 self.headerRow = 0 self.title = ''.join( random.choice(string.ascii_uppercase + string.digits) for _ in range(5)) # BUG: VALIGN does not work with different font sizes !!! self.addTableStyleCommand(('VALIGN', (0, 0), (-1, -1), 'BOTTOM')) self.addTableStyleCommand( ('FONTSIZE', (0, 0), (-1, -1), self.fontsize))
def addTableHeader(self, line, fonttype="bold", color="blue"): """ Prepends a table line to data and insert the correct styles, like double underline and bold. :param line: the data for the header line :type line: tuple, list :param fonttype: one of normal, bold, italic :type fonttype: str :param color: the color of the horizontal line :type color: str """ self.headerRow = 1 line = copy.copy(line) if isinstance(line, tuple): line = list(line) if self.leftTablePadding > 0: line.insert(0, "") self.tableData.insert(0, line) cmd = ('FONT', (self.offsetCol, 0), (-1, 0), base_fonts()[fonttype]) self.tableStyleCommands.append(cmd) self.addDoubleLine(color=color_dict().get(color))
from reportlab.platypus.flowables import SlowPageBreak, DDIndenter, PageBreakIfNotEmpty from reportlab.pdfgen import canvas from reportlab.lib.styles import ParagraphStyle # Configure Fonts! from reportlab.pdfbase.pdfdoc import PDFInfo from autobasedoc import base_fonts, color_dict, colors from autobasedoc.styledtable import StyledTable from autobasedoc.styles import StyleSheet, Styles from autobasedoc.pageinfo import addPlugin, PageInfo from autobasedoc.fonts import registerFont, setFonts, setTtfFonts, getFont from autobasedoc.tableofcontents import AutoTableOfContents _baseFontNames = base_fonts() _color_dict = color_dict() _basePath = os.path.realpath(os.path.dirname(__file__)) sys.path.append(_basePath) # #TODO: cx Freeze, this needs adoption to your version of cx_freeze # if _basePath.endswith("library.zip"): # _basePath = os.path.realpath(os.path.join(_basePath, '../')) __font_dir__ = os.path.realpath(os.path.join(_basePath, "fonts")) #__assets_dir__ = os.path.realpath(os.path.join(_basePath,"assets")) def reprFrame(frame): _dict = vars(frame) for key in sorted(list(_dict.keys())):