Example usage for org.apache.pdfbox.pdmodel.graphics.pattern PDTilingPattern setTilingType

List of usage examples for org.apache.pdfbox.pdmodel.graphics.pattern PDTilingPattern setTilingType

Introduction

In this page you can find the example usage for org.apache.pdfbox.pdmodel.graphics.pattern PDTilingPattern setTilingType.

Prototype

public void setTilingType(int tilingType) 

Source Link

Document

This will set the tiling type.

Usage

From source file:de.rototor.pdfbox.graphics2d.PdfBoxGraphics2D.java

License:Apache License

private void applyShadingAsColor(PDShading shading) throws IOException {
    /*//from  w ww. j  a  v a 2  s .  c o m
     * If the paint has a shading we must create a tiling pattern and set that as
     * stroke color...
     */
    PDTilingPattern pattern = new PDTilingPattern();
    pattern.setPaintType(PDTilingPattern.PAINT_COLORED);
    pattern.setTilingType(PDTilingPattern.TILING_CONSTANT_SPACING_FASTER_TILING);
    PDRectangle anchorRect = bbox;
    pattern.setBBox(anchorRect);
    pattern.setXStep(anchorRect.getWidth());
    pattern.setYStep(anchorRect.getHeight());

    PDAppearanceStream appearance = new PDAppearanceStream(this.document);
    appearance.setResources(pattern.getResources());
    appearance.setBBox(pattern.getBBox());

    PDPageContentStream imageContentStream = new PDPageContentStream(document, appearance,
            ((COSStream) pattern.getCOSObject()).createOutputStream());
    imageContentStream.addRect(0, 0, anchorRect.getWidth(), anchorRect.getHeight());
    imageContentStream.clip();
    imageContentStream.shadingFill(shading);
    imageContentStream.close();

    PDColorSpace patternCS1 = new PDPattern(null);
    COSName tilingPatternName = xFormObject.getResources().add(pattern);
    PDColor patternColor = new PDColor(tilingPatternName, patternCS1);

    contentStream.setNonStrokingColor(patternColor);
    contentStream.setStrokingColor(patternColor);
}