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

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

Introduction

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

Prototype

@Override
public PDRectangle getBBox() 

Source Link

Document

An array of four numbers in the form coordinate system (see below), giving the coordinates of the left, bottom, right, and top edges, respectively, of the pattern's bounding box.

Usage

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

License:Apache License

private void applyShadingAsColor(PDShading shading) throws IOException {
    /*//from   ww  w .j  a v a  2 s.  co  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);
}