Ejemplo n.º 1
0
def demoPDF(html):
    import piddlePDF
    pc = piddlePDF.PDFCanvas((750, 1000), 'HTMLPiddler.pdf')
    pc.drawLine(100, 100, 250, 150, color=piddle.green)
    pc.drawRect(100, 100, 650, 900, edgeColor=piddle.pink)
    ptt = HTMLPiddler(html, (250, 150), (100, 650))
    ptt.renderOn(pc)
    pc.save()
Ejemplo n.º 2
0
def test2():
    canvas = piddlePDF.PDFCanvas('test2.pdf')

    drawString(canvas, "<alpha/>", 10, 10)

    #	drawString(canvas, "&amp;", 10, 10)
    drawString(canvas, "&alpha;", 10, 30)
    #	drawString(canvas, "a", 10, 50, Font(face="symbol"))
    #	drawString(canvas, "hello there!", 30, 90, angle= -90)
    #	drawString(canvas, "<b>goodbye!</b> <u>yall</u>", 100, 90, angle= 45)
    #	drawString(canvas, "there is a <u>time</u> and a <b>place</b><super>2</super>",
    #		100, 90, angle= -75)
    canvas.flush()
Ejemplo n.º 3
0
def test1():
    canvas = piddlePDF.PDFCanvas('test1.pdf')
    drawString(canvas, "<u><b>hello there</b></u><super>hi</super>", 10, 20)
    drawString(canvas, "hello!", 10, 40)

    print "'hello!' width = ", stringWidth(canvas, "hello!")
    print "'hello!' PIDDLE width = ", canvas.stringWidth("hello!")

    drawString(canvas, "<b>hello!</b> goodbye", 10, 60)
    print "'<b>hello!</b> goodbye' width = ", stringWidth(
        canvas, "<b>hello!</b> goodbye")
    drawString(canvas, "hello!", 10, 80, Font(bold=1))
    print "'hello!' Font(bold=1) PIDDLE width = ", canvas.stringWidth(
        "hello!", Font(bold=1))
    drawString(canvas, " goodbye", 10, 100)
    print "' goodbye' PIDDLE width = ", canvas.stringWidth(" goodbye")
    canvas.flush()
Ejemplo n.º 4
0
def stringformatTest():

    # change the following line only to try a different PIDDLE backend
    canvas = piddlePDF.PDFCanvas('bigtest1.pdf')

    ################################################### testing drawString tags
    #      < b > < /b > - bold
    #      < i > < /i > - italics
    #      < u > < /u > - underline
    #      < super > < /super > - superscript
    #      < sub > < /sub > - subscript

    x = 10
    y = canvas.defaultFont.size * 1.5

    ##### try out each possible tags and all combos
    (x, y) = allTagCombos(canvas, x, y)

    ##### now try various fonts
    (x, y) = allTagCombos(canvas, x, y + 30, Font(face="serif"))
    (x, y) = allTagCombos(canvas, x, y + 30, Font(face="monospaced"))

    # what about rotated
    (x, y) = allTagCombos(canvas, x, y + 30, Font(face="serif"), angle=-30)

    ##### now try a couple of different font sizes
    (x, y) = allTagCombos(canvas, x, y + 30, Font(size=16))
    (x, y) = allTagCombos(canvas, x, y + 30, Font(size=9))

    ##### now try a different default style setting
    (x, y) = allTagCombos(canvas, x, y + 30, Font(underline=1))

    ##### now try a combo of the above 4 and a different color
    (x, y) = allTagCombos(canvas, x, y + 30, color=red)

    ################################################### testing stringWidth tags
    sfwidth = stringWidth(
        canvas,
        "<b><sub>bold+sub</sub></b> hello <u><super>underline+super</super></u>"
    )

    # break down the various string widths
    print 'sw("<b><sub>bold+sub</sub></b>") = ', stringWidth(
        canvas, "<b><sub>bold+sub</sub></b>")
    print 'sw(" hello ") = ', stringWidth(canvas, " hello ")
    print 'sw("<u><super>underline+super</super></u>") = ', \
     stringWidth(canvas,"<u><super>underline+super</super></u>")

    pwidth1 = canvas.stringWidth(
        "bold+sub", Font(size=canvas.defaultFont.size - sizedelta, bold=1))
    print "pwidth1 = ", pwidth1
    pwidth2 = canvas.stringWidth(" hello ")
    print "pwidth2 = ", pwidth2
    pwidth3 = canvas.stringWidth(
        "underline+super",
        Font(size=canvas.defaultFont.size - sizedelta, underline=1))
    print "pwidth3 = ", pwidth3

    # these should be the same
    print "sfwidth = ", sfwidth, " pwidth = ", pwidth1 + pwidth2 + pwidth3

    ################################################### testing greek characters
    # looks better in a larger font
    canvas = piddlePDF.PDFCanvas('bigtest2.pdf')
    x = 10
    y = canvas.defaultFont.size * 1.5
    drawString(canvas,
               "&alpha; &beta; <chi/> &Delta; <delta/>",
               x,
               y,
               Font(size=16),
               color=blue)
    print "line starting with alpha should be font size 16"
    y = y + 30
    drawString(canvas, "&epsiv; &eta; &Gamma; <gamma/>", x, y, color=green)
    y = y + 30
    drawString(canvas, "&iota; &kappa; &Lambda; <lambda/>", x, y, color=blue)
    y = y + 30
    drawString(canvas,
               "<u>&mu;</u> &nu; <b>&Omega;</b> <omega/>",
               x,
               y,
               color=green)
    print "mu should be underlined, Omega should be big and bold"
    y = y + 30
    drawString(canvas, "&omicron; &Phi; &phi; <phiv/>", x, y, color=blue)
    y = y + 30
    drawString(canvas, "&Pi; &pi; &piv; <Psi/> &psi; &rho;", x, y, color=green)
    y = y + 30
    drawString(canvas,
               "<u>&Sigma; &sigma; &sigmav; <tau/></u>",
               x,
               y,
               color=blue)
    print "line starting with sigma should be completely underlined"
    y = y + 30
    drawString(canvas,
               "&Theta; &theta; &thetav; <Xi/> &xi; &zeta;",
               x,
               y,
               color=green)
    y = y + 30
    drawString(canvas, "That's &alpha;ll <u>folks</u><super>&omega;</super>",
               x, y)

    canvas.flush()