[reportlab-users] pythonpoint / pgpgen bookmarking question or maybe bug?

Karl N. Redman karlredman at marketsystems.com
Tue Oct 11 19:52:41 EDT 2005


Hi,
I'm trying to add a <bookmark name="somename" outlinelevel=1 /> type tag 
at the slide level (or any level for that mater) of the XML hiararchy 
for pythonpoint. I've successfully edited my pythonpoint.dtd to add the 
bookmark tag and I've inherited from PPPSlide and PPMLParser classes in 
order to override the necessary methods for handling my new tag. 
However, when I try to add a new bookmark (through the Canvas object) I 
get the the exception "ValueError: format not resolved " from line 1469 
of pdfdoc.py.

The issue only comes up when a call to Canvas.addOutlineEntry() has been 
called with the 'title' and 'key' parameters containing different values 
(ie. 'mybookmarktitle', 'bookmarknumber1234' respectively). I need to be 
able to have duplicate titles for bookmarks in the outline but have 
those bookmarks indexed by different keys. Otherwise the library just 
indexes one bookmark so that it only points to one page even though the 
outline shows the bookmark twice.

For example I need my outline to look this this:

Cover Page

Section I.

    subsection a.

    subsection b.

Section II.

    subsection a.

    subsection b.

    subsection c.


Some 'subsection' bookmarks may refer to the same page (or at least 
that's what I want to do). I realize that the Slide concept for 
pythonpoint slightly conflicts with my wanting to allow having multiple 
bookmarks refer to a single page. But there is really no reason why I 
shouldn't be able to accomplish this anyway. What am I missing here? Why 
am I getting this seemingly unrelated exception?


Here's my Traceback:

Traceback (most recent call last):

  File "msi_report.py", line 574, in ?

    report.renderReport_pdf()

  File "msi_report.py", line 260, in renderReport_pdf

    pdfDoc = XML2PDF(self.__outputFileName, buff)

  File "msi_report.py", line 294, in __init__

    pdfcontent = pres.save()

  File "/usr/lib/python2.3/site-packages/reportlab/tools/pythonpoint/pythonpoint.py", line 449, in save

    return self.saveAsPresentation()

  File "/usr/lib/python2.3/site-packages/reportlab/tools/pythonpoint/pythonpoint.py", line 395, in saveAsPresentation

    canv.save()

  File "/usr/lib/python2.3/site-packages/reportlab/pdfgen/canvas.py", line 831, in save

    self._doc.SaveToFile(self._filename, self)

  File "/usr/lib/python2.3/site-packages/reportlab/pdfbase/pdfdoc.py", line 233, in SaveToFile

    f.write(self.GetPDFData(canvas))

  File "/usr/lib/python2.3/site-packages/reportlab/pdfbase/pdfdoc.py", line 255, in GetPDFData

    return self.format()

  File "/usr/lib/python2.3/site-packages/reportlab/pdfbase/pdfdoc.py", line 378, in format

    IOf = IO.format(self)

  File "/usr/lib/python2.3/site-packages/reportlab/pdfbase/pdfdoc.py", line 727, in format

    fcontent = format(content, document, toplevel=1) # yes this is at top level

  File "/usr/lib/python2.3/site-packages/reportlab/pdfbase/pdfdoc.py", line 95, in format

    f = fmt(document)

  File "/usr/lib/python2.3/site-packages/reportlab/pdfbase/pdfdoc.py", line 1065, in format

    return PD.format(document)

  File "/usr/lib/python2.3/site-packages/reportlab/pdfbase/pdfdoc.py", line 566, in format

    fv = format(v, document)

  File "/usr/lib/python2.3/site-packages/reportlab/pdfbase/pdfdoc.py", line 95, in format

    f = fmt(document)

  File "/usr/lib/python2.3/site-packages/reportlab/pdfbase/pdfdoc.py", line 1469, in format

    if f is None: raise ValueError, "format not resolved %s" % self.name

ValueError: format not resolved



Here's an example of the code I'm running. Note this code would only 
work for a single instance of a <bookmark/> but you get the point.

class XML2PDF(object):

    """expects layout to be for 8.5x11 paper

    """

    def __init__(self, outputFileName, inputBuffer):

        #valideate the xml

        pythonpoint.validate(inputBuffer)

        #parse setup parser object

        self.parser = myPPMLParser()

        self._processCommonOptions(inputBuffer, outputFileName)

        self.parser.sourceFilename = outputFileName

        self.parser.feed(inputBuffer)

        

        #get the presentation object

        pres = self.parser.getPresentation()

        #set page dimentions

        pres.pageWidth = pagesizes.LETTER[0]

        pres.pageHeight = pagesizes.LETTER[1]

        #set other parameters

        pres.sourceFilename = outputFileName

        

        #fix slides that may be hidden in the xml data

        pres.slides = pythonpoint.handleHiddenSlides(pres.slides)

        #do the work and save the file

        pdfcontent = pres.save()

        pass

    def _processCommonOptions(self, rawdata, datafilename, notes=0, handout=0, printout=0, cols=0, verbose=0, outDir=None, fx=1):

        #print 'inner process fx=%d' % fx

        self.parser.fx = fx

        self.parser.sourceFilename = datafilename

        self.parser.outDir = outDir

        self.parser.notes = notes

        self.parser.handout = handout

        self.parser.printout = printout

        self.parser.cols = cols

        self.parser.verbose = verbose

        pass ##end class

    

class myPPMLParser(stdparser.PPMLParser):

    def start_bookmark(self, args):

        if (args.has_key('name')):

            self._curSlide.bookmarkName = args['name']

        if (args.has_key('incOutlinelevel')):

            self._curSlide.outlinelevel = args['incOutlinelevel']

        else:

            self._curSlide.outlinelevel = 1

    def start_slide(self, args):

        s = myPPSlide()

        s.id = self._arg('slide',args,'id')

        s.title = self._arg('slide',args,'title')

        a = self._arg('slide',args,'effectname')

        if a <> 'None':

            s.effectName = a

        s.effectDirection = self.ceval('slide',args,'effectdirection')

        s.effectDimension = self._arg('slide',args,'effectdimension')

        s.effectDuration = self.ceval('slide',args,'effectduration')

        s.effectMotion = self._arg('slide',args,'effectmotion')

        #HACK - may not belong here in the long run...

        #by default, use the slide title for the outline entry,

        #unless it is specified as an arg.

        a = self._arg('slide',args,'outlineentry')

        if a == "Hide":

            s.outlineEntry = None

        elif a <> 'None':

            s.outlineEntry = a

        else:

            s.outlineEntry = s.title

        s.outlineLevel = self.ceval('slide',args,'outlinelevel')

        #let it know its section, which may be none

        s.section = self._curSection

        self._curSlide = s




class myPPSlide(pythonpoint.PPSlide):

    def __init__(self):

        pythonpoint.PPSlide.__init__(self)

        self.bookmarkName = None

        self.incOutlinelevel = None

    def drawOn(self, canv):

        pythonpoint.PPSlide.drawOn(self, canv)

        if ( self.bookmarkName != None):

            canv.bookmarkPage(self.bookmarkName)

	    # THIS SEEMS BROKEN !!!!!!!!!!!!!!!!!!!!!
            canv.addOutlineEntry(self.bookmarkName, self.bookmarkName+"x", self.incOutlinelevel)




More information about the reportlab-users mailing list