View Single Post
Old 04-24-2007, 12:24 AM   #17
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,435
Karma: 27757438
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
I've added support for inline graphics to pylrs. Attached is a demo with the python code to create it.

@Falstaff The patch is available at
pylrs.py
https://libprs500.kovidgoyal.net/cha...lrs.py&new=235
pylrf.py
https://libprs500.kovidgoyal.net/cha...lrf.py&new=235

Here's the python code to create helloworld.lrf
Code:
from libprs500.lrf.pylrs.pylrs import *

"""
    TextBlocks can be added to any page at any time, since the entire book is
    kept in memory.  Text can also be added to any paragraph at any time.
"""

def helloworld():
    # create the book
    book = Book()

    # add a page to the book using the default page style
    page = book.Page()
    page.TextBlock().Paragraph('Demonstration of embedded graphics').CR()
    

    # add a textblock to the page using defaults for TextStyle and BlockStyle 
    textBlock = page.TextBlock()
    textBlock.blockStyle = BlockStyle(blockrule='horz-fixed', blockwidth='575')

    # add a paragraph to the text block 
    istr = ImageStream('/tmp/try/cherubs.jpg')
    im = Image(istr, x0=0, y0=0, x1=300, y1=300, xsize=100, ysize=100)
    p = Paragraph('This line of text is before the graphic. ')
    dc = DrawChar(lines=3)
    dc.append(Plot(im, xsize=450, ysize=450))
    p.append(dc)
    textBlock.append(p)
    textBlock.Paragraph('This line of text is after the graphic. It needs to be long enough to ensure that the graphic is not cut-off.')
    
    

    # generate the lrf file
    book.renderLrs("/tmp/helloworld.lrs")
    book.renderLrf("/home/kovid/helloworld.lrf")


if __name__ == "__main__":
    helloworld()
Attached Files
File Type: lrf helloworld.lrf (20.4 KB, 453 views)
kovidgoyal is offline   Reply With Quote