[reportlab-users] Bulleted text

Saketh Bhamidipati saketh.bhamidipati at gmail.com
Wed Jun 28 23:03:21 EDT 2006


On 6/28/06, Andy Robinson <andy at reportlab.com> wrote:
>
> > So, in summary, here are my two questions:
> >
> >    1. How can I turn asterisks in a text into bullets, and draw the
> >       bullets to the canvas?
> >    2. How can I make drawText append the text to the end of the last
> >       drawText, and go to the next page if necessary?
> >
> > Thank you in advance for the assistance! It is greatly appreciated.
>
> Get to grips with Platypus, the 'next level up'.  It is designed to
> handle paragraphs, paragraph styles, flow over pages and so on.
> Paragraph classes also have a 'bullet' feature so you can define the
> 'bullet string'; this might be a special character.  you construct a
> sequence of paragraphs in a bulleted style, instead of drawing on the
> page yourself.
>
> To start learning, examine the test scripts matching
>    reportlab\test\test_platypus_*.py
> and run them and look at their PDF output.  You will find examples of
> bullets.
>
>
>
> Also, make sure you are on ReportLab 2.0 which accepts Unicode strings
> as input to just about everything.  Python DOES natively use Unicode if
> you work throughout with Unicode strings:
>
> utext = unicode(text)
> utext.replace(u'*', u'\N{BULLET}
>
>
> Good luck,
>
>
> - Andy
>
> _______________________________________________
> reportlab-users mailing list
> reportlab-users at reportlab.com
> http://two.pairlist.net/mailman/listinfo/reportlab-users
>
Platypus is so much better! But I am still confused.

Here is my code so far - I'm trying to avoid the unicode stuff and I'm
trying to just use ReportLab's bullets:
#!/usr/bin/python

from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer
from reportlab.platypus.doctemplate import PageTemplate, BaseDocTemplate
from reportlab.platypus.frames import Frame
from reportlab.lib.styles import getSampleStyleSheet
from reportlab.rl_config import defaultPageSize
from reportlab.platypus.xpreformatted import XPreformatted
from reportlab.lib.styles import ParagraphStyle, PropertySet
from reportlab.lib.enums import TA_LEFT, TA_CENTER, TA_RIGHT
from reportlab.lib.units import inch
from reportlab.lib.colors import black
PAGE_HEIGHT = defaultPageSize[1]; PAGE_WIDTH = defaultPageSize[0]
styles = getSampleStyleSheet()

Title = "Hello, World!"
Author = "Saketh Bhamidipati"

class ParagraphStyle(PropertySet):
    defaults = {
        'fontName':'Times-Roman',
        'fontSize':12,
        'leading':12,
        'leftIndent': inch,
        'rightIndent': inch,
        'firstLineIndent': 0,
        'alignment':TA_LEFT,
        'spaceBefore':0,
        'spaceAfter':0,
        'bulletFontName':'Times-Roman',
        'bulletFontSize':10,
        'bulletIndent': 6,
        'textColor': black
        }



class NotalonTemplate(BaseDocTemplate):
    def __init__(self, filename, **kw):
        textframe = Frame(2 * inch, 2 * inch, 5.75 * inch, 8 * inch, id =
'TF')
        self.allowSplitting = 0
        self.showBoundary = 1
        apply(BaseDocTemplate.__init__, (self, filename), kw)
        template = PageTemplate('TwoColumns', [textframe], myPageTemplate)
        self.addPageTemplates(template)

def myPageTemplate(canvas, doc):
    canvas.saveState()
    canvas.setFont('Times-Roman', 12)
    canvas.drawCentredString(PAGE_WIDTH / 2.0, PAGE_HEIGHT - 108, Title)
    canvas.drawString(PAGE_WIDTH - 2 * inch, PAGE_HEIGHT - inch, Author)
    canvas.setFont('Times-Roman', 10)
    canvas.drawCentredString(PAGE_WIDTH / 2.0, inch / 2.0, "%d" % doc.page)
    canvas.restoreState()

def go():
    doc = NotalonTemplate("hanuman.pdf")
    Story = [Spacer(0, 0)]
    style = styles["Normal"]
    Story.append(Paragraph("<bullet>This is bulleted text.</bullet>",
style))
    doc.build(Story)
go()

Although this code generates a PDF file, there is no bulleted text that
shows up. When I remove the <bullet> tags, however, the "This is bulleted
text" shows up. If I pass the text as the bulletText parameter, the bullet
doesn't show up, but the text does. This is confusing.

As you can see, I don't understand ParagraphStyles either - if someone could
please help me replace my default style with the ParagraphStyle, I would
appreciate it greatly.

My questions:

   1. How can I get bullets to show up?
   2. How can I make a custom ParagraphStyle to pass to
Story.append(Paragraph(text,
   style)) under the 'style' parameter?
   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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://two.pairlist.net/pipermail/reportlab-users/attachments/20060628/4739a052/attachment.htm


More information about the reportlab-users mailing list