コード例 #1
0
def makeDocument():

    doc = Document(originTop=False, w=W, h=H, autoPages=1)
    doc.addStyle('h1', dict(textFill=0))
    doc.addStyle('h2', dict(textFill=0))
    doc.addStyle('p', dict(textFill=0))

    page = doc[0]  # Get the first/single page of the document.
    page.padding = 40  # TODO: order if 4 values?

    # Make rect as page element centered with centered origin.
    conditions = [Fit()]

    g = Galley(parent=page, conditions=conditions, textFill=0)
    ts = Typesetter(doc, g)
    print ts
    ts.typesetFile(markdownPath)

    # Solve the layout conditions of the red rectangle.
    # Show if one of the conditions failed to solve.
    score = page.solve()
    if score.fails:
        print 'Failed conditions', score.fails

    # Set the view parameters for the required output.
    view = doc.getView()
    view.padding = 0  # Make view padding to show crop marks and frame
    view.showPageFrame = True  # Show frame of the page in blue
    #view.showPagePadding = True
    view.showPageCropMarks = True  # Show crop marks

    return doc
コード例 #2
0
def makeDocument():
    """Make a new document."""

    W = H = PageSize

    # Create a new document, default to the defined page size.
    doc = Document(w=W, h=H, originTop=False, title='Text Flow', autoPages=2)

    rs = doc.getRootStyle()
    rs['fill'] = (1, 1, 0)  # Yellow background for debugging
    rs['font'] = 'Verdana'
    rs['fontSize'] = 14
    rs['textFill'] = 1

    #textBoxStyle = doc.addStyle('textbox', dict(fill=color(0, 0, 0, 0.7),
    #                                            padding=40))
    pStyle = doc.addStyle('p', dict(textFill=blackColor))
    h1Style = doc.addStyle('h1', dict(fontSize=24, textFill=(0, 0, 1)))
    #h2Style = doc.addStyle('h2', dict(fontSize=18, textFill=(0, 1, 0)))

    view = doc.getView()
    view.padding = 0  # Aboid showing of crop marks, etc.
    view.showCropMarks = True
    view.showRegistrationMarks = True
    view.showFrame = True
    view.showPadding = True
    view.showOrigin = True
    view.showDimensions = False

    # Get list of pages with equal y, then equal x.
    #page = doc[1][0] # Get the single page from the document.
    page0 = doc.getPage(1)  # Get page on pageNumber,
    # first in row (this is only one now).
    page0.name = 'Page 1'
    page0.padding = PagePadding

    s = doc.context.newString('Headline\n', style=h1Style)
    for n in range(10):
        s += doc.context.newString(('(Line %d) Volume of text defines'
                                    ' the box height.'
                                    ' Volume of text defines'
                                    ' the box height. \n') % (n + 1),
                                   style=pStyle)
        h1 = None

    e1 = newTextBox(
        s,
        name='CSSTextBox1',
        parent=page0,
        padding=4,
        x=100,
        font='Verdana',
        h=h1,
        mb=20,
        mr=10,  # Conditions make the element
        # move to top-left of the page.
        gridX=((fr(3), px(8)), (fr(2), px(8))),
        # And the condition that there should be no overflow,
        # otherwise the text box will try to solve it.
        conditions=[Left2Left(), Fit2Width(),
                    Float2Top()],
        # Position of the origin of the element.
        # Just to show where it is.
        # Has no effect on the position conditions.
        yAlign=BOTTOM,
        xAlign=LEFT,
        leading=5,
        fontSize=9,
        textFill=blackColor,
        strokeWidth=pt(0.5),
        fill=color(0.9),
        stroke=noColor)
    print(e1.style)

    newTextBox(
        s,  # Empty box, will get the overflow
        # from e1, if there is any.
        name='CSSTextBox2',  # Flow reference by element.name
        parent=page0,
        padding=4,
        x=100,
        h=200,
        conditions=[Left2Left(), Fit2Width(),
                    Float2Top()],
        yAlign=TOP,
        fill=whiteColor,
        stroke=noColor)

    score = doc.solve()  # Try to solve all pages.
    if score.fails:
        print(score.fails)

    return doc  # Answer the doc for further doing.
コード例 #3
0
ファイル: UseMarkDownText.py プロジェクト: jkim828/PageBot
from pagebot.document import Document
from pagebot.elements import *
from pagebot.conditions import *
from pagebot.typesetter import Typesetter
from pagebot.toolbox.color import color, blackColor
from pagebot.constants import A4

W, H = A4

MARKDOWN_PATH = 'EmbeddedPython.md'

context = getContext()

doc = Document(originTop=False, w=W, h=H, autoPages=1)
#print(doc.styles.keys())
doc.addStyle('h1', dict(textFill=blackColor), force=True)
doc.addStyle('h2', dict(textFill=blackColor), force=True)
doc.addStyle('p', dict(textFill=blackColor), force=True)

ts = Typesetter(context, doc.styles, g)
ts.typesetFile(MARKDOWN_PATH)

page = doc[1]  # Get the first/single page of the document.
page.padding = 40  # TODO: order if 4 values?

# Make rect as page element centered with centered origin.
conditions = [Fit()]
g = newTextBox(parent=page,
               conditions=conditions,
               textFill=blackColor,
               autoPages=10)