// See if we can apply the pattern color to chunk, phrase or paragraph
PatternColor pat = new PatternColor(p);
PatternColor pat1 = new PatternColor(p1);
PatternColor pat2 = new PatternColor(p2);
String text = "Text with pattern";
document.add(new Paragraph(text, FontFactory.getFont(FontFactory.HELVETICA, 60, LwgFont.BOLD, new GrayColor(0.3f))));
document.add(new Paragraph(text, FontFactory.getFont(FontFactory.HELVETICA, 60, LwgFont.BOLD, pat)));
// draw a rectangle filled with star pattern
cb.setPatternFill(p);
cb.setGrayStroke(0.0f);
cb.rectangle(20, 20, 284, 120);
cb.fillStroke();
// draw some characters filled with star.
// Note: A gray, rgb, cmyk or spot color should be applied first
// otherwise, you will not be able to see the character glyph
// since the glyph path is filled by pattern
cb.beginText();
cb.setFontAndSize(bf, 1);
cb.setTextMatrix(270f, 0f, 0f, 270f, 20f, 100f);
cb.setGrayFill(0.9f);
cb.showText("ABC");
cb.setPatternFill(p);
cb.moveTextWithLeading(0.0f, 0.0f);
cb.showText("ABC");
cb.endText();
cb.setPatternFill(p);
// draw a circle. Similar to rectangle
cb.setGrayStroke(0.0f);
cb.circle(150f, 400f, 150f);
cb.fillStroke();
// New Page to draw text in the pattern painter's canvas
document.newPage();
document.add(new Paragraph(text, FontFactory.getFont(FontFactory.HELVETICA, 60, LwgFont.BOLD, new GrayColor(0.3f))));
document.add(new Paragraph(text, FontFactory.getFont(FontFactory.HELVETICA, 60, LwgFont.BOLD, pat1)));
// draw a rectangle
cb.setPatternFill(p1);
cb.setGrayStroke(0.0f);
cb.rectangle(0, 0, 284, 120);
cb.fillStroke();
// draw some characters
cb.beginText();
cb.setFontAndSize(bf, 1);
cb.setTextMatrix(270f, 0f, 0f, 270f, 20f, 100f);
cb.setGrayFill(0.9f);
cb.showText("ABC");
cb.setPatternFill(p1);
cb.moveTextWithLeading(0.0f, 0.0f);
cb.showText("ABC");
cb.endText();
// draw a circle
cb.setPatternFill(p1);
cb.setGrayStroke(0.0f);
cb.circle(150f, 400f, 150f);
cb.fillStroke();
cb.sanityCheck();
// New page to place image in the pattern painter's canvas
document.newPage();
document.add(new Paragraph(text, FontFactory.getFont(FontFactory.HELVETICA, 60, LwgFont.BOLD, new GrayColor(0.3f))));
document.add(new Paragraph(text, FontFactory.getFont(FontFactory.HELVETICA, 60, LwgFont.BOLD, pat2)));
// The original LwgImage for comparison reason.
// Note: The width and height is the same as bbox in pattern
cb.addImage(img, img.getScaledWidth(), 0f, 0f, img.getScaledHeight(), 350f, 400f);
// draw a rectangle