2 from pdflib_py import *
3 from math import sin,cos
7 img = Image.new("L", (3, 3))
8 draw = ImageDraw.Draw(img)
9 draw.point((0,1), fill=255)
10 draw.point((0,2), fill=255)
11 draw.point((1,0), fill=255)
12 draw.point((1,2), fill=255)
13 draw.point((2,0), fill=255)
14 draw.point((2,1), fill=255)
15 img.save("/tmp/mask1.png")
17 img = Image.new("L", (16, 1))
18 draw = ImageDraw.Draw(img)
20 draw.point((i,0), fill=i*16)
21 img.save("/tmp/mask2.png")
23 img = Image.new("RGB", (3, 3))
24 draw = ImageDraw.Draw(img)
25 draw.point((0,1), fill=(0,0,0))
26 draw.point((0,2), fill=(255,0,0))
27 draw.point((1,0), fill=(0,255,0))
28 draw.point((1,2), fill=(0,0,255))
29 draw.point((2,0), fill=(255,255,0))
30 draw.point((2,1), fill=(0,255,255))
31 img.save("/tmp/img1.png")
33 img = Image.new("RGB", (16, 1))
34 draw = ImageDraw.Draw(img)
36 draw.point((i,0), fill=(0,255,0))
37 img.save("/tmp/img2.png")
40 PDF_open_file(p, "transparency.pdf")
41 font = PDF_load_font(p, "Helvetica", "host", "")
43 PDF_set_parameter(p, "usercoordinates", "true")
47 PDF_begin_page(p, width, height)
49 PDF_setcolor(p, "fill", "rgb", 0.0,0.0,0.0,1.0)
51 PDF_lineto(p, width, 0)
52 PDF_lineto(p, width, height)
53 PDF_lineto(p, 0, height)
57 PDF_setfont(p, font, 10.0)
58 PDF_setcolor(p, "fill", "rgb", 1.0,1.0,1.0,1.0)
59 PDF_set_text_pos(p, 50, 205);PDF_show(p, "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")
60 PDF_set_text_pos(p, 50, 105);PDF_show(p, "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")
62 mask = PDF_load_image(p, "png", "/tmp/mask1.png", "mask")
63 i = PDF_load_image(p, "png", "/tmp/img1.png", "masked "+str(mask))
64 PDF_place_image(p, i, 100, 300, 20)
66 mask2 = PDF_load_image(p, "png", "/tmp/mask2.png", "mask")
67 i2 = PDF_load_image(p, "png", "/tmp/img2.png", "masked "+str(mask2))
68 PDF_place_image(p, i2, 0, 200, 25)
70 PDF_setcolor(p, "fill", "rgb", 1.0,1.0,1.0,1.0)
71 gstate = PDF_create_gstate(p, "opacityfill 0.25") # blendmode multiply opacityfill 0.5")
72 PDF_set_gstate(p, gstate)
74 PDF_lineto(p, 50+300, 75)
75 PDF_lineto(p, 50+300, 150)
76 PDF_lineto(p, 50, 150)