Пример #1
0
def createTextbox(textfile, textboxRect, page, path):

    fontSize = 12
    linecounter = 0

    # Extracts text from file and eliminates blank lines
    # Counts the number of lines in the file
    with open(textfile) as input_txt:
        lineString = ""
        lineArray = []
        for line in input_txt:
            if not line.isspace():
                lineString = lineString + line
                lineArray.append(line)
                linecounter = linecounter + 1
                lineLength = fitz.getTextlength(line, "Times-Roman", fontSize)
                while (lineLength > textboxRect.width):
                    linecounter = linecounter + 1
                    lineLength = lineLength - textboxRect.width

    # At font size 12, textbox can hold up to 10 lines of text
    # Decreases font size by increments of 4 while line capacity is exceeded
    lineCapacity = 10
    while (linecounter > lineCapacity):

        # Line capacity of textbox increases by the percent increase from each font size decrement
        # Ex: 12 --> 8 makes for a 50% increase in line capacity
        percentIncrease = calculatePercentIncrease(fontSize, fontSize - 2)
        lineCapacity = lineCapacity + (lineCapacity * percentIncrease)

        # Decrement font size by increment of 2
        fontSize = fontSize - 2
        linecounter = 0

        # Recalculate the number of lines
        # This is necessary since decreasing font size may decrease the number of lines
        # When text exceeds horizontal boundaries, a new line is started
        for line in lineArray:
            linecounter = linecounter + 1
            lineLength = fitz.getTextlength(line, "Times-Roman", fontSize)
            while (lineLength > textboxRect.width):
                linecounter = linecounter + 1
                lineLength = lineLength - textboxRect.width

    # Generate textbox with text
    textboxShape = page.new_shape()
    textboxShape.draw_rect(textboxRect)
    textboxShape.finish(color=getColor("dodgerblue4"),
                        fill_opacity=1,
                        closePath=False)
    textboxShape.commit()
    page.insertTextbox(textboxRect,
                       lineString,
                       fontsize=fontSize,
                       fontname="Times-Roman",
                       align=0)

    return
Пример #2
0
def dontenter(img, r, morph = None):
    """Draw the "Do Not Enter" traffic symbol.
    """
    red = getColor("red3")
    white = (1,1,1)
    img.drawOval(r)               # draw red circle w/ thick white border
    img.finish(fill = red, color = white, width = r.width * 0.04)
    img.drawOval(r)               # draw empty circle, thin black border
    img.finish(width = r.width * 0.001)
    deltah = r.width * 0.13
    deltav = r.height * 0.45
    rs = r + (deltah, deltav, -deltah, -deltav)
    img.drawRect(rs)              # draw white horizontal rectangle
    img.finish(color = white, fill = white, width = r.width * 0.06,
               roundCap = False, morph = morph)
    return
Пример #3
0
#==============================================================================
# Pie Chart program
#==============================================================================
doc = fitz.open()  # new empty PDF
page = doc.newPage()  # without parms, this is an ISO-A4 format page

# title line
title = "Sitzverteilung nach der Bundestagswahl 2013"
# pie chart center and point of 1st data pie
center = fitz.Point(200, 250)
point = fitz.Point(200, 150)  # this will cycle through table data
# this is the radius
radius = abs(point - center)

blue = getColor("blue")  # we need some colors
white = getColor("white")

lineheight = 20  # legend line height
ts_v = 200  # vertical start of legend block
ts_h = center.x + radius + 50  # horizontal coord of legend block

# these are the data to visualize:
# number of seats of political parties in German parliament since 2013
table = (
    (253, "black", "CDU"),  # seats, party color & party name 
    (56, "dodgerblue", "CSU"),
    (193, "red", "SPD"),
    (64, "violetred", "Die Linke"),
    (63, "green", "Die Grünen"),
    (1, "gray", "fraktionslos"),
Пример #4
0
def pencil(img, penciltip, pb_height, left, morph = None):
    """Draw a pencil image. Parameters:
    img       -  Shape object
    penciltip - fitz.Point, coordinates of the pencil tip
    pb_height - the thickness of the pencil. This controls the dimension of the
                picture: it will be contained in a rectangle of 100 x 345 pixels
                if this parameter is 100.
    left      - bool, indicates whether the pencil points left (True) or right.
    morph     - a tuple (point, matrix) to achieve image torsion.
    """
    from fitz.utils import getColor
    from functools import partial
    # define some colors
    yellow  = getColor("darkgoldenrod")
    black   = getColor("black")
    white   = getColor("white")
    red     = getColor("red")
    wood    = getColor("wheat2")
    wood2   = getColor("wheat3")
    #---------------------------------------------------------------------------
    # some adjustments depending on pencil tip is left or right:
    # for choosing between a left point (lp) or a right point (rb),
    # we specify oneof(lp, rp), delivering either lp or rp. Likewise,
    # variable 's' is used as a sign and is either +1 or -1.
    #---------------------------------------------------------------------------
    w = pb_height * 0.01                         # standard line thickness
    pb_width  = 2 * pb_height                    # pencil body width
    myfinish = partial(img.finish, width = w, morph = morph, closePath = False)
    oneof = lambda l, r: l if left else r        # choose an alternative
    s = oneof(1,-1)
    tipendtop = penciltip + fitz.Point(s, -0.5) * pb_height
    tipendbot = penciltip + fitz.Point(s, 0.5) * pb_height
    r = fitz.Rect(tipendtop,
                  tipendbot + (pb_width * s, 0)) # pencil body
    r.normalize()                                # force r to be finite
    # topline / botline indicate the pencil edges
    topline0  = fitz.Point(r.x0 + r.width*0.1,
                           r.y0 + pb_height/5.)  # upper pencil edge - left
    topline1  = fitz.Point(r.x0 + r.width*0.9,
                           topline0.y)           # upper epncil edge - right
    botline0  = fitz.Point(r.x0 + r.width*0.1,
                           r.y1 - pb_height/5.)  # lower pencil edge - left
    botline1  = fitz.Point(r.x0 + r.width*0.9,
                           botline0.y)           # lower pencil edge - right
    
    # control point 1 for pencil rubber
    hp1 = oneof(r.tr, r.tl) + (pb_height*0.6*s, 0)
    # control point 2 for pencil rubber
    hp2 = oneof(r.br, r.bl) + (pb_height*0.6*s, 0)
    # pencil body is some type of yellow
    img.drawRect(r)
    myfinish(fill = yellow, color = wood)
    img.drawPolyline((r.tl, topline0, botline0, r.bl))
    img.drawPolyline((r.tr, topline1, botline1, r.br))
    myfinish(fill = wood, color = wood)
    # draw pencil edge lines
    img.drawLine(topline0, topline1)
    img.drawLine(botline0, botline1)
    myfinish(color = wood2)

    #===========================================================================
    # black rectangle near pencil rubber
    #===========================================================================
    blackrect = fitz.Rect(oneof((r.tr - (pb_height/2., 0)), r.tl),
                          oneof(r.br, (r.bl + (pb_height/2., 0))))
    img.drawRect(blackrect)
    myfinish(fill = black)

    #===========================================================================
    # draw the pencil rubber
    #===========================================================================
    img.drawBezier(oneof(r.tr, r.tl), hp1, hp2, oneof(r.br, r.bl))
    myfinish(fill = red)

    #===========================================================================
    # draw pencil tip and curves indicating pencil sharpening traces
    #===========================================================================
    img.drawPolyline((tipendtop, penciltip, tipendbot))
    myfinish(fill = wood)                   # pencil tip
    p1 = tipendtop                          # either left or right
    p2 = oneof(topline0, topline1)
    p3 = oneof(botline0, botline1)
    p4 = tipendbot
    p0 = -fitz.Point(pb_height/5., 0)*s     # horiz. displacment of ctrl points
    cp1 = p1 + (p2-p1)*0.5 + p0             # ctrl point upper rounding
    cp2 = p2 + (p3-p2)*0.5 + p0*2.9         # ctrl point middle rounding
    cp3 = p3 + (p4-p3)*0.5 + p0             # ctrl point lower rounding
    img.drawCurve(p1, cp1, p2)
    myfinish(fill = yellow, color=yellow, closePath = True)
    img.drawCurve(p2, cp2, p3)
    myfinish(fill = yellow, color=yellow, closePath = True)
    img.drawCurve(p3, cp3, p4)
    myfinish(fill = yellow, color=yellow, closePath = True)

    #===========================================================================
    # draw the pencil tip lead
    #===========================================================================
    img.drawPolyline((penciltip + (tipendtop - penciltip)*0.4,
                      penciltip,
                      penciltip + (tipendbot - penciltip)*0.4))
    #===========================================================================
    # add a curve to indicate lead is round
    #===========================================================================
    img.drawCurve(penciltip + (tipendtop - penciltip)*0.4,
                  penciltip + (pb_height * 0.6 * s, 0),
                  penciltip + (tipendbot - penciltip)*0.4)
    myfinish(fill = black)
                    
    #===========================================================================
    # re-border pencil body to get rid of some pesky pixels
    #===========================================================================
    img.drawPolyline((p1, p2, p3, p4))
    myfinish(color = yellow)
    br_tl = oneof(blackrect.tl, blackrect.tr)
    br_bl = oneof(blackrect.bl, blackrect.br)
    img.drawPolyline((br_tl, tipendtop, penciltip, tipendbot, br_bl))
    myfinish()
    #===========================================================================
    # draw pencil label - first a rounded rectangle
    #===========================================================================
    p1 = fitz.Point(0.65, 0.15) * pb_height
    p2 = fitz.Point(0.45, 0.15) * pb_height
    lblrect = fitz.Rect(topline0 + oneof(p1, p2),
                        botline1 - oneof(p2, p1))
    img.drawRect(lblrect)
    img.drawCurve(lblrect.tr,
                   fitz.Point(lblrect.x1+pb_height/4., penciltip.y),
                   lblrect.br)
    img.drawCurve(lblrect.tl,
                   fitz.Point(lblrect.x0-pb_height/4., penciltip.y),
                   lblrect.bl)
    myfinish(fill = black)
    
    #===========================================================================
    # finally the white vertical stripes - whatever they are good for
    #===========================================================================
    p1t = blackrect.tl + (blackrect.width/3.,   pb_height/20.)
    p1b = blackrect.bl + (blackrect.width/3.,   -pb_height/20.)
    p2t = blackrect.tl + (blackrect.width*2/3., pb_height/20.)
    p2b = blackrect.bl + (blackrect.width*2/3., -pb_height/20.)
    img.drawLine(p1t, p1b)
    img.drawLine(p2t, p2b)
    img.finish(color = white, width = pb_height*0.08, roundCap = False,
               morph = morph)

    # insert text to indicate a medium lead grade
    if img.insertTextbox(lblrect, "HB", color = white,
                          fontname = "Helvetica", morph = morph,
                          fontsize = pb_height * 0.22, align = 1) < 0:
        raise ValueError("not enough space to store 'HB' text")
    return
Пример #5
0
def hand(img, rect, color = None, fill = None, morph = None):
    """Put a hand symbol inside a rectangle on a PDF page. Parameters:
    img - an object of the Shape class (contains relevant page information)
    rect - a rectangle. Its width must be at least 30% larger than its height.
    color, fill - color triples for border and filling (optional).
    morph - morphing parameters (point, matrix)
    """
    if rect.width / rect.height < 1.25:
        raise ValueError("rect width:height ratio must be at least 1.25")
    if not color:
        line = getColor("orange")
    else:
        line = color
    if not fill:
        skin = getColor("burlywood1")
    else:
        skin = fill
    #--------------------------------------------------------------------------
    # Define control points for the symbol, relative to a rect height of 3.
    # This is the actual brainware of the whole thing ...
    #--------------------------------------------------------------------------
    points = ((0.0, 1.4), (1.4, 0.2), (1.4, 1.4), (2.2, 0.0), (1.4, 1.4),
              (3.4, 1.4), (3.4, 1.8), (2.8, 1.8), (2.8, 2.2), (2.6, 2.2),
              (2.6, 2.6), (2.5, 2.6), (2.5, 3.0),
             )
    # rescale points to the argument rectangle.
    f = rect.height / 3
    tl = rect.tl                           # need this as displacement
    # function for rescaling the points in the list
    rescale = lambda x: fitz.Point(points[x])*f + tl
    p1  = rescale(0)
    p2  = rescale(1)
    p3  = rescale(2)
    p4  = rescale(3)
    p5  = rescale(4)
    p6  = rescale(5)
    p7  = rescale(6)
    p8  = rescale(7)
    p9  = rescale(8)
    p10 = rescale(9)
    p11 = rescale(10)
    p12 = rescale(11)
    p13 = rescale(12)

    # some additional helper points for Bezier curves of the finger tips.
    d1 = fitz.Point(0.4, 0) *f
    d7 = p7 - fitz.Point(1.2, 0) * f
    d9 = fitz.Point(d7.x, p9.y)
    d11 = fitz.Point(d7.x, p11.y)
    # now draw everything
    # IMPORTANT: the end point of each draw method must equal the start point
    # of the next one in order to create one connected path. Only then the
    # "finish" parameters will apply to all individual draws.
    img.drawCurve(p1, p3, p2)
    img.drawCurve(p2, p4, p5)
    img.drawLine(p5, p6)
    img.drawBezier(p6, p6 + d1, p7 + d1, p7)
    img.drawLine(p7, d7)
    img.drawLine(d7, p8)
    img.drawBezier(p8, p8 + d1, p9 + d1, p9)
    img.drawLine(p9, d9)
    img.drawLine(d9, p10)
    img.drawBezier(p10, p10 + d1, p11 + d1, p11)
    img.drawLine(p11, d11)
    img.drawLine(d11, p12)
    img.drawBezier(p12, p12 + d1, p13 + d1, p13)
    img.drawLine(p13, rect.bl)
    img.finish(color = line, fill = skin, closePath = False, morph = morph)
    return
Пример #6
0
                   rect.tr + (-dx, 2 * dy))
    img.drawOval(rl)                        # draw left eye
    img.drawOval(rr)                        # draw right eye
    img.finish(fill = color, morph = morph)
    p0 = rl.bl + (0, dy)                    # left corner of mouth
    p1 = rr.br + (0, dy)                    # right corner of mouth
    c  = rl.bl + (rr.br - rl.bl)*0.5
    img.drawCurve(p0, c, p1)                # draw mouth
    img.finish(width = 4 * w, closePath = False, morph = morph)

#------------------------------------------------------------------------------
# Main program:
# Create PDF with one symbol per page which can be used by showPDFpage
#------------------------------------------------------------------------------
if __name__ == "__main__":
    green = getColor("limegreen")
    red = getColor("red2")
    doc = fitz.open()
    p = doc.newPage()
    img = p.newShape()
    r = fitz.Rect(100, 100, 200, 200)
    heart(img, r, red)
    img.commit()
    p.setCropBox(r + (10, 10, -10, -15))

    p = doc.newPage()
    img = p.newShape()
    pnt = r.tl + (r.br - r.tl)*0.5
    clover(img, r, green, morph = (pnt, fitz.Matrix(45)))
    img.commit()
    p.setCropBox(r + (5, 5, -5, -5))
Пример #7
0
window = sg.Window('Inputs', layout)

event, value_list = window.Read()
input_path = value_list[0]
output_path = value_list[1]
line_one = value_list[2]
line_two = value_list[3]
line_three = value_list[4]
stampall = value_list[5]
maxstring = max((len(line_one)), (len(line_two)),(len(line_three) + 4))
leftwidth = maxstring*7+26

from fitz.utils import getColor

yellow  = getColor("darkgoldenrod")
black   = getColor("black")
white   = getColor("white")
red     = getColor("red")
wood    = getColor("wheat2")
wood2 = getColor("wheat3")

print("Tamponner toutes le pages:", stampall)
print("Char. max.:", maxstring)

# stamps_path = input()

#print("\n Enter the full path to the OUTPUT folder:")

#output_path = input()
Пример #8
0
        sat = delta / cmax
    S = str(int(round(sat * 100))).zfill(3)

    return H + S + V


# create color list sorted down by hue, value, saturation
mylist = sorted(getColorInfoList(), reverse=True, key=lambda x: sortkey(x))

w = 800  # page width
h = 600  # page height
rw = 80  # width of color rect
rh = 60  # height of color rect

num_colors = len(mylist)  # number of color triples
black = getColor("black")  # text color
white = getColor("white")  # text color
fsize = 8  # fontsize
lheight = fsize * 1.2  # line height
idx = 0  # index in color database
doc = fitz.open()  # empty PDF
while idx < num_colors:
    doc.insertPage(-1, width=w, height=h)  # new empty page
    page = doc[-1]  # load it
    for i in range(10):  # row index
        if idx >= num_colors:
            break
        for j in range(10):  # column index
            rect = fitz.Rect(rw * j, rh * i, rw * j + rw,
                             rh * i + rh)  # color rect
            cname = mylist[idx][0].lower()  # color name
Пример #9
0
def pencil(page, penciltip, pb_height, left):
    """Draws a pencil image. 
    """
    from fitz.utils import getColor
    # define some colors
    yellow = getColor("darkgoldenrod")
    black = getColor("black")
    white = getColor("white")
    red = getColor("red")
    wood = getColor("wheat2")
    wood2 = getColor("wheat3")
    #---------------------------------------------------------------------------
    # some adjustments follow depending on pencil tip is left or right:
    # when choices need be made between a left point (lp) or a right point (rb),
    # we specify lp*a + rp*b, delivering either lp or rp.
    # Variable 's' is used as a sign and is either +1 or -1.
    #---------------------------------------------------------------------------
    if left:  # pencil tip is left
        a = 1
        b = 0
        s = 1
    else:
        a = 0
        b = 1
        s = -1

    def oneof(x, y):
        return x * a + y * b

    w = pb_height * 0.01  # standard line thickness
    pb_width = 2 * pb_height  # pencil body width
    tipendtop = penciltip + fitz.Point(1, -0.5) * pb_height * s
    tipendbot = penciltip + fitz.Point(1, 0.5) * pb_height * s
    r = fitz.Rect(tipendtop, tipendbot + (pb_width * s, 0))  # pencil body
    r.normalize()  # force r to be finite
    # topline / botline indicate the pencil edges
    topline0 = fitz.Point(r.x0 + r.width * 0.1,
                          r.y0 + pb_height / 5.)  # upper pencil edge - left
    topline1 = fitz.Point(r.x0 + r.width * 0.9,
                          topline0.y)  # upper epncil edge - right
    botline0 = fitz.Point(r.x0 + r.width * 0.1,
                          r.y1 - pb_height / 5.)  # lower pencil edge - left
    botline1 = fitz.Point(r.x0 + r.width * 0.9,
                          botline0.y)  # lower pencil edge - right

    # control point 1 for pencil rubber
    hp1 = oneof(r.top_right, r.top_left) + (pb_height * 0.6 * s, 0)
    # control point 2 for pencil rubber
    hp2 = oneof(r.bottom_right, r.bottom_left) + (pb_height * 0.6 * s, 0)
    # pencil body is some type of yellow
    page.drawRect(r, fill=yellow, color=wood, width=w)
    page.drawPolyline((r.top_left, topline0, botline0, r.bottom_left),
                      fill=wood,
                      color=yellow,
                      width=w)
    page.drawPolyline((r.top_right, topline1, botline1, r.bottom_right),
                      fill=wood,
                      color=yellow,
                      width=w)
    # draw pencil edge lines
    page.drawLine(topline0, topline1, width=w, color=wood2)
    page.drawLine(botline0, botline1, width=w, color=wood2)

    #===========================================================================
    # draw the pencil rubber
    #===========================================================================
    page.drawBezier(oneof(r.top_right, r.top_left),
                    hp1,
                    hp2,
                    oneof(r.bottom_right, r.bottom_left),
                    fill=red,
                    width=w)
    #===========================================================================
    # black rectangle near pencil rubber
    #===========================================================================
    blackrect = fitz.Rect(
        oneof((r.top_right - (pb_height / 2., 0)), r.top_left),
        oneof(r.bottom_right, (r.bottom_left + (pb_height / 2., 0))))
    page.drawRect(blackrect, fill=black, width=w)

    #===========================================================================
    # draw pencil tip and curves indicating pencil sharpening traces
    #===========================================================================
    page.drawPolyline((tipendtop, penciltip, tipendbot), width=w,
                      fill=wood)  # pencil tip
    p1 = oneof(r.top_left, r.top_right)  # either left or right
    p2 = oneof(topline0, topline1)
    p3 = oneof(botline0, botline1)
    p4 = oneof(r.bottom_left, r.bottom_right)
    p0 = -fitz.Point(pb_height / 5.,
                     0) * s  # horiz. displacment of ctrl points
    cp1 = p1 + (p2 - p1) * 0.5 + p0  # ctrl point upper rounding
    cp2 = p2 + (p3 - p2) * 0.5 + p0 * 2.9  # ctrl point middle rounding
    cp3 = p3 + (p4 - p3) * 0.5 + p0  # ctrl point lower rounding
    page.drawCurve(p1, cp1, p2, fill=yellow, width=w, color=wood)
    page.drawCurve(p2, cp2, p3, fill=yellow, width=w, color=wood)
    page.drawCurve(p3, cp3, p4, fill=yellow, width=w, color=wood)

    #===========================================================================
    # draw the pencil tip lead mine
    #===========================================================================
    page.drawPolyline(
        (penciltip + (tipendtop - penciltip) * 0.4, penciltip, penciltip +
         (tipendbot - penciltip) * 0.4),
        fill=black,
        width=w,
        closePath=True)
    #===========================================================================
    # add a curve to indicate lead mine is round
    #===========================================================================
    page.drawCurve(penciltip + (tipendtop - penciltip) * 0.4,
                   fitz.Point(penciltip.x + pb_height * 0.6 * s, penciltip.y),
                   penciltip + (tipendbot - penciltip) * 0.4,
                   width=w,
                   fill=black)

    #===========================================================================
    # re-border pencil body getting rid of some pesky pixels
    #===========================================================================
    page.drawLine(r.top_left, r.top_right, width=w)
    page.drawLine(r.bottom_left, r.bottom_right, width=w)
    page.drawPolyline((tipendtop, penciltip, tipendbot), width=w)
    #===========================================================================
    # draw pencil label - first a rounded rectangle
    #===========================================================================
    p1 = fitz.Point(0.65, 0.15) * pb_height
    p2 = fitz.Point(0.45, 0.15) * pb_height
    lblrect = fitz.Rect(topline0 + oneof(p1, p2), botline1 - oneof(p2, p1))
    page.drawRect(lblrect, width=w, fill=black)
    page.drawCurve(lblrect.top_right,
                   fitz.Point(lblrect.x1 + pb_height / 4., penciltip.y),
                   lblrect.bottom_right,
                   width=w,
                   fill=black)
    page.drawCurve(lblrect.top_left,
                   fitz.Point(lblrect.x0 - pb_height / 4., penciltip.y),
                   lblrect.bottom_left,
                   width=w,
                   fill=black)
    # ... then text indicating it's a medium pencil
    if page.insertTextbox(lblrect,
                          "No.2",
                          color=white,
                          fontname="Helvetica",
                          fontsize=pb_height * 0.22,
                          align=1) < 0:
        raise ValueError("not enough space to store pencil text")

    #===========================================================================
    # finally the white vertical stripes - whatever they are good for
    #===========================================================================
    p1t = blackrect.top_left + fitz.Point(blackrect.width / 3.,
                                          pb_height / 20.)
    p1b = blackrect.bottom_left + fitz.Point(blackrect.width / 3.,
                                             -pb_height / 20.)
    p2t = blackrect.top_left + fitz.Point(blackrect.width * 2 / 3.,
                                          pb_height / 20.)
    p2b = blackrect.bottom_left + fitz.Point(blackrect.width * 2 / 3.,
                                             -pb_height / 20.)
    page.drawLine(p1t,
                  p1b,
                  color=white,
                  width=pb_height * 0.08,
                  roundCap=False)
    page.drawLine(p2t,
                  p2b,
                  color=white,
                  width=pb_height * 0.08,
                  roundCap=False)
    return
Пример #10
0
    calfa = math.cos(alfa)
    salfa = math.sin(alfa)
    for p in pnts:
        s = p - pb
        r = abs(s)
        if r > 0: s /= r
        np = (s.x * calfa - s.y * salfa, s.y * calfa + s.x * salfa)
        points.append(pb + fitz.Point(np)*r)
    return points

if __name__ == "__main__":
    from fitz.utils import getColor
    doc    = fitz.open()          # a new PDF
    page   = doc.newPage()        # a new page in it
    img    = page.newShape()      # start a Shape
    red    = getColor("red")      # line color for sine
    blue   = getColor("blue")     # line color for cosine
    yellow = getColor("py_color") # background color
    w = 0.3                       # line width
    #--------------------------------------------------------------------------
    # Define start / end points of x axis that we want to use as 0 and 2*pi.
    # They may be positioned in any way.
    #--------------------------------------------------------------------------
    pb = fitz.Point(200, 200)               # begin, treated as (0, 0)
    pe = fitz.Point(400, 100)               # end, treated as (2*pi, 0)
    
    # compute auxiliary end point pe1 with same y coord. as pb
    alfa = img.horizontal_angle(pb, pe)     # connection angle towards x-axis
    rad = abs(pe - pb)                      # distance of these points
    pe1 = pb + (rad, 0)                     # make corresp. horizontal end point
# =============================================================================
Пример #11
0
from os.path import isdir, isfile, join

import PySimpleGUI as sg

print = sg.EasyPrint

help_lisc_input = "Ce logiciel est soumis à la licence GPL v2, (c) Jodobear 2019.\n\nMentionner uniquement le dossier comprenant les fichiers pdf."
help_num = "Pour tampons numérotés: Le numéro de tampon correspond au trois premiers caractères du nom de fichier.\nPar exemple, un fichier nommé <<A14-Défense>> aura pour tampon <<A14>>.\nMettre éventuellement <<Pièce n°>> en 3e ligne pour obtenir <<Pièce n° A14>>.\n"
help_thanks = "Merci d'utiliser ce logiciel. Si vous avez des problèmes ou voulez contribuer à son développement, voir\nhttps://github.com/jodobear/pdf-stamper"
help_donation = "Pour faire un don au développeur du projet, voir https://tallyco.in/jodobear \n"

fonts = ["Helvetica", "Helvetica-Oblique", "Helvetica-Bold",
         "Helvetica-BoldOblique", "Courier", "Courier-Oblique",
         "Courier-Bold", "Courier-BoldOblique", "Times-Roman",
         "Times-Italic", "Times-Bold", "Times-BoldItalic"]
colors = {"Noir": getColor("black"), "Blanc": getColor("white"),
         "Rouge": getColor("red"), "Bleu": getColor("blue")}

layout = [
    [sg.T("Appuyer sur 'Aide' pour instructions.")],
    [sg.T('Dossier à tamponner:',
             size=(18, 1)), sg.In(), sg.FolderBrowse("Parcourir", size=(10, 1))],
    [sg.T("Dossier d'enregistrement:", size=(18, 1)),
     sg.InputText(), sg.FolderBrowse("Parcourir", size=(10, 1))],
    [sg.T('1e ligne du tampon:', size=(18, 2)), sg.In()],
    [sg.T('2e ligne du tampon:', size=(18, 2)), sg.In()],
    [sg.T('3e ligne du tampon:', size=(18, 2)), sg.In()],
    [sg.Frame(layout=[
        [sg.Radio('Tamponner toutes les pages', "RADIO1", default=True, size=(24, 1)),
         sg.Radio('Tamponner la page n°', "RADIO1"), sg.In(size=(3, 1))],
        [sg.Checkbox('Numéroter les tampons', size=(18, 1), default=False),
Пример #12
0
We draw each sun ray after it has been reflected by the cup.

The resulting picture is save in three image formats: PDF, PNG and SVG / SVGZ

"""
def pvon(a):
    """Starting point of a reflected sun ray, given an angle a."""
    return(math.cos(a), math.sin(a))

def pbis(a):
    """End point of a reflected sun ray, given an angle a."""
    return(math.cos(3*a - math.pi), (math.sin(3*a - math.pi)))

fileprfx = "catacaustic"                         # filename prefix
coffee = getColor("coffee")                      # color: latte macchiato?
yellow = getColor("yellow")                      # color of sun rays
blue   = getColor("blue")                        # color cup border
doc = fitz.open()                                # new empty PDF 
page = doc.newPage(-1, width = 800, height = 800)# create square sized page
center = fitz.Point(page.rect.width / 2,         # center of circle on page
                    page.rect.height / 2)

radius = page.rect.width / 2 - 20                # leave a border of 20 pixels

img = page.newShape()
img.drawCircle(center, radius)
img.finish(color = coffee, fill = coffee)        # fill coffee into the cup

count = 200                                      # how many sun rays we draw
interval = math.pi / count                       # angle fraction
Пример #13
0
print = sg.EasyPrint

help_lisc_input = "This software is liscenced under GPL v2, (c) Jodobear 2019.\n\nNOTE: Input path to the folder containing only pdf files to be stamped. Do not provide path to the file itself."
help_num = "FOR STAMPS WITH NUMBERS: Stamp numbers correspond to first three characters of the document name.\nFor example, a document named <<A14-Defence>> will be stamped with number <<A14>>.\nOptionally, input label (e.g. 'Exhibit No.') in Line 3 to get <<Exhibit No. A14>>.\n"
help_thanks = "Thank you for using this software. If you have any issues or want to contribute to the development, visit\nhttps://github.com/jodobear/pdf-stamper"
help_donation = "Please consider buying us a coffee at https://tallyco.in/jodobear \n"

fonts = [
    "Helvetica", "Helvetica-Oblique", "Helvetica-Bold",
    "Helvetica-BoldOblique", "Courier", "Courier-Oblique", "Courier-Bold",
    "Courier-BoldOblique", "Times-Roman", "Times-Italic", "Times-Bold",
    "Times-BoldItalic"
]
colors = {
    "Black": getColor("black"),
    "White": getColor("white"),
    "Red": getColor("red"),
    "Blue": getColor("blue")
}

layout = [[sg.T("Please click 'Help' for instructions.")],
          [
              sg.T('Folder to be stamped:', size=(18, 1)),
              sg.In(),
              sg.FolderBrowse(size=(10, 1))
          ],
          [
              sg.T('Output folder:', size=(18, 1)),
              sg.InputText(),
              sg.FolderBrowse(size=(10, 1))
Пример #14
0
"""
print(fitz.__doc__)


def pvon(a):
    """Starting point of a reflected sun ray, given an angle a."""
    return (math.cos(a), math.sin(a))


def pbis(a):
    """End point of a reflected sun ray, given an angle a."""
    return (math.cos(3 * a - math.pi), (math.sin(3 * a - math.pi)))


fileprfx = "catacaustic"  # filename prefix
coffee = getColor("coffee")  # color: latte macchiato?
yellow = getColor("yellow")  # color of sun rays
blue = getColor("blue")  # color cup border
doc = fitz.open()  # new empty PDF
page = doc.newPage(-1, width=800, height=800)  # create square sized page
center = fitz.Point(
    page.rect.width / 2,
    page.rect.height / 2  # center of circle on page
)

radius = page.rect.width / 2 - 20  # leave a border of 20 pixels

img = page.newShape()
img.drawCircle(center, radius)
img.finish(color=coffee, fill=coffee)  # fill coffee into the cup
Пример #15
0
    else:
        sat = delta / cmax
    S = str(int(round(sat  * 100))).zfill(3)

    return H + S + V

# create color list sorted down by hue, value, saturation
mylist = sorted(getColorInfoList(), reverse = True, key=lambda x: sortkey(x))

w = 800            # page width
h = 600            # page height
rw = 80            # width of color rect
rh = 60            # height of color rect

num_colors = len(mylist)     # number of color triples
black = getColor("black")    # text color
white = getColor("white")    # text color
fsize = 8                    # fontsize
lheight = fsize *1.2         # line height
idx = 0                      # index in color database
doc = fitz.open()            # empty PDF
while idx < num_colors:
    doc.insertPage(-1, width = w, height = h)    # new empty page
    page=doc[-1]                                 # load it
    for i in range(10):                          # row index
        if idx >= num_colors:
            break
        for j in range(10):                      # column index
            rect = fitz.Rect(rw*j, rh*i, rw*j + rw, rh*i + rh)  # color rect
            cname = mylist[idx][0].lower()       # color name
            col = mylist[idx][1:]                # color tuple -> to floats
Пример #16
0
Demo for creating the "SPUMONI" drawing contained in ReportLab's Users Guide
on pp. 25 - 26

Dependencies:
PyMuPDF

License:
 GNU GPL 3+

The only purpose of this ugly picture is to show that creating it with PyMuPDF
definitely is at least as easy and straightforward ...

"""

green, pink, brown = getColor("green"), getColor("pink"), getColor("brown")
clist = (pink, green, brown)       # make a list of these colors
top  = 72                          # some convenience constants
left = right = top / 2
nrects = 14
fname = "Helvetica-Bold"           # fontname
doc = fitz.open()                  # empty new document
cw = doc._getCharWidths(fname)     # get glyph widths of the font
text = "SPUMONI"                   # the ominous text
textl = sum([cw[ord(c)] for c in text])     # get total glyph width of text
width, height = fitz.PaperSize("letter")
page = doc.newPage(-1, width = width, height = height)     # insert new page
rwidth = (width - 2*left) / nrects # rect width, leaves borders of 36 px
fsize = (width - 2*left) / textl   # optimum fontsize
rheight = 400                      # rect height
for i in range(nrects-2):          # draw colored rectangles (last 2 stay white)
Пример #17
0
# Pie Chart program - semi circle version
#==============================================================================
from fitz.utils import getColor        # for getting RGB colors by name
doc = fitz.open()                      # new empty PDF
doc.insertPage()                       # creates an ISO-A4 page
page = doc[-1]                         # this is the page
img = page.newShape()
# title of the page
title = "Sitzverteilung nach der Bundestagswahl 2013"
# pie chart center and point of 1st data pie
center = fitz.Point(200, 250)
point  = fitz.Point(100, 250)          # will cycle through table data
# this is the radius
radius = abs(point - center)

blue = getColor("blue")                # we need some colors
white = getColor("white")

lineheight = 20                        # legend line height
ts_v  = 150                            # vertical start of legend block
ts_h  = center.x + radius + 50         # horizontal coord of legend block

# these are the data to visualize:
# number of seats of political parties in German parliament since 2013
table  = (       # seats, party color & name 
          (64, "violetred", "Die Linke"),
          (193, "red", "SPD"),
          (63, "green", "Die Grünen"),
          (253, "black", "CDU"),
          (56, "dodgerblue", "CSU"),
          (1, "gray", "fraktionslos"),
Пример #18
0
    salfa = math.sin(alfa)
    for p in pnts:
        s = p - pb
        r = abs(s)
        if r > 0: s /= r
        np = (s.x * calfa - s.y * salfa, s.y * calfa + s.x * salfa)
        points.append(pb + fitz.Point(np) * r)
    return points


if __name__ == "__main__":
    from fitz.utils import getColor
    doc = fitz.open()  # a new PDF
    page = doc.newPage()  # a new page in it
    img = page.newShape()  # start a Shape
    red = getColor("red")  # line color for sine
    blue = getColor("blue")  # line color for cosine
    yellow = getColor("py_color")  # background color
    w = 0.3  # line width
    #--------------------------------------------------------------------------
    # Define start / end points of x axis that we want to use as 0 and 2*pi.
    # They may be oriented in any way.
    #--------------------------------------------------------------------------
    pb = fitz.Point(200, 200)  # begin, treated as (0, 0)
    pe = fitz.Point(400, 100)  # end, treated as (2*pi, 0)

    alfa = img.horizontal_angle(pb, pe)  # connection angle towards x-axis
    rad = abs(pe - pb)  # distance of these points
    pe1 = pb + (rad, 0)  # make corresp. horizontal end point
    # =============================================================================
    #   first draw a rectangle in which the functions graphs will later appear
Пример #19
0
Demo for creating the "SPUMONI" drawing contained in ReportLab's Users Guide
on pp. 25 - 26

Dependencies:
PyMuPDF

License:
 GNU GPL 3+

The only purpose of this ugly picture is to show, that creating it with PyMuPDF
is definitely at least as easy and straightforward ...

"""

green, pink, brown = getColor("green"), getColor("pink"), getColor("brown")
clist = (pink, green, brown)       # make a list of these colors
top  = 72                          # some convenience constants
left = right = top / 2
nrects = 14
fname = "Helvetica-Bold"           # fontname
doc = fitz.open()                  # empty new document
cw = doc._getCharWidths(fname)     # get glyph widths of the font
text = "SPUMONI"                   # the ominous text
textl = sum([cw[ord(c)] for c in text])     # get total glyph width of text
width, height = fitz.PaperSize("letter")
page = doc.newPage(-1, width = width, height = height)     # insert new page
rwidth = (width - 2*left) / nrects # rect width, leaves borders of 36 px
fsize = (width - 2*left) / textl   # optimum fontsize
rheight = 400                      # rect height
for i in range(nrects-2):          # draw colored rectangles (last 2 stay white)