Skip to main content

PatternFill Class

A pattern fill that uses a PatternTemplate to fill PDF content with a repeating tiling pattern.

Declaration

public class PatternFill extends Fill

Remarks

A pattern fill can use either a colored tiling pattern that defines its own colors or an uncolored tiling pattern that uses an underlying color space and color value.

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);
            }
        }
    }
}

Inherited Members

com.devexpress.system.JavaObject.clone()
com.devexpress.system.JavaObject.equals(java.lang.Object)
com.devexpress.system.JavaObject.hashCode()
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
JavaObject
Fill
PatternFill

Constructors

PatternFill(PatternTemplate patternTemplate, ColorSpace underlyingColorSpace, PdfColor underlyingPdfColor, @Nullable Double opacity) Constructor

Initializes a new instance of the PatternFill class with the specified pattern template, underlying color space, underlying color, and opacity.

Declaration

public PatternFill(PatternTemplate patternTemplate, ColorSpace underlyingColorSpace, PdfColor underlyingPdfColor, @Nullable Double opacity)

Parameters

Name Type Description
patternTemplate PatternTemplate

The pattern template that defines the fill content.

underlyingColorSpace ColorSpace

The color space used for an uncolored tiling pattern.

underlyingPdfColor PdfColor

The color applied to an uncolored tiling pattern.

opacity

The opacity.

PatternFill(PatternTemplate patternTemplate, ColorSpace underlyingColorSpace, PdfColor underlyingPdfColor) Constructor

Initializes a new instance of the PatternFill class with the specified pattern template, underlying color space, and underlying color.

Declaration

public PatternFill(PatternTemplate patternTemplate, ColorSpace underlyingColorSpace, PdfColor underlyingPdfColor)

Parameters

Name Type Description
patternTemplate PatternTemplate

The pattern template that defines the fill content.

underlyingColorSpace ColorSpace

The color space used for an uncolored tiling pattern.

underlyingPdfColor PdfColor

The color applied to an uncolored tiling pattern.

PatternFill(PatternTemplate patternTemplate, ColorSpace underlyingColorSpace) Constructor

Initializes a new instance of the PatternFill class with the specified pattern template and underlying color space.

Declaration

public PatternFill(PatternTemplate patternTemplate, ColorSpace underlyingColorSpace)

Parameters

Name Type Description
patternTemplate PatternTemplate

The pattern template that defines the fill content.

underlyingColorSpace ColorSpace

The color space used for an uncolored tiling pattern.

PatternFill(PatternTemplate patternTemplate) Constructor

Initializes a new instance of the PatternFill class with the specified pattern template.

Declaration

public PatternFill(PatternTemplate patternTemplate)

Parameters

Name Type Description
patternTemplate PatternTemplate

The pattern template that defines the fill content.

Methods

deepClone() Method

Creates a deep copy of the current object.

Declaration

public Fill deepClone()

Returns

Type Description
Fill

A deep copy of the current object.

getPatternTemplate() Method

Returns the pattern template used to define the fill content.

Declaration

public PatternTemplate getPatternTemplate()

Returns

Type Description
PatternTemplate

The pattern template.

getUnderlyingColorSpace() Method

Returns the color space used for an uncolored tiling pattern.

Declaration

public ColorSpace getUnderlyingColorSpace()

Returns

Type Description
ColorSpace

The underlying color space.

getUnderlyingPdfColor() Method

Returns the color applied to an uncolored tiling pattern.

Declaration

public PdfColor getUnderlyingPdfColor()

Returns

Type Description
PdfColor

The underlying color.