[reportlab-users] Bulleted text
Mike Dewhirst
miked at dewhirst.com.au
Thu Jun 29 05:44:37 EDT 2006
Saketh Bhamidipati wrote:
<snip>
My questions:
>
> 1. How can I get bullets to show up?
It is possible Python is silently barfing. Try bullet_char = chr(183)
> 2. How can I make a custom ParagraphStyle to pass to
> Story.append(Paragraph(text, style)) under the 'style' parameter?
I haven't had time to read your code coz I'm rushing. Also, what appears
below is a rushed effort (which works for me) which needs cleaning up.
It was cobbled together from the platypus examples in version 1.2
<excerpt>
import sys
from os import makedirs
from reportlab.lib.enums import TA_CENTER, TA_LEFT, TA_RIGHT, TA_JUSTIFY
from reportlab.platypus import * # includes tables.py
from reportlab.lib.colors import *
from reportlab.lib.units import inch
from reportlab.lib.styles import *
from reportlab.lib.pagesizes import A4
from reportlab.rl_config import defaultPageSize
PAGE_HEIGHT=defaultPageSize[1]
# # # # # # # # # # # # # # # # # # # # # # # # # # # #
# #
import names
import mdafs
from names import FORMDIR, PdfFont, IMAGES
f = PdfFont()
normal = f.normal
bold = f.bold
italic = f.italic
bold_italic = f.bold_italic
indent = f.indent
bullet_char = f.bullet_char
logo_name = f.logo_name
logo_x = f.logo_x
logo_y = f.logo_y
title_size = f.title_size
space_before_title = f.space_before_title
space_after_title = f.space_after_title
heading_size1 = f.heading_size + 4
heading_size2 = f.heading_size + 2
heading_size3 = f.heading_size # same size but italic
heading_size4 = f.heading_size # same size but italic
heading_size5 = f.heading_size - 2
heading_size6 = f.heading_size - 2 # same size but italic
space_before_heading = f.space_before_heading
space_after_heading = f.space_after_heading
para_font_size = f.para_font_size
space_before_para = f.space_before_para
space_after_para = f.space_after_para
space_before_indent = f.space_before_indent
space_after_indent = f.space_after_indent
space_before_bullet = f.space_before_bullet
space_after_bullet = f.space_after_bullet
leading_factor = f.leading_factor
def get_stylesheet():
"""Returns a stylesheet object"""
stylesheet = StyleSheet1()
stylesheet.add(ParagraphStyle(name='Normal',
fontName=normal,
fontSize=para_font_size,
leading=para_font_size *
leading_factor) )
stylesheet.add(ParagraphStyle(name='BodyText',
parent=stylesheet['Normal'],
spaceBefore=space_before_para,
spaceAfter=space_after_para) )
stylesheet.add(ParagraphStyle(name='BodyCenterText',
parent=stylesheet['BodyText'],
alignment=TA_CENTER) )
stylesheet.add(ParagraphStyle(name='BodyRightText',
parent=stylesheet['BodyText'],
alignment=TA_RIGHT) )
stylesheet.add(ParagraphStyle(name='Italic',
parent=stylesheet['BodyText'],
fontName = italic) )
stylesheet.add(ParagraphStyle(name='Indent',
parent=stylesheet['BodyText'],
firstLineIndent=0,
leftIndent=indent,
spaceBefore=space_before_indent,
spaceAfter=space_after_indent),
alias='bq')
stylesheet.add(ParagraphStyle(name='IndentIndent',
parent=stylesheet['Indent'],
leftIndent=indent + (indent * 0.67)),
alias='bqmore')
stylesheet.add(ParagraphStyle(name='Bullet',
parent=stylesheet['Indent'],
leftIndent=indent + (indent * 0.5),
bulletIndent=indent,
bulletFontName='Symbol',
bulletFontSize=para_font_size - 1,
spaceBefore=space_before_bullet,
spaceAfter=space_after_bullet),
alias='bu')
stylesheet.add(ParagraphStyle(name='BulletIndent',
parent=stylesheet['Bullet'],
leftIndent=indent + (indent * 0.67),
bulletIndent=indent + (indent * 0.5)),
alias='bumore')
stylesheet.add(ParagraphStyle(name='Title',
parent=stylesheet['Normal'],
fontName = bold,
fontSize=title_size,
leading=0, #title_size, # *
leading_factor,
alignment=TA_CENTER,
spaceBefore=space_before_title,
spaceAfter=space_after_title),
alias='title')
stylesheet.add(ParagraphStyle(name='Heading1',
parent=stylesheet['Normal'],
fontName = bold,
fontSize=heading_size1,
leading=heading_size1 * leading_factor,
spaceAfter=space_after_heading),
alias='h1')
stylesheet.add(ParagraphStyle(name='Heading2',
parent=stylesheet['Normal'],
fontName = bold,
fontSize=heading_size2,
leading=heading_size2 * leading_factor,
spaceBefore=space_before_heading,
spaceAfter=space_after_heading),
alias='h2')
stylesheet.add(ParagraphStyle(name='Heading3',
parent=stylesheet['Normal'],
fontName = bold,
fontSize=heading_size3,
leading=heading_size3 * leading_factor,
spaceBefore=space_before_heading,
spaceAfter=space_after_heading),
alias='h3')
stylesheet.add(ParagraphStyle(name='Heading4',
parent=stylesheet['Normal'],
fontName = bold_italic,
fontSize=heading_size4,
leading=heading_size4 * leading_factor,
spaceBefore=space_before_heading,
spaceAfter=space_after_heading),
alias='h4')
stylesheet.add(ParagraphStyle(name='Heading5',
parent=stylesheet['Normal'],
fontName = bold,
fontSize=heading_size5,
leading=heading_size5 * leading_factor,
spaceBefore=space_before_heading - 4,
spaceAfter=space_after_heading),
alias='h5')
stylesheet.add(ParagraphStyle(name='Heading6',
parent=stylesheet['Normal'],
fontName = bold_italic,
fontSize=heading_size6,
leading=heading_size6 * leading_factor,
spaceBefore=space_before_heading - 4,
spaceAfter=space_after_heading),
alias='h6')
stylesheet.add(ParagraphStyle(name='Code',
parent=stylesheet['Normal'],
fontName='Courier',
fontSize=8,
leading=9,
firstLineIndent=0,
leftIndent=indent + (indent * 0.5)),
alias='pre')
return stylesheet
##
styles = get_stylesheet()
TitleStyle = styles['Title']
HeaderStyle1 = styles['Heading1']
HeaderStyle2 = styles['Heading2']
HeaderStyle3 = styles['Heading3']
HeaderStyle4 = styles['Heading4']
HeaderStyle5 = styles['Heading5']
HeaderStyle6 = styles['Heading6']
ParaStyle = styles['BodyText']
ParaCenterStyle = styles['BodyCenterText']
ParaRightStyle = styles['BodyRightText']
IndentStyle = styles['Indent']
BulletStyle = styles['Bullet']
# new styles
IndentIndentStyle = styles['IndentIndent']
BulletIndentStyle = styles['BulletIndent']
PreStyle = styles['Code']
# #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# next comes my story list class etc
#
</excerpt>
Hope this helps.
Regards
mike
> 3. How can I choose which frame I am writing the text in? (I need to
> make another frame for the headings in a column to the left; right now I
> only have the right column.)
>
> Thank you very much - I am in the last stage of writing my note-taking
> application, and the PDF exporting functionality is key.
>
> -Saketh
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> reportlab-users mailing list
> reportlab-users at reportlab.com
> http://two.pairlist.net/mailman/listinfo/reportlab-users
More information about the reportlab-users
mailing list