Skip to main content

PatternTemplate Class

A reusable pattern template.

Declaration

public class PatternTemplate extends JavaObject implements ICloneable

Remarks

PatternTemplate is a reusable pattern template that contains page fragments and defines how the pattern is rendered in a PDF document. A pattern template specifies the pattern bounds, transformation matrix, color behavior, and tiling steps used to repeat the pattern across a page.

Use the PatternTemplate class to create and configure tiling patterns that consist of reusable PDF content fragments.

The following code snippet creates a PatternTemplate that defines a reusable tiling pattern with custom content fragments. The example applies the pattern as a fill for a PDF shape and saves the resulting document.

 Reusable Tiling Pattern, PDF Document API for Java

package pdf;

import com.devexpress.docs.pdf.*;
import com.devexpress.system.drawing.*;
import com.devexpress.drawing.printing.*;

import java.io.*;
import java.nio.file.*;

public class Main {
    public static void main(String[] args) throws Exception {
        try (PdfDocument document = new PdfDocument()) {
            Page page = document.getPages().add(DXPaperKind.LETTER);

            // Create a pattern template.
            PatternTemplate patternTemplate = new PatternTemplate();

            // Define the pattern cell bounds.
            patternTemplate.setBoundingBox(new RectangleF(0, 0, 50, 50));

            // Define the distance between pattern cells.
            patternTemplate.setXStep(50);
            patternTemplate.setYStep(50);

            // Specify that the pattern defines its own colors.
            patternTemplate.setColored(true);

            // Create a fragment that draws a rectangle in the pattern cell.
            PathFragment patternFragment = PathFragment.rectangle(10, 10, 30, 30);
            patternFragment.setAction(PathShapeAction.FILL);

            // Set the pattern element fill color.
            patternFragment.setFill(
                    Fill.createSolid(PdfColor.getDarkOrange())
            );

            // Add the fragment to the pattern template.
            patternTemplate.getFragments().add(patternFragment);

            // Create a triangle geometry.
            GraphicsPath triangle = new GraphicsPath(new PointF(50, 500));
            triangle.appendLineSegment(new PointF(50, 300));
            triangle.appendLineSegment(new PointF(250, 300));
            triangle.setClosed(true);

            // Create a path fragment for a triangle shape.
            PathFragment triangleFragment = new PathFragment();

            // Assign geometry to the fragment.
            triangleFragment.getPaths().add(triangle);

            // Specify that the triangle displays both fill and outline.
            triangleFragment.setAction(PathShapeAction.FILL_AND_STROKE);

            // Apply the pattern template as the triangle fill.
            triangleFragment.setFill(Fill.createPattern(patternTemplate, ColorSpace.getDeviceRGB()));

            // Set the triangle outline color.
            triangleFragment.setOutline(
                    Outline.create(Fill.createSolid(PdfColor.getDarkOrange())));

            // Add the triangle to the page.
            page.addFragment(triangleFragment);

            // Save the PDF document.
            try (OutputStream stream =
                         Files.newOutputStream(
                                 Path.of("Result.pdf"))) {
                document.save(stream);
            }
        }
    }
}

Implements

com.devexpress.system.ICloneable

Inherited Members

com.devexpress.system.JavaObject.clone()
com.devexpress.system.JavaObject.equals(java.lang.Object)
com.devexpress.system.JavaObject.hashCode()
com.devexpress.system.JavaObject.initFields()
com.devexpress.system.JavaObject.memberwiseClone()
com.devexpress.system.JavaObject.toString()
java.lang.Object.finalize()
java.lang.Object.getClass()
java.lang.Object.notify()
java.lang.Object.notifyAll()
java.lang.Object.wait()
java.lang.Object.wait(long)
java.lang.Object.wait(long,int)

Inheritance

Object
com.devexpress.system.JavaObject
PatternTemplate

PatternTemplate()

Initializes a new instance of the PatternTemplate class.

Declaration

public PatternTemplate()

Methods

deepClone() Method

Creates a deep copy of the current object.

Declaration

public PatternTemplate deepClone()

Returns

Type Description
PatternTemplate

A deep copy of the current object.

getBoundingBox() Method

Returns the bounding box of the pattern template.

Declaration

public RectangleF getBoundingBox()

Returns

Type Description
RectangleF

The pattern bounding box.

getColored() Method

Returns whether the pattern defines its own colors.

Declaration

public boolean getColored()

Returns

Type Description
boolean

true if the pattern defines its own colors; otherwise, false.

getFragments() Method

Returns the collection of page fragments that define the pattern content.

Declaration

public IFragmentCollection getFragments()

Returns

Type Description
IFragmentCollection

The collection of page fragments.

getMatrix() Method

Returns the transformation matrix applied to the pattern template.

Declaration

public DXMatrix getMatrix()

Returns

Type Description
DXMatrix

The transformation matrix.

getXStep() Method

Returns the horizontal spacing between pattern cells.

Declaration

public double getXStep()

Returns

Type Description
double

The horizontal spacing between pattern cells.

getYStep() Method

Returns the vertical spacing between pattern cells.

Declaration

public double getYStep()

Returns

Type Description
double

The vertical spacing between pattern cells.

objectClone() Method

Creates a copy of the current object.

Declaration

public Object objectClone()

Returns

Type Description
Object

A copy of the current object.

setBoundingBox(RectangleF value) Method

Sets the bounding box of the pattern template.

Declaration

public void setBoundingBox(RectangleF value)

Parameters

Name Type Description
value RectangleF

The pattern bounding box.

setColored(boolean value) Method

Sets whether the pattern defines its own colors.

Declaration

public void setColored(boolean value)

Parameters

Name Type Description
value boolean

true if the pattern defines its own colors; otherwise, false.

setMatrix(DXMatrix value) Method

Sets the transformation matrix applied to the pattern template.

Declaration

public void setMatrix(DXMatrix value)

Parameters

Name Type Description
value DXMatrix

The transformation matrix.

setXStep(double value) Method

Sets the horizontal spacing between pattern cells.

Declaration

public void setXStep(double value)

Parameters

Name Type Description
value double

The horizontal spacing between pattern cells.

setYStep(double value) Method

Sets the vertical spacing between pattern cells.

Declaration

public void setYStep(double value)

Parameters

Name Type Description
value double

The vertical spacing between pattern cells.