itext - How to add a shading pattern to a custom shape -
itext - How to add a shading pattern to a custom shape -
i have drawn equilateral triangle follows using itext
canvas.setcolorstroke(basecolor.black); int x = start.getx(); int y = start.gety(); canvas.moveto(x,y); canvas.lineto(x + side,y); canvas.lineto(x + (side/2), (float)(y+(side*math.sin(converttoradian(60))))); canvas.closepathstroke();
i wish multi color gradient in shape i.e. fill shading comprising of basecolor.pink
, basecolor.blue
. can't find way itext ?
i've created illustration called shadedfill fills triangle drawing using shading pattern goes pinkish bluish show in shaded_fill.pdf:
pdfcontentbyte canvas = writer.getdirectcontent(); float x = 36; float y = 740; float side = 70; pdfshading axial = pdfshading.simpleaxial(writer, x, y, x + side, y, basecolor.pink, basecolor.blue); pdfshadingpattern shading = new pdfshadingpattern(axial); canvas.setshadingfill(shading); canvas.moveto(x,y); canvas.lineto(x + side, y); canvas.lineto(x + (side / 2), (float)(y + (side * math.sin(math.pi / 3)))); canvas.closepathfillstroke();
as can see, need create pdfshading
object. created axial shading varies pinkish bluish coordinate (x, y)
coordinate (x + side, y)
. axial shading, can create pdfshadingpattern
can used parameter of setshadingfill()
method set fill color canvas
.
see shadedfill total source code.
itext
Comments
Post a Comment