> For the complete documentation index, see [llms.txt](https://docs.apryse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apryse.com/core/get-started/samples/patterntest.md).

# PDF Patterns & Shading - Pattern

Sample code for using Apryse Server SDK to create various patterns and shadings in PDF files, provided in Python, C++, C#, Java, Node.js (JavaScript), PHP, Ruby and VB.

Sample code for using Apryse Server SDK to create various patterns and shadings in PDF files. Learn more about our [Server SDK](/core/get-started/get-started.md) and [PDF Editing & Manipulation Library](/core/page-manipulation/manipulation.md).

{% tabs %}
{% tab title="C#" %}
{% code lineNumbers="true" %}

```csharp
//
// Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
//

using System;
using pdftron;
using pdftron.Common;
using pdftron.Filters;
using pdftron.SDF;
using pdftron.PDF;

namespace PatternTestCS
{
	/// <summary>
	/// This example illustrates how to create PDF patterns and shadings.
	/// </summary>
	class PatternTest
	{
		private static pdftron.PDFNetLoader pdfNetLoader = pdftron.PDFNetLoader.Instance();
		static PatternTest() {}
		
		// Relative path to the folder containing test files.
		const string input_path =  "../../../../TestFiles/";
		const string output_path = "../../../../TestFiles/Output/";

		static void Main(string[] args)
		{
			PDFNet.Initialize(PDFTronLicense.Key);
			try	
			{
				using (PDFDoc doc = new PDFDoc())
				using (ElementWriter writer = new ElementWriter())
				using (ElementBuilder eb = new ElementBuilder())
				{
					// The following sample illustrates how to create and use tiling patterns
					Page page = doc.PageCreate();
					writer.Begin(page);

					Element element = eb.CreateTextBegin(Font.Create(doc, Font.StandardType1Font.e_times_bold), 1);
					writer.WriteElement(element);  // Begin the text block

					element = eb.CreateTextRun("G");
					element.SetTextMatrix(720, 0, 0, 720, 20, 240);
					GState gs = element.GetGState();
					gs.SetTextRenderMode(GState.TextRenderingMode.e_fill_stroke_text);
					gs.SetLineWidth(4);

					// Set the fill color space to the Pattern color space. 
					gs.SetFillColorSpace(ColorSpace.CreatePattern());
					gs.SetFillColor(CreateTilingPattern(doc));

					writer.WriteElement(element);
					writer.WriteElement(eb.CreateTextEnd()); // Finish the text block

					writer.End();	// Save the page
					doc.PagePushBack(page);
					//-----------------------------------------------

					/// The following sample illustrates how to create and use image tiling pattern
					page = doc.PageCreate();
					writer.Begin(page);
			
					eb.Reset();
					element = eb.CreateRect(0, 0, 612, 794);

					// Set the fill color space to the Pattern color space. 
					gs = element.GetGState();
					gs.SetFillColorSpace(ColorSpace.CreatePattern());
					gs.SetFillColor(CreateImageTilingPattern(doc));
					element.SetPathFill(true);		

					writer.WriteElement(element);

					writer.End();	// Save the page
					doc.PagePushBack(page);
					//-----------------------------------------------

					/// The following sample illustrates how to create and use PDF shadings
					page = doc.PageCreate();
					writer.Begin(page);

					eb.Reset();
					element = eb.CreateRect(0, 0, 612, 794);

					// Set the fill color space to the Pattern color space. 
					gs = element.GetGState();
					gs.SetFillColorSpace(ColorSpace.CreatePattern());
					gs.SetFillColor(CreateAxialShading(doc));
					element.SetPathFill(true);		

					writer.WriteElement(element);

					writer.End();	// save the page
					doc.PagePushBack(page);
					//-----------------------------------------------

					doc.Save(output_path + "patterns.pdf", SDFDoc.SaveOptions.e_remove_unused);
					Console.WriteLine("Done. Result saved in patterns.pdf...");
				}
			}
			catch (PDFNetException e)
			{
				Console.WriteLine(e.Message);
			}
			PDFNet.Terminate();
		}

		static PatternColor CreateTilingPattern(PDFDoc doc) 
		{
			using (ElementWriter writer = new ElementWriter())
			using (ElementBuilder eb = new ElementBuilder())
			{
				// Create a new pattern content stream - a heart. ------------
				writer.Begin(doc);
				eb.PathBegin();
				eb.MoveTo(0, 0);
				eb.CurveTo(500, 500, 125, 625, 0, 500);
				eb.CurveTo(-125, 625, -500, 500, 0, 0);
				Element heart = eb.PathEnd();
				heart.SetPathFill(true); 
	
				// Set heart color to red.
				heart.GetGState().SetFillColorSpace(ColorSpace.CreateDeviceRGB()); 
				heart.GetGState().SetFillColor(new ColorPt(1, 0, 0)); 
				writer.WriteElement(heart);

				Obj pattern_dict = writer.End();

				// Initialize pattern dictionary. For details on what each parameter represents please 
				// refer to Table 4.22 (Section '4.6.2 Tiling Patterns') in PDF Reference Manual.
				pattern_dict.PutName("Type", "Pattern");
				pattern_dict.PutNumber("PatternType", 1);

				// TilingType - Constant spacing.
				pattern_dict.PutNumber("TilingType", 1); 

				// This is a Type1 pattern - A colored tiling pattern.
				pattern_dict.PutNumber("PaintType", 1);

				// Set bounding box
				pattern_dict.PutRect("BBox", -253, 0, 253, 545);

				// Set the pattern matrix
				pattern_dict.PutMatrix("Matrix", new Matrix2D(0.04, 0, 0, 0.04, 0, 0));

				// Set the desired horizontal and vertical spacing between pattern cells, 
				// measured in the pattern coordinate system.
				pattern_dict.PutNumber("XStep", 1000);
				pattern_dict.PutNumber("YStep", 1000);
	
				return new PatternColor(pattern_dict); // finished creating the Pattern resource
			}
		}

		static PatternColor CreateImageTilingPattern(PDFDoc doc) 
		{
			using (ElementWriter writer = new ElementWriter())
			using (ElementBuilder eb = new ElementBuilder())
			{

				// Create a new pattern content stream - a single bitmap object ----------
				writer.Begin(doc);
				Image  img = Image.Create(doc, input_path + "butterfly.png");
				Element img_element = eb.CreateImage(img, 0, 0, img.GetImageWidth(), img.GetImageHeight());
				writer.WritePlacedElement(img_element);
				Obj pattern_dict = writer.End();

				// Initialize pattern dictionary. For details on what each parameter represents please 
				// refer to Table 4.22 (Section '4.6.2 Tiling Patterns') in PDF Reference Manual.
				pattern_dict.PutName("Type", "Pattern");
				pattern_dict.PutNumber("PatternType", 1);

				// TilingType - Constant spacing.
				pattern_dict.PutNumber("TilingType", 1); 

				// This is a Type1 pattern - A colored tiling pattern.
				pattern_dict.PutNumber("PaintType", 1);

				// Set bounding box
				pattern_dict.PutRect("BBox", -253, 0, 253, 545);

				// Set the pattern matrix
				pattern_dict.PutMatrix("Matrix", new Matrix2D(0.3, 0, 0, 0.3, 0, 0));

				// Set the desired horizontal and vertical spacing between pattern cells, 
				// measured in the pattern coordinate system.
				pattern_dict.PutNumber("XStep", 300);
				pattern_dict.PutNumber("YStep", 300);
			
				return new PatternColor(pattern_dict); // finished creating the Pattern resource
			}
		}

		static PatternColor CreateAxialShading(PDFDoc doc) 
		{
			// Create a new Shading object ------------
			Obj pattern_dict = doc.CreateIndirectDict();

			// Initialize pattern dictionary. For details on what each parameter represents 
			// please refer to Tables 4.30 and 4.26 in PDF Reference Manual
			pattern_dict.PutName("Type", "Pattern");
			pattern_dict.PutNumber("PatternType", 2); // 2 stands for shading
					
			Obj shadingDict = pattern_dict.PutDict("Shading");
			shadingDict.PutNumber("ShadingType", 2);
			shadingDict.PutName("ColorSpace", "DeviceCMYK");
					
			// Set the coordinates of the axial shading to the output
			shadingDict.PutRect("Coords", 0, 0, 612, 794);

			// Set the Functions for the axial shading
			Obj funct = shadingDict.PutDict("Function");
			Obj C0 = funct.PutArray("C0");
			C0.PushBackNumber(1);
			C0.PushBackNumber(0);
			C0.PushBackNumber(0);
			C0.PushBackNumber(0);

			Obj C1 = funct.PutArray("C1");
			C1.PushBackNumber(0);
			C1.PushBackNumber(1);
			C1.PushBackNumber(0);
			C1.PushBackNumber(0);
					
			Obj domain = funct.PutArray("Domain");
			domain.PushBackNumber(0);
			domain.PushBackNumber(1);
			
			funct.PutNumber("FunctionType", 2);
			funct.PutNumber("N", 1);

			return new PatternColor(pattern_dict);
		}
	}
}
```

{% endcode %}
{% endtab %}

{% tab title="Go" %}
{% code lineNumbers="true" %}

```go
//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2021 by PDFTron Systems Inc. All Rights Reserved.
// Consult LICENSE.txt regarding license information.
//---------------------------------------------------------------------------------------

package main
import (
	"fmt"
	. "pdftron"
)

import  "pdftron/Samples/LicenseKey/GO"

// Relative path to the folder containing the test files.
var inputPath = "../../TestFiles/"
var outputPath = "../../TestFiles/Output/"

func CreateTilingPattern(doc PDFDoc) Obj{
    writer := NewElementWriter()
    eb := NewElementBuilder()
    
    // Create a new pattern content stream - a heart. ------------
    writer.Begin(doc.GetSDFDoc())
    eb.PathBegin()
    eb.MoveTo(0.0, 0.0)
    eb.CurveTo(500.0, 500.0, 125.0, 625.0, 0.0, 500.0)
    eb.CurveTo(-125.0, 625.0, -500.0, 500.0, 0.0, 0.0)
    heart := eb.PathEnd()
    heart.SetPathFill(true)
    
    // Set heart color to red.
    heart.GetGState().SetFillColorSpace(ColorSpaceCreateDeviceRGB()) 
    heart.GetGState().SetFillColor(NewColorPt(1.0, 0.0, 0.0)) 
    writer.WriteElement(heart)
    
    patternDict := writer.End()
    
    // Initialize pattern dictionary. For details on what each parameter represents please 
    // refer to Table 4.22 (Section '4.6.2 Tiling Patterns') in PDF Reference Manual.
    patternDict.PutName("Type", "Pattern")
    patternDict.PutNumber("PatternType", 1)
    
    // TilingType - Constant spacing.
    patternDict.PutNumber("TilingType",1) 

    // This is a Type1 pattern - A colored tiling pattern.
    patternDict.PutNumber("PaintType", 1)

    // Set bounding box
    patternDict.PutRect("BBox", -253.0, 0.0, 253.0, 545.0)

    // Create and set the matrix
    patternMtx := NewMatrix2D(0.04,0.0,0.0,0.04,0.0,0.0)
    patternDict.PutMatrix("Matrix", patternMtx)
    
    // Set the desired horizontal and vertical spacing between pattern cells, 
    // measured in the pattern coordinate system.
    patternDict.PutNumber("XStep", 1000)
    patternDict.PutNumber("YStep", 1000)
    
    return patternDict // finished creating the Pattern resource
}
    
    
    
func CreateImageTilingPattern(doc PDFDoc) Obj{
    writer := NewElementWriter()
    eb := NewElementBuilder()
    
    // Create a new pattern content stream - a single bitmap object ----------
    writer.Begin(doc.GetSDFDoc())
    image := ImageCreate(doc.GetSDFDoc(), inputPath + "dice.jpg")
    imgElement := eb.CreateImage(image, 0.0, 0.0, float64(image.GetImageWidth()), float64(image.GetImageHeight()))
    writer.WritePlacedElement(imgElement)
    patternDict := writer.End()
    
    // Initialize pattern dictionary. For details on what each parameter represents please 
    // refer to Table 4.22 (Section '4.6.2 Tiling Patterns') in PDF Reference Manual.
    patternDict.PutName("Type", "Pattern")
    patternDict.PutNumber("PatternType",1)
    
    // TilingType - Constant spacing.
    patternDict.PutNumber("TilingType", 1)
    
    // This is a Type1 pattern - A colored tiling pattern.
    patternDict.PutNumber("PaintType", 1)
    
    // Set bounding box
    patternDict.PutRect("BBox", -253.0, 0.0, 253.0, 545.0)
    
    // Create and set the matrix
    patternMtx := NewMatrix2D(0.3,0.0,0.0,0.3,0.0,0.0)
    patternDict.PutMatrix("Matrix", patternMtx)
    
    // Set the desired horizontal and vertical spacing between pattern cells, 
    // measured in the pattern coordinate system.
    patternDict.PutNumber("XStep", 300)
    patternDict.PutNumber("YStep", 300)
    
    return patternDict     // finished creating the Pattern resource
}    
    
func CreateAxialShading(doc PDFDoc) Obj{
    // Create a new Shading object ------------
    patternDict := doc.CreateIndirectDict()
    
    // Initialize pattern dictionary. For details on what each parameter represents 
    // please refer to Tables 4.30 and 4.26 in PDF Reference Manual
    patternDict.PutName("Type", "Pattern")
    patternDict.PutNumber("PatternType", 2)    // 2 stands for shading
    
    shadingDict := patternDict.PutDict("Shading")
    shadingDict.PutNumber("ShadingType",2)
    shadingDict.PutName("ColorSpace","DeviceCMYK")
    
    // pass the coordinates of the axial shading to the output
    shadingCoords := shadingDict.PutArray("Coords")
    shadingCoords.PushBackNumber(0)
    shadingCoords.PushBackNumber(0)
    shadingCoords.PushBackNumber(612)
    shadingCoords.PushBackNumber(794)
    
    // pass the function to the axial shading
    function := shadingDict.PutDict("Function")
    C0 := function.PutArray("C0")
    C0.PushBackNumber(1)
    C0.PushBackNumber(0)
    C0.PushBackNumber(0)
    C0.PushBackNumber(0)
    
    C1 := function.PutArray("C1")
    C1.PushBackNumber(0)
    C1.PushBackNumber(1)
    C1.PushBackNumber(0)
    C1.PushBackNumber(0)
    
    domain := function.PutArray("Domain")
    domain.PushBackNumber(0)
    domain.PushBackNumber(1)
    
    function.PutNumber("FunctionType", 2)
    function.PutNumber("N", 1)
    
    return patternDict
}    

func main(){
    PDFNetInitialize(PDFTronLicense.Key)
      
    doc := NewPDFDoc()
    writer := NewElementWriter()
    eb := NewElementBuilder()
    
    // The following sample illustrates how to create and use tiling patterns
    page := doc.PageCreate()
    writer.Begin(page)
    
    element := eb.CreateTextBegin(FontCreate(doc.GetSDFDoc(), FontE_times_bold), 1.0)
    writer.WriteElement(element) // Begin the text block
    
    data := "G"
    element = eb.CreateTextRun(data)
    element.SetTextMatrix(720.0, 0.0, 0.0, 720.0, 20.0, 240.0)
    gs := element.GetGState()
    gs.SetTextRenderMode(GStateE_fill_stroke_text)
    gs.SetLineWidth(4)
    
    // Set the fill color space to the Pattern color space. 
    gs.SetFillColorSpace(ColorSpaceCreatePattern())
    gs.SetFillColor(NewPatternColor(CreateTilingPattern(doc)))
    
    element.SetPathFill(true)
   
    writer.WriteElement(element)
    writer.WriteElement(eb.CreateTextEnd()) // Finish the text block
    
    writer.End() // Save the page
    doc.PagePushBack(page)
    
    //-----------------------------------------------
    // The following sample illustrates how to create and use image tiling pattern
    
    page = doc.PageCreate()
    writer.Begin(page)
    
    eb.Reset()
    element = eb.CreateRect(0.0, 0.0, 612.0, 794.0)
    
    // Set the fill color space to the Pattern color space. 
    gs = element.GetGState()
    gs.SetFillColorSpace(ColorSpaceCreatePattern())
    gs.SetFillColor(NewPatternColor(CreateImageTilingPattern(doc)))
    element.SetPathFill(true)
    
    writer.WriteElement(element)
    
    writer.End()    // Save the page
    doc.PagePushBack(page)
    
    //-----------------------------------------------
    
    // The following sample illustrates how to create and use PDF shadings
    page = doc.PageCreate()
    writer.Begin(page)
    
    eb.Reset()
    element = eb.CreateRect(0.0, 0.0, 612.0, 794.0)
    
    // Set the fill color space to the Pattern color space. 
    gs = element.GetGState()
    gs.SetFillColorSpace(ColorSpaceCreatePattern())
    gs.SetFillColor(NewPatternColor(CreateAxialShading(doc)))
    element.SetPathFill(true)
    
    writer.WriteElement(element)
    writer.End()    // save the page
    doc.PagePushBack(page)
    //-----------------------------------------------
    
    doc.Save(outputPath + "patterns.pdf", uint(SDFDocE_remove_unused))
    fmt.Println("Done. Result saved in patterns.pdf...")
    
    doc.Close()
    PDFNetTerminate()
}
```

{% endcode %}
{% endtab %}

{% tab title="C++" %}
{% code lineNumbers="true" %}

```cpp
//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
// Consult legal.txt regarding legal and license information.
//---------------------------------------------------------------------------------------

#include <PDF/PDFNet.h>
#include <PDF/PDFDoc.h>
#include <PDF/Image.h>
#include <PDF/ElementBuilder.h>
#include <PDF/ElementWriter.h>
#include <PDF/ElementReader.h>

#include <iostream>
#include "../../LicenseKey/CPP/LicenseKey.h"

using namespace std;
using namespace pdftron;
using namespace SDF;
using namespace PDF;

const string input_path =  "../../TestFiles/";

Obj CreateTilingPattern(PDFDoc& doc) 
{
	ElementWriter writer;	
	ElementBuilder eb;

	// Create a new pattern content stream - a heart. ------------
	writer.Begin(doc);
	eb.PathBegin();
	eb.MoveTo(0, 0);
	eb.CurveTo(500, 500, 125, 625, 0, 500);
	eb.CurveTo(-125, 625, -500, 500, 0, 0);
	Element heart = eb.PathEnd();
	heart.SetPathFill(true); 
	
	// Set heart color to red.
	heart.GetGState().SetFillColorSpace(ColorSpace::CreateDeviceRGB()); 
	heart.GetGState().SetFillColor(ColorPt(1, 0, 0)); 
	writer.WriteElement(heart);

	Obj pattern_dict = writer.End();

	// Initialize pattern dictionary. For details on what each parameter represents please 
	// refer to Table 4.22 (Section '4.6.2 Tiling Patterns') in PDF Reference Manual.
	pattern_dict.PutName("Type", "Pattern");
	pattern_dict.PutNumber("PatternType", 1);

	// TilingType - Constant spacing.
	pattern_dict.PutNumber("TilingType",1); 

	// This is a Type1 pattern - A colored tiling pattern.
	pattern_dict.PutNumber("PaintType", 1);

	// Set bounding box
	pattern_dict.PutRect("BBox", -253, 0, 253, 545);

	// Create and set the matrix
	Common::Matrix2D pattern_mtx(0.04,0,0,0.04,0,0);
	pattern_dict.PutMatrix("Matrix", pattern_mtx);

	// Set the desired horizontal and vertical spacing between pattern cells, 
	// measured in the pattern coordinate system.
	pattern_dict.PutNumber("XStep", 1000);
	pattern_dict.PutNumber("YStep", 1000);
	
	return pattern_dict; // finished creating the Pattern resource
}

Obj CreateImageTilingPattern(PDFDoc& doc) 
{
	ElementWriter writer;	
	ElementBuilder eb;

	// Create a new pattern content stream - a single bitmap object ----------
	writer.Begin(doc);
	Image image = Image::Create(doc, (input_path + "dice.jpg").c_str());
	Element img_element = eb.CreateImage(image, 0, 0, image.GetImageWidth(), image.GetImageHeight());
	writer.WritePlacedElement(img_element);
	Obj pattern_dict = writer.End();

	// Initialize pattern dictionary. For details on what each parameter represents please 
	// refer to Table 4.22 (Section '4.6.2 Tiling Patterns') in PDF Reference Manual.
	pattern_dict.PutName("Type", "Pattern");
	pattern_dict.PutNumber("PatternType",1);

	// TilingType - Constant spacing.
	pattern_dict.PutNumber("TilingType", 1); 

	// This is a Type1 pattern - A colored tiling pattern.
	pattern_dict.PutNumber("PaintType", 1);

	// Set bounding box
	pattern_dict.PutRect("BBox", -253, 0, 253, 545);

	// Create and set the matrix
	Common::Matrix2D pattern_mtx(0.3,0,0,0.3,0,0);
	pattern_dict.PutMatrix("Matrix", pattern_mtx);

	// Set the desired horizontal and vertical spacing between pattern cells, 
	// measured in the pattern coordinate system.
	pattern_dict.PutNumber("XStep", 300);
	pattern_dict.PutNumber("YStep", 300);
	
	return pattern_dict; // finished creating the Pattern resource
}

Obj CreateAxialShading(PDFDoc& doc) 
{
	// Create a new Shading object ------------
	Obj pattern_dict = doc.CreateIndirectDict();

	// Initialize pattern dictionary. For details on what each parameter represents 
	// please refer to Tables 4.30 and 4.26 in PDF Reference Manual
	pattern_dict.PutName("Type", "Pattern");
	pattern_dict.PutNumber("PatternType", 2); // 2 stands for shading
	
	Obj shadingDict = pattern_dict.PutDict("Shading");
	shadingDict.PutNumber("ShadingType",2);
	shadingDict.PutName("ColorSpace","DeviceCMYK");
	
	// pass the coordinates of the axial shading to the output
	Obj shadingCoords = shadingDict.PutArray("Coords");
	shadingCoords.PushBackNumber(0);
	shadingCoords.PushBackNumber(0);
	shadingCoords.PushBackNumber(612);
	shadingCoords.PushBackNumber(794);

	// pass the function to the axial shading
	Obj function = shadingDict.PutDict("Function");
	Obj C0 = function.PutArray("C0");
	C0.PushBackNumber(1);
	C0.PushBackNumber(0);
	C0.PushBackNumber(0);
	C0.PushBackNumber(0);

	Obj C1 = function.PutArray("C1");
	C1.PushBackNumber(0);
	C1.PushBackNumber(1);
	C1.PushBackNumber(0);
	C1.PushBackNumber(0);
	
	Obj domain = function.PutArray("Domain");
	domain.PushBackNumber(0);
	domain.PushBackNumber(1);

	function.PutNumber("FunctionType", 2);
	function.PutNumber("N", 1);


	return pattern_dict;
}


int main(int argc, char *argv[])
{
	PDFNet::Initialize(LicenseKey);

	// Relative path to the folder containing test files.
	string output_path = "../../TestFiles/Output/";

	try  
	{	 
		PDFDoc doc;
		ElementWriter writer;	
		ElementBuilder eb;

		// The following sample illustrates how to create and use tiling patterns
		Page page = doc.PageCreate();
		writer.Begin(page);

		Element element = eb.CreateTextBegin(Font::Create(doc, Font::e_times_bold), 1);
		writer.WriteElement(element);  // Begin the text block

		const char* data = "G";
		element = eb.CreateTextRun((UChar*)data, UInt32(strlen(data)));
		element.SetTextMatrix(720, 0, 0, 720, 20, 240);
		GState gs = element.GetGState();
		gs.SetTextRenderMode(GState::e_fill_stroke_text);
		gs.SetLineWidth(4);

		// Set the fill color space to the Pattern color space. 
		gs.SetFillColorSpace(ColorSpace::CreatePattern());
		gs.SetFillColor(CreateTilingPattern(doc));

		writer.WriteElement(element);
		writer.WriteElement(eb.CreateTextEnd()); // Finish the text block

		writer.End();	// Save the page
		doc.PagePushBack(page);
		//-----------------------------------------------

		/// The following sample illustrates how to create and use image tiling pattern
		page = doc.PageCreate();
		writer.Begin(page);

		eb.Reset();
		element = eb.CreateRect(0, 0, 612, 794);

		// Set the fill color space to the Pattern color space. 
		gs = element.GetGState();
		gs.SetFillColorSpace(ColorSpace::CreatePattern());
		gs.SetFillColor(CreateImageTilingPattern(doc));
		element.SetPathFill(true);		

		writer.WriteElement(element);

		writer.End();	// Save the page
		doc.PagePushBack(page);
		//-----------------------------------------------

		/// The following sample illustrates how to create and use PDF shadings
		page = doc.PageCreate();
		writer.Begin(page);

		eb.Reset();
		element = eb.CreateRect(0, 0, 612, 794);

		// Set the fill color space to the Pattern color space. 
		gs = element.GetGState();
		gs.SetFillColorSpace(ColorSpace::CreatePattern());
		gs.SetFillColor(CreateAxialShading(doc));
		element.SetPathFill(true);		

		writer.WriteElement(element);

		writer.End();	// save the page
		doc.PagePushBack(page);
		//-----------------------------------------------

		doc.Save((output_path + "patterns.pdf").c_str(), SDFDoc::e_remove_unused, 0);
		cout << "Done. Result saved in patterns.pdf..." << endl;
	}
	catch(Common::Exception& e)
	{
		cout << e << endl;
	}
	catch(...)
	{
		cout << "Unknown Exception" << endl;
	}

	PDFNet::Terminate();
}
```

{% endcode %}
{% endtab %}

{% tab title="Java" %}
{% code lineNumbers="true" %}

```java
//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
// Consult legal.txt regarding legal and license information.
//---------------------------------------------------------------------------------------

import com.pdftron.common.Matrix2D;
import com.pdftron.common.PDFNetException;
import com.pdftron.pdf.*;
import com.pdftron.sdf.Obj;
import com.pdftron.sdf.SDFDoc;


public class PatternTest {


    public static final String input_path = "../../TestFiles/";


    static Obj CreateTilingPattern(PDFDoc doc) throws PDFNetException {
        ElementWriter writer = new ElementWriter();
        ElementBuilder eb = new ElementBuilder();

        // Create a new pattern content stream - a heart. ------------
        writer.begin(doc);
        eb.pathBegin();
        eb.moveTo(0, 0);
        eb.curveTo(500, 500, 125, 625, 0, 500);
        eb.curveTo(-125, 625, -500, 500, 0, 0);
        Element heart = eb.pathEnd();
        heart.setPathFill(true);

        // Set heart color to red.
        heart.getGState().setFillColorSpace(ColorSpace.createDeviceRGB());
        heart.getGState().setFillColor(new ColorPt(1, 0, 0));
        writer.writeElement(heart);

        Obj pattern_dict = writer.end();

        // Initialize pattern dictionary. For details on what each parameter represents please
        // refer to Table 4.22 (Section '4.6.2 Tiling Patterns') in PDF Reference Manual.
        pattern_dict.putName("Type", "Pattern");
        pattern_dict.putNumber("PatternType", 1);

        // TilingType - Constant spacing.
        pattern_dict.putNumber("TilingType", 1);

        // This is a Type1 pattern - A colored tiling pattern.
        pattern_dict.putNumber("PaintType", 1);

        // Set bounding box
        pattern_dict.putRect("BBox", -253, 0, 253, 545);

        // Create and set the matrix
        Matrix2D pattern_mtx = new Matrix2D(0.04, 0, 0, 0.04, 0, 0);
        pattern_dict.putMatrix("Matrix", pattern_mtx);

        // Set the desired horizontal and vertical spacing between pattern cells,
        // measured in the pattern coordinate system.
        pattern_dict.putNumber("XStep", 1000);
        pattern_dict.putNumber("YStep", 1000);

        return pattern_dict; // finished creating the Pattern resource
    }

    static Obj CreateImageTilingPattern(PDFDoc doc) throws PDFNetException {
        ElementWriter writer = new ElementWriter();
        ElementBuilder eb = new ElementBuilder();

        // Create a new pattern content stream - a single bitmap object ----------
        writer.begin(doc);
        Image image = Image.create(doc, (input_path + "dice.jpg"));
        Element img_element = eb.createImage(image, 0, 0, image.getImageWidth(), image.getImageHeight());
        writer.writePlacedElement(img_element);
        Obj pattern_dict = writer.end();

        // Initialize pattern dictionary. For details on what each parameter represents please
        // refer to Table 4.22 (Section '4.6.2 Tiling Patterns') in PDF Reference Manual.
        pattern_dict.putName("Type", "Pattern");
        pattern_dict.putNumber("PatternType", 1);

        // TilingType - Constant spacing.
        pattern_dict.putNumber("TilingType", 1);

        // This is a Type1 pattern - A colored tiling pattern.
        pattern_dict.putNumber("PaintType", 1);

        // Set bounding box
        pattern_dict.putRect("BBox", -253, 0, 253, 545);

        // Create and set the matrix
        Matrix2D pattern_mtx = new Matrix2D(0.3, 0, 0, 0.3, 0, 0);
        pattern_dict.putMatrix("Matrix", pattern_mtx);

        // Set the desired horizontal and vertical spacing between pattern cells,
        // measured in the pattern coordinate system.
        pattern_dict.putNumber("XStep", 300);
        pattern_dict.putNumber("YStep", 300);

        return pattern_dict; // finished creating the Pattern resource
    }

    static Obj CreateAxialShading(PDFDoc doc) throws PDFNetException {
        // Create a new Shading object ------------
        Obj pattern_dict = doc.createIndirectDict();

        // Initialize pattern dictionary. For details on what each parameter represents
        // please refer to Tables 4.30 and 4.26 in PDF Reference Manual
        pattern_dict.putName("Type", "Pattern");
        pattern_dict.putNumber("PatternType", 2); // 2 stands for shading

        Obj shadingDict = pattern_dict.putDict("Shading");
        shadingDict.putNumber("ShadingType", 2);
        shadingDict.putName("ColorSpace", "DeviceCMYK");

        // pass the coordinates of the axial shading to the output
        Obj shadingCoords = shadingDict.putArray("Coords");
        shadingCoords.pushBackNumber(0);
        shadingCoords.pushBackNumber(0);
        shadingCoords.pushBackNumber(612);
        shadingCoords.pushBackNumber(794);

        // pass the function to the axial shading
        Obj function = shadingDict.putDict("Function");
        Obj C0 = function.putArray("C0");
        C0.pushBackNumber(1);
        C0.pushBackNumber(0);
        C0.pushBackNumber(0);
        C0.pushBackNumber(0);

        Obj C1 = function.putArray("C1");
        C1.pushBackNumber(0);
        C1.pushBackNumber(1);
        C1.pushBackNumber(0);
        C1.pushBackNumber(0);

        Obj domain = function.putArray("Domain");
        domain.pushBackNumber(0);
        domain.pushBackNumber(1);

        function.putNumber("FunctionType", 2);
        function.putNumber("N", 1);


        return pattern_dict;
    }


    public static void main(String[] args) {
        PDFNet.initialize(PDFTronLicense.Key());

        // Relative path to the folder containing test files.
        String output_path = "../../TestFiles/Output/";

        try (PDFDoc doc = new PDFDoc()) {
            ElementWriter writer = new ElementWriter();
            ElementBuilder eb = new ElementBuilder();

            // The following sample illustrates how to create and use tiling patterns
            Page page = doc.pageCreate();
            writer.begin(page);

            Element element = eb.createTextBegin(Font.create(doc, Font.e_times_bold), 1);
            writer.writeElement(element);  // Begin the text block

            String data = "G";
            element = eb.createTextRun(data);
            element.setTextMatrix(720, 0, 0, 720, 20, 240);
            GState gs = element.getGState();
            gs.setTextRenderMode(GState.e_fill_stroke_text);
            gs.setLineWidth(4);

            // Set the fill color space to the Pattern color space.
            gs.setFillColorSpace(ColorSpace.createPattern());
            gs.setFillColor(new PatternColor(CreateTilingPattern(doc)));

            writer.writeElement(element);
            writer.writeElement(eb.createTextEnd()); // Finish the text block

            writer.end();    // Save the page
            doc.pagePushBack(page);
            //-----------------------------------------------

            /// The following sample illustrates how to create and use image tiling pattern
            page = doc.pageCreate();
            writer.begin(page);

            eb.reset();
            element = eb.createRect(0, 0, 612, 794);

            // Set the fill color space to the Pattern color space.
            gs = element.getGState();
            gs.setFillColorSpace(ColorSpace.createPattern());
            gs.setFillColor(new PatternColor(CreateImageTilingPattern(doc)));
            element.setPathFill(true);

            writer.writeElement(element);

            writer.end();    // Save the page
            doc.pagePushBack(page);
            //-----------------------------------------------

            /// The following sample illustrates how to create and use PDF shadings
            page = doc.pageCreate();
            writer.begin(page);

            eb.reset();
            element = eb.createRect(0, 0, 612, 794);

            // Set the fill color space to the Pattern color space.
            gs = element.getGState();
            gs.setFillColorSpace(ColorSpace.createPattern());

            gs.setFillColor(new PatternColor(CreateAxialShading(doc)));
            element.setPathFill(true);

            writer.writeElement(element);

            writer.end();    // save the page
            doc.pagePushBack(page);
            //-----------------------------------------------

            doc.save(output_path + "patterns.pdf", SDFDoc.SaveMode.REMOVE_UNUSED, null);
            System.out.println("Done. Result saved in patterns.pdf...");
        } catch (Exception e) {
            e.printStackTrace();
        }

        PDFNet.terminate();
    }
}
```

{% endcode %}
{% endtab %}

{% tab title="JavaScript" %}
{% code lineNumbers="true" %}

```js
//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
// Consult legal.txt regarding legal and license information.
//---------------------------------------------------------------------------------------

const { PDFNet } = require('@pdftron/pdfnet-node');
const PDFTronLicense = require('../LicenseKey/LicenseKey');

((exports) => {
  'use strict';

  exports.runPatternTest = () => {
    const createTilingPattern = async (doc) => {
      const writer = await PDFNet.ElementWriter.create();
      const eb = await PDFNet.ElementBuilder.create();

      // Create a new pattern content stream - a heart. ------------
      writer.begin(doc);
      eb.pathBegin();
      eb.moveTo(0, 0);
      eb.curveTo(500, 500, 125, 625, 0, 500);
      eb.curveTo(-125, 625, -500, 500, 0, 0);
      const heart = await eb.pathEnd();
      heart.setPathFill(true);

      // Set heart color to red.
      const gstate = await heart.getGState();
      gstate.setFillColorSpace(await PDFNet.ColorSpace.createDeviceRGB());
      gstate.setStrokeColorWithColorPt(await PDFNet.ColorPt.init(1, 0, 0));
      writer.writeElement(heart);

      const patternDict = await writer.end();

      // Initialize pattern dictionary. For details on what each parameter represents please 
      // refer to Table 4.22 (Section '4.6.2 Tiling Patterns') in PDF Reference Manual.
      patternDict.putName('Type', 'Pattern');
      patternDict.putNumber('PatternType', 1);

      // TilingType - Constant spacing.
      patternDict.putNumber('TilingType', 1);

      // This is a Type1 pattern - A colored tiling pattern.
      patternDict.putNumber('PaintType', 1);

      // Set bounding box
      patternDict.putRect('BBox', -253, 0, 253, 545);

      // Create and set the matrix
      const pattern_mtx = await PDFNet.Matrix2D.create(0.04, 0, 0, 0.04, 0, 0);
      patternDict.putMatrix('Matrix', pattern_mtx);

      // Set the desired horizontal and vertical spacing between pattern cells, 
      // measured in the pattern coordinate system.
      patternDict.putNumber('XStep', 1000);
      await patternDict.putNumber('YStep', 1000);

      return patternDict; // finished creating the Pattern resource
    }

    const createImageTilingPattern = async (doc) => {
      const writer = await PDFNet.ElementWriter.create();
      const eb = await PDFNet.ElementBuilder.create();

      // Create a new pattern content stream - a single bitmap object ----------
      writer.begin(doc);
      const image = await PDFNet.Image.createFromFile(doc, '../TestFiles/dice.jpg');
      const imgElement = await eb.createImageScaled(image, 0, 0, await image.getImageWidth(), await image.getImageHeight());
      writer.writePlacedElement(imgElement);

      const patternDict = await writer.end();

      // Initialize pattern dictionary. For details on what each parameter represents please 
      // refer to Table 4.22 (Section '4.6.2 Tiling Patterns') in PDF Reference Manual.
      patternDict.putName('Type', 'Pattern');
      patternDict.putNumber('PatternType', 1);

      // TilingType - Constant spacing.
      patternDict.putNumber('TilingType', 1);

      // This is a Type1 pattern - A colored tiling pattern.
      patternDict.putNumber('PaintType', 1);

      // Set bounding box
      patternDict.putRect('BBox', -253, 0, 253, 545);

      // Create and set the matrix
      const pattern_mtx = await PDFNet.Matrix2D.create(0.3, 0, 0, 0.3, 0, 0);
      patternDict.putMatrix('Matrix', pattern_mtx);

      // Set the desired horizontal and vertical spacing between pattern cells, 
      // measured in the pattern coordinate system.
      patternDict.putNumber('XStep', 300);
      await patternDict.putNumber('YStep', 300);

      return patternDict; // finished creating the Pattern resource
    }

    const createAxialShading = async (doc) => {
      // Create a new Shading object ------------
      const patternDict = await doc.createIndirectDict();

      // Initialize pattern dictionary. For details on what each parameter represents 
      // please refer to Tables 4.30 and 4.26 in PDF Reference Manual
      patternDict.putName('Type', 'Pattern');
      patternDict.putNumber('PatternType', 2); // 2 stands for shading

      const shadingDict = await patternDict.putDict('Shading');
      shadingDict.putNumber('ShadingType', 2);
      shadingDict.putName('ColorSpace', 'DeviceCMYK');

      // pass the coordinates of the axial shading to the output
      const shadingCoords = await shadingDict.putArray('Coords');
      shadingCoords.pushBackNumber(0);
      shadingCoords.pushBackNumber(0);
      shadingCoords.pushBackNumber(612);
      shadingCoords.pushBackNumber(794);

      // pass the function to the axial shading
      const func = await shadingDict.putDict('Function');
      const C0 = await func.putArray('C0');
      C0.pushBackNumber(1);
      C0.pushBackNumber(0);
      C0.pushBackNumber(0);
      await C0.pushBackNumber(0);

      const C1 = await func.putArray('C1');
      C1.pushBackNumber(0);
      C1.pushBackNumber(1);
      C1.pushBackNumber(0);
      await C1.pushBackNumber(0);

      const domain = await func.putArray('Domain');
      domain.pushBackNumber(0);
      await domain.pushBackNumber(1);

      func.putNumber('FunctionType', 2);
      await func.putNumber('N', 1);

      return patternDict;
    }

    const main = async () => {
      try {
        const doc = await PDFNet.PDFDoc.create();
        const writer = await PDFNet.ElementWriter.create();
        var eb = await PDFNet.ElementBuilder.create();

        // The following sample illustrates how to create and use tiling patterns
        var page = await doc.pageCreate();
        writer.beginOnPage(page);

        var element = await eb.createTextBeginWithFont(await PDFNet.Font.createAndEmbed(doc, PDFNet.Font.StandardType1Font.e_times_bold), 1);
        writer.writeElement(element);  // Begin the text block

        const data = 'G';
        element = await eb.createNewTextRun(data);
        element.setTextMatrixEntries(720, 0, 0, 720, 20, 240);
        var gs = await element.getGState();
        gs.setTextRenderMode(PDFNet.GState.TextRenderingMode.e_fill_stroke_text);
        gs.setLineWidth(4);

        // Set the fill color space to the Pattern color space. 
        gs.setFillColorSpace(await PDFNet.ColorSpace.createPattern());
        var patterColor = await PDFNet.PatternColor.create(await createTilingPattern(doc));
        gs.setFillColorWithPattern(patterColor);

        writer.writeElement(element);
        writer.writeElement(await eb.createTextEnd()); // Finish the text block

        writer.end();	// Save the page
        doc.pagePushBack(page);
        //-----------------------------------------------

        /// The following sample illustrates how to create and use image tiling pattern
        page = await doc.pageCreate();
        writer.beginOnPage(page);

        eb.reset();
        element = await eb.createRect(0, 0, 612, 794);

        // Set the fill color space to the Pattern color space. 
        gs = await element.getGState();
        gs.setFillColorSpace(await PDFNet.ColorSpace.createPattern());
        patterColor = await PDFNet.PatternColor.create(await createImageTilingPattern(doc));
        gs.setFillColorWithPattern(patterColor);
        element.setPathFill(true);

        writer.writeElement(element);

        await writer.end();	// Save the page
        doc.pagePushBack(page);
        //-----------------------------------------------

        /// The following sample illustrates how to create and use PDF shadings
        page = await doc.pageCreate();
        writer.beginOnPage(page);

        eb.reset();
        element = await eb.createRect(0, 0, 612, 794);

        // Set the fill color space to the Pattern color space. 
        gs = await element.getGState();
        gs.setFillColorSpace(await PDFNet.ColorSpace.createPattern());
        patterColor = await PDFNet.PatternColor.create(await createAxialShading(doc));
        gs.setFillColorWithPattern(patterColor);
        element.setPathFill(true);

        writer.writeElement(element);

        await writer.end();	// Save the page
        doc.pagePushBack(page);
        //-----------------------------------------------

        await doc.save('../TestFiles/Output/patterns.pdf', PDFNet.SDFDoc.SaveOptions.e_remove_unused);
        console.log('Done. Result saved in patterns.pdf...');
      } catch (err) {
        console.log(err);
      }
    }
    PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function(error) {
      console.log('Error: ' + JSON.stringify(error));
    }).then(function(){ return PDFNet.shutdown(); });
  };
  exports.runPatternTest();
})(exports);
  // eslint-disable-next-line spaced-comment
  //# sourceURL=PatternTest.js
```

{% endcode %}
{% endtab %}

{% tab title="PHP" %}
{% code lineNumbers="true" %}

```php
<?php
//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2023 by Apryse Software Inc. All Rights Reserved.
// Consult LICENSE.txt regarding license information.
//---------------------------------------------------------------------------------------
if(file_exists("../../../PDFNetC/Lib/PDFNetPHP.php"))
include("../../../PDFNetC/Lib/PDFNetPHP.php");
include("../../LicenseKey/PHP/LicenseKey.php");

// Relative path to the folder containing the test files.
$input_path = getcwd()."/../../TestFiles/";
$output_path = $input_path."Output/";

function CreateTilingPattern($doc) 
{
	$writer = new ElementWriter();	
	$builder = new ElementBuilder();

	// Create a new pattern content stream - a heart. ------------
	$writer->Begin($doc->GetSDFDoc());
	$builder->PathBegin();
	$builder->MoveTo(0, 0);
	$builder->CurveTo(500, 500, 125, 625, 0, 500);
	$builder->CurveTo(-125, 625, -500, 500, 0, 0);
	$heart = $builder->PathEnd();
	$heart->SetPathFill(true); 
	
	// Set heart color to red.
	$heart->GetGState()->SetFillColorSpace(ColorSpace::CreateDeviceRGB()); 
	$heart->GetGState()->SetFillColor(new ColorPt(1.0, 0.0, 0.0)); 
	$writer->WriteElement($heart);

	$pattern_dict = $writer->End();

	// Initialize pattern dictionary. For details on what each parameter represents please 
	// refer to Table 4.22 (Section '4.6.2 Tiling Patterns') in PDF Reference Manual.
	$pattern_dict->PutName("Type", "Pattern");
	$pattern_dict->PutNumber("PatternType", 1);

	// TilingType - Constant spacing.
	$pattern_dict->PutNumber("TilingType",1); 

	// This is a Type1 pattern - A colored tiling pattern.
	$pattern_dict->PutNumber("PaintType", 1);

	// Set bounding box
	$pattern_dict->PutRect("BBox", -253, 0, 253, 545);

	// Create and set the matrix
	$pattern_mtx = new Matrix2D(0.04,0.0,0.0,0.04,0.0,0.0);
	$pattern_dict->PutMatrix("Matrix", $pattern_mtx);

	// Set the desired horizontal and vertical spacing between pattern cells, 
	// measured in the pattern coordinate system.
	$pattern_dict->PutNumber("XStep", 1000);
	$pattern_dict->PutNumber("YStep", 1000);
	
	return $pattern_dict; // finished creating the Pattern resource
}

function CreateImageTilingPattern($doc) 
{
	$writer = new ElementWriter();	
	$builder = new ElementBuilder();

	// Create a new pattern content stream - a single bitmap object ----------
	$writer->Begin($doc->GetSDFDoc());
	global $input_path;
	$image = Image::Create($doc->GetSDFDoc(), $input_path."dice.jpg");
	$img_element = $builder->CreateImage($image, 0.0, 0.0, (double)$image->GetImageWidth(), (double)$image->GetImageHeight());
	$writer->WritePlacedElement($img_element);
	$pattern_dict = $writer->End();

	// Initialize pattern dictionary. For details on what each parameter represents please 
	// refer to Table 4.22 (Section '4.6.2 Tiling Patterns') in PDF Reference Manual.
	$pattern_dict->PutName("Type", "Pattern");
	$pattern_dict->PutNumber("PatternType",1);

	// TilingType - Constant spacing.
	$pattern_dict->PutNumber("TilingType", 1); 

	// This is a Type1 pattern - A colored tiling pattern.
	$pattern_dict->PutNumber("PaintType", 1);

	// Set bounding box
	$pattern_dict->PutRect("BBox", -253, 0, 253, 545);

	// Create and set the matrix
	$pattern_mtx = new Matrix2D(0.3,0.0,0.0,0.3,0.0,0.0);
	$pattern_dict->PutMatrix("Matrix", $pattern_mtx);

	// Set the desired horizontal and vertical spacing between pattern cells, 
	// measured in the pattern coordinate system.
	$pattern_dict->PutNumber("XStep", 300);
	$pattern_dict->PutNumber("YStep", 300);
	
	return $pattern_dict; // finished creating the Pattern resource
}

function CreateAxialShading($doc) 
{
	// Create a new Shading object ------------
	$pattern_dict = $doc->CreateIndirectDict();

	// Initialize pattern dictionary. For details on what each parameter represents 
	// please refer to Tables 4.30 and 4.26 in PDF Reference Manual
	$pattern_dict->PutName("Type", "Pattern");
	$pattern_dict->PutNumber("PatternType", 2); // 2 stands for shading
	
	$shadingDict = $pattern_dict->PutDict("Shading");
	$shadingDict->PutNumber("ShadingType",2);
	$shadingDict->PutName("ColorSpace","DeviceCMYK");
	
	// pass the coordinates of the axial shading to the output
	$shadingCoords = $shadingDict->PutArray("Coords");
	$shadingCoords->PushBackNumber(0);
	$shadingCoords->PushBackNumber(0);
	$shadingCoords->PushBackNumber(612);
	$shadingCoords->PushBackNumber(794);

	// pass the function to the axial shading
	$function = $shadingDict->PutDict("Function");
	$C0 = $function->PutArray("C0");
	$C0->PushBackNumber(1);
	$C0->PushBackNumber(0);
	$C0->PushBackNumber(0);
	$C0->PushBackNumber(0);

	$C1 = $function->PutArray("C1");
	$C1->PushBackNumber(0);
	$C1->PushBackNumber(1);
	$C1->PushBackNumber(0);
	$C1->PushBackNumber(0);
	
	$domain = $function->PutArray("Domain");
	$domain->PushBackNumber(0);
	$domain->PushBackNumber(1);

	$function->PutNumber("FunctionType", 2);
	$function->PutNumber("N", 1);


	return $pattern_dict;
}

//---------------------------------------------------------------------------------------

	PDFNet::Initialize($LicenseKey);
	PDFNet::GetSystemFontList();    // Wait for fonts to be loaded if they haven't already. This is done because PHP can run into errors when shutting down if font loading is still in progress.
	
	$doc = new PDFDoc();
	$writer = new ElementWriter();	
	$builder = new ElementBuilder();

	// The following sample illustrates how to create and use tiling patterns
	$page = $doc->PageCreate();
	$writer->Begin($page);

	$element = $builder->CreateTextBegin(Font::Create($doc->GetSDFDoc(), Font::e_times_bold), 1.0);
	$writer->WriteElement($element);  // Begin the text block

	$data = "G";
	$element = $builder->CreateTextRun($data);
	$element->SetTextMatrix(720.0, 0.0, 0.0, 720.0, 20.0, 240.0);
	$gs = $element->GetGState();
	$gs->SetTextRenderMode(GState::e_fill_stroke_text);
	$gs->SetLineWidth(4);

	// Set the fill color space to the Pattern color space. 
	$gs->SetFillColorSpace(ColorSpace::CreatePattern());
	$gs->SetFillColor(new PatternColor(CreateTilingPattern($doc)));

	$writer->WriteElement($element);
	$writer->WriteElement($builder->CreateTextEnd()); // Finish the text block

	$writer->End();	// Save the page
	$doc->PagePushBack($page);
	//-----------------------------------------------

	/// The following sample illustrates how to create and use image tiling pattern
	$page = $doc->PageCreate();
	$writer->Begin($page);

	$builder->Reset();
	$element = $builder->CreateRect(0, 0, 612, 794);

	// Set the fill color space to the Pattern color space. 
	$gs = $element->GetGState();
	$gs->SetFillColorSpace(ColorSpace::CreatePattern());
	$gs->SetFillColor(new PatternColor(CreateImageTilingPattern($doc)));
	$element->SetPathFill(true);		

	$writer->WriteElement($element);

	$writer->End();	// Save the page
	$doc->PagePushBack($page);
	//-----------------------------------------------

	/// The following sample illustrates how to create and use PDF shadings
	$page = $doc->PageCreate();
	$writer->Begin($page);

	$builder->Reset();
	$element = $builder->CreateRect(0, 0, 612, 794);

	// Set the fill color space to the Pattern color space. 
	$gs = $element->GetGState();
	$gs->SetFillColorSpace(ColorSpace::CreatePattern());
	$gs->SetFillColor(new PatternColor(CreateAxialShading($doc)));
	$element->SetPathFill(true);		

	$writer->WriteElement($element);

	$writer->End();	// save the page
	$doc->PagePushBack($page);
	//-----------------------------------------------

	$doc->Save($output_path."patterns.pdf", SDFDoc::e_remove_unused);
	PDFNet::Terminate();
	echo "Done. Result saved in patterns.pdf...\n";
?>
```

{% endcode %}
{% endtab %}

{% tab title="Python" %}
{% code lineNumbers="true" %}

```python
#---------------------------------------------------------------------------------------
# Copyright (c) 2001-2023 by Apryse Software Inc. All Rights Reserved.
# Consult LICENSE.txt regarding license information.
#---------------------------------------------------------------------------------------

import site
site.addsitedir("../../../PDFNetC/Lib")
import sys
from PDFNetPython import *

sys.path.append("../../LicenseKey/PYTHON")
from LicenseKey import *

# Relative path to the folder containing the test files.
input_path = "../../TestFiles/"
output_path = "../../TestFiles/Output/"

def CreateTilingPattern(doc):
    writer = ElementWriter()
    eb = ElementBuilder()
    
    # Create a new pattern content stream - a heart. ------------
    writer.Begin(doc.GetSDFDoc())
    eb.PathBegin()
    eb.MoveTo(0, 0)
    eb.CurveTo(500, 500, 125, 625, 0, 500)
    eb.CurveTo(-125, 625, -500, 500, 0, 0)
    heart = eb.PathEnd()
    heart.SetPathFill(True)
    
    # Set heart color to red.
    heart.GetGState().SetFillColorSpace(ColorSpace.CreateDeviceRGB()) 
    heart.GetGState().SetFillColor(ColorPt(1, 0, 0)) 
    writer.WriteElement(heart)
    
    pattern_dict = writer.End()
    
    # Initialize pattern dictionary. For details on what each parameter represents please 
    # refer to Table 4.22 (Section '4.6.2 Tiling Patterns') in PDF Reference Manual.
    pattern_dict.PutName("Type", "Pattern")
    pattern_dict.PutNumber("PatternType", 1)
    
    # TilingType - Constant spacing.
    pattern_dict.PutNumber("TilingType",1) 

    # This is a Type1 pattern - A colored tiling pattern.
    pattern_dict.PutNumber("PaintType", 1)

    # Set bounding box
    pattern_dict.PutRect("BBox", -253, 0, 253, 545)

    # Create and set the matrix
    pattern_mtx = Matrix2D(0.04,0,0,0.04,0,0)
    pattern_dict.PutMatrix("Matrix", pattern_mtx)
    
    # Set the desired horizontal and vertical spacing between pattern cells, 
    # measured in the pattern coordinate system.
    pattern_dict.PutNumber("XStep", 1000)
    pattern_dict.PutNumber("YStep", 1000)
    
    return pattern_dict # finished creating the Pattern resource

    
    
    
def CreateImageTilingPattern(doc):
    writer = ElementWriter()
    eb = ElementBuilder()
    
    # Create a new pattern content stream - a single bitmap object ----------
    writer.Begin(doc.GetSDFDoc())
    image = Image.Create(doc.GetSDFDoc(), input_path + "dice.jpg")
    img_element = eb.CreateImage(image, 0, 0, image.GetImageWidth(), image.GetImageHeight())
    writer.WritePlacedElement(img_element)
    pattern_dict = writer.End()
    
    # Initialize pattern dictionary. For details on what each parameter represents please 
    # refer to Table 4.22 (Section '4.6.2 Tiling Patterns') in PDF Reference Manual.
    pattern_dict.PutName("Type", "Pattern")
    pattern_dict.PutNumber("PatternType",1)
    
    # TilingType - Constant spacing.
    pattern_dict.PutNumber("TilingType", 1)
    
    # This is a Type1 pattern - A colored tiling pattern.
    pattern_dict.PutNumber("PaintType", 1)
    
    # Set bounding box
    pattern_dict.PutRect("BBox", -253, 0, 253, 545)
    
    # Create and set the matrix
    pattern_mtx = Matrix2D(0.3,0,0,0.3,0,0)
    pattern_dict.PutMatrix("Matrix", pattern_mtx)
    
    # Set the desired horizontal and vertical spacing between pattern cells, 
    # measured in the pattern coordinate system.
    pattern_dict.PutNumber("XStep", 300)
    pattern_dict.PutNumber("YStep", 300)
    
    return pattern_dict     # finished creating the Pattern resource
    
    
def CreateAxialShading(doc):
    # Create a new Shading object ------------
    pattern_dict = doc.CreateIndirectDict()
    
    # Initialize pattern dictionary. For details on what each parameter represents 
    # please refer to Tables 4.30 and 4.26 in PDF Reference Manual
    pattern_dict.PutName("Type", "Pattern")
    pattern_dict.PutNumber("PatternType", 2)    # 2 stands for shading
    
    shadingDict = pattern_dict.PutDict("Shading")
    shadingDict.PutNumber("ShadingType",2)
    shadingDict.PutName("ColorSpace","DeviceCMYK")
    
    # pass the coordinates of the axial shading to the output
    shadingCoords = shadingDict.PutArray("Coords")
    shadingCoords.PushBackNumber(0)
    shadingCoords.PushBackNumber(0)
    shadingCoords.PushBackNumber(612)
    shadingCoords.PushBackNumber(794)
    
    # pass the function to the axial shading
    function = shadingDict.PutDict("Function")
    C0 = function.PutArray("C0")
    C0.PushBackNumber(1)
    C0.PushBackNumber(0)
    C0.PushBackNumber(0)
    C0.PushBackNumber(0)
    
    C1 = function.PutArray("C1")
    C1.PushBackNumber(0)
    C1.PushBackNumber(1)
    C1.PushBackNumber(0)
    C1.PushBackNumber(0)
    
    domain = function.PutArray("Domain")
    domain.PushBackNumber(0)
    domain.PushBackNumber(1)
    
    function.PutNumber("FunctionType", 2)
    function.PutNumber("N", 1)
    
    return pattern_dict
    

def main():
    PDFNet.Initialize(LicenseKey)
      
    doc = PDFDoc()
    writer = ElementWriter()
    eb = ElementBuilder()
    
    # The following sample illustrates how to create and use tiling patterns
    page = doc.PageCreate()
    writer.Begin(page)
    
    element = eb.CreateTextBegin(Font.Create(doc.GetSDFDoc(), Font.e_times_bold), 1)
    writer.WriteElement(element) # Begin the text block
    
    data = "G"
    element = eb.CreateTextRun(data)
    element.SetTextMatrix(720, 0, 0, 720, 20, 240)
    gs = element.GetGState()
    gs.SetTextRenderMode(GState.e_fill_stroke_text)
    gs.SetLineWidth(4)
    
    # Set the fill color space to the Pattern color space. 
    gs.SetFillColorSpace(ColorSpace.CreatePattern())
    gs.SetFillColor(PatternColor(CreateTilingPattern(doc)))
    
    element.SetPathFill(True)
   
    writer.WriteElement(element)
    writer.WriteElement(eb.CreateTextEnd()) # Finish the text block
    
    writer.End() # Save the page
    doc.PagePushBack(page)
    
    #-----------------------------------------------
    # The following sample illustrates how to create and use image tiling pattern
    
    page = doc.PageCreate()
    writer.Begin(page)
    
    eb.Reset()
    element = eb.CreateRect(0, 0, 612, 794)
    
    # Set the fill color space to the Pattern color space. 
    gs = element.GetGState()
    gs.SetFillColorSpace(ColorSpace.CreatePattern())
    gs.SetFillColor(PatternColor(CreateImageTilingPattern(doc)))
    element.SetPathFill(True)
    
    writer.WriteElement(element)
    
    writer.End()    # Save the page
    doc.PagePushBack(page)
    
    #-----------------------------------------------
    
    # The following sample illustrates how to create and use PDF shadings
    page = doc.PageCreate()
    writer.Begin(page)
    
    eb.Reset()
    element = eb.CreateRect(0, 0, 612, 794)
    
    # Set the fill color space to the Pattern color space. 
    gs = element.GetGState()
    gs.SetFillColorSpace(ColorSpace.CreatePattern())
    gs.SetFillColor(PatternColor(CreateAxialShading(doc)))
    element.SetPathFill(True)
    
    writer.WriteElement(element)
    writer.End()    # save the page
    doc.PagePushBack(page)
    #-----------------------------------------------
    
    doc.Save(output_path + "patterns.pdf", SDFDoc.e_remove_unused)
    print("Done. Result saved in patterns.pdf...")
    
    doc.Close()
    PDFNet.Terminate()

if __name__ == '__main__':
    main()
```

{% endcode %}
{% endtab %}

{% tab title="Ruby" %}
{% code lineNumbers="true" %}

```ruby
#---------------------------------------------------------------------------------------
# Copyright (c) 2001-2023 by Apryse Software Inc. All Rights Reserved.
# Consult LICENSE.txt regarding license information.
#---------------------------------------------------------------------------------------

require '../../../PDFNetC/Lib/PDFNetRuby'
include PDFNetRuby
require '../../LicenseKey/RUBY/LicenseKey'

$stdout.sync = true

# Relative path to the folder containing the test files.
$input_path = "../../TestFiles/"
$output_path = "../../TestFiles/Output/"

def CreateTilingPattern(doc)
	writer = ElementWriter.new
	eb = ElementBuilder.new
	
	# Create a new pattern content stream - a heart. ------------
	writer.Begin(doc.GetSDFDoc)
	eb.PathBegin
	eb.MoveTo(0, 0)
	eb.CurveTo(500, 500, 125, 625, 0, 500)
	eb.CurveTo(-125, 625, -500, 500, 0, 0)
	heart = eb.PathEnd
	heart.SetPathFill(true)
	
	# Set heart color to red.
	heart.GetGState.SetFillColorSpace(ColorSpace.CreateDeviceRGB) 
	heart.GetGState.SetFillColor(ColorPt.new(1, 0, 0)) 
	writer.WriteElement(heart)
	
	pattern_dict = writer.End
	
	# Initialize pattern dictionary. For details on what each parameter represents please 
	# refer to Table 4.22 (Section '4.6.2 Tiling Patterns') in PDF Reference Manual.
	pattern_dict.PutName("Type", "Pattern")
	pattern_dict.PutNumber("PatternType", 1)
	
	# TilingType - Constant spacing.
	pattern_dict.PutNumber("TilingType",1) 

	# This is a Type1 pattern - A colored tiling pattern.
	pattern_dict.PutNumber("PaintType", 1)

	# Set bounding box
	pattern_dict.PutRect("BBox", -253, 0, 253, 545)

	# Create and set the matrix
	pattern_mtx = Matrix2D.new(0.04,0,0,0.04,0,0)
	pattern_dict.PutMatrix("Matrix", pattern_mtx)
	
	# Set the desired horizontal and vertical spacing between pattern cells, 
	# measured in the pattern coordinate system.
	pattern_dict.PutNumber("XStep", 1000)
	pattern_dict.PutNumber("YStep", 1000)
	
	return pattern_dict # finished creating the Pattern resource
end

def CreateImageTilingPattern(doc)
	writer = ElementWriter.new
	eb = ElementBuilder.new
	
	# Create a new pattern content stream - a single bitmap object ----------
	writer.Begin(doc.GetSDFDoc)
	image = Image.Create(doc.GetSDFDoc, $input_path + "dice.jpg")
	img_element = eb.CreateImage(image, 0, 0, image.GetImageWidth, image.GetImageHeight)
	writer.WritePlacedElement(img_element)
	pattern_dict = writer.End
	
	# Initialize pattern dictionary. For details on what each parameter represents please 
	# refer to Table 4.22 (Section '4.6.2 Tiling Patterns') in PDF Reference Manual.
	pattern_dict.PutName("Type", "Pattern")
	pattern_dict.PutNumber("PatternType",1)
	
	# TilingType - Constant spacing.
	pattern_dict.PutNumber("TilingType", 1)
	
	# This is a Type1 pattern - A colored tiling pattern.
	pattern_dict.PutNumber("PaintType", 1)
	
	# Set bounding box
	pattern_dict.PutRect("BBox", -253, 0, 253, 545)
	
	# Create and set the matrix
	pattern_mtx = Matrix2D.new(0.3,0,0,0.3,0,0)
	pattern_dict.PutMatrix("Matrix", pattern_mtx)
	
	# Set the desired horizontal and vertical spacing between pattern cells, 
	# measured in the pattern coordinate system.
	pattern_dict.PutNumber("XStep", 300)
	pattern_dict.PutNumber("YStep", 300)
	
	return pattern_dict	 # finished creating the Pattern resource
end
	
def CreateAxialShading(doc)
	# Create a new Shading object ------------
	pattern_dict = doc.CreateIndirectDict
	
	# Initialize pattern dictionary. For details on what each parameter represents 
	# please refer to Tables 4.30 and 4.26 in PDF Reference Manual
	pattern_dict.PutName("Type", "Pattern")
	pattern_dict.PutNumber("PatternType", 2)	# 2 stands for shading
	
	shadingDict = pattern_dict.PutDict("Shading")
	shadingDict.PutNumber("ShadingType",2)
	shadingDict.PutName("ColorSpace","DeviceCMYK")
	
	# pass the coordinates of the axial shading to the output
	shadingCoords = shadingDict.PutArray("Coords")
	shadingCoords.PushBackNumber(0)
	shadingCoords.PushBackNumber(0)
	shadingCoords.PushBackNumber(612)
	shadingCoords.PushBackNumber(794)
	
	# pass the function to the axial shading
	function = shadingDict.PutDict("Function")
	c0 = function.PutArray("C0")
	c0.PushBackNumber(1)
	c0.PushBackNumber(0)
	c0.PushBackNumber(0)
	c0.PushBackNumber(0)
	
	c1 = function.PutArray("C1")
	c1.PushBackNumber(0)
	c1.PushBackNumber(1)
	c1.PushBackNumber(0)
	c1.PushBackNumber(0)
	
	domain = function.PutArray("Domain")
	domain.PushBackNumber(0)
	domain.PushBackNumber(1)
	
	function.PutNumber("FunctionType", 2)
	function.PutNumber("N", 1)
	
	return pattern_dict
end

	PDFNet.Initialize(PDFTronLicense.Key)
	  
	doc = PDFDoc.new
	writer = ElementWriter.new
	eb = ElementBuilder.new
	
	# The following sample illustrates how to create and use tiling patterns
	page = doc.PageCreate
	writer.Begin(page)
	
	element = eb.CreateTextBegin(Font.Create(doc.GetSDFDoc, Font::E_times_bold), 1)
	writer.WriteElement(element) # Begin the text block
	
	data = "G"
	element = eb.CreateTextRun(data)
	element.SetTextMatrix(720, 0, 0, 720, 20, 240)
	gs = element.GetGState
	gs.SetTextRenderMode(GState::E_fill_stroke_text)
	gs.SetLineWidth(4)
	
	# Set the fill color space to the Pattern color space. 
	gs.SetFillColorSpace(ColorSpace.CreatePattern)
	gs.SetFillColor(PatternColor.new(CreateTilingPattern(doc)))
	
	element.SetPathFill(true)
   
	writer.WriteElement(element)
	writer.WriteElement(eb.CreateTextEnd) # Finish the text block
	
	writer.End # Save the page
	doc.PagePushBack(page)
	
	#-----------------------------------------------
	# The following sample illustrates how to create and use image tiling pattern
	
	page = doc.PageCreate
	writer.Begin(page)
	
	eb.Reset
	element = eb.CreateRect(0, 0, 612, 794)
	
	# Set the fill color space to the Pattern color space. 
	gs = element.GetGState
	gs.SetFillColorSpace(ColorSpace.CreatePattern)
	gs.SetFillColor(PatternColor.new(CreateImageTilingPattern(doc)))
	element.SetPathFill(true)
	
	writer.WriteElement(element)
	
	writer.End	# Save the page
	doc.PagePushBack(page)
	
	#-----------------------------------------------
	
	# The following sample illustrates how to create and use PDF shadings
	page = doc.PageCreate
	writer.Begin(page)
	
	eb.Reset
	element = eb.CreateRect(0, 0, 612, 794)
	
	# Set the fill color space to the Pattern color space. 
	gs = element.GetGState
	gs.SetFillColorSpace(ColorSpace.CreatePattern)
	gs.SetFillColor(PatternColor.new(CreateAxialShading(doc)))
	element.SetPathFill(true)
	
	writer.WriteElement(element)
	writer.End	# save the page
	doc.PagePushBack(page)
	#-----------------------------------------------
	
	doc.Save($output_path + "patterns.pdf", SDFDoc::E_remove_unused)
	puts "Done. Result saved in patterns.pdf..."
	
	doc.Close
	PDFNet.Terminate
```

{% endcode %}
{% endtab %}

{% tab title="VB" %}
{% code lineNumbers="true" %}

```vb
Imports System
Imports PDFTRON
Imports PDFTRON.Common
Imports PDFTRON.Filters
Imports PDFTRON.SDF
Imports PDFTRON.PDF
Module PatternTestVB
	Dim pdfNetLoader As PDFNetLoader
	Sub New()
		pdfNetLoader = pdftron.PDFNetLoader.Instance()
	End Sub

	' <summary>
	' This example illustrates how to create PDF patterns and shadings.
	' </summary>
	Sub Main()

		Const output_path As String = "../../../../TestFiles/Output/"
		PDFNet.Initialize(PDFTronLicense.Key)
		Try
			Using doc As PDFDoc = New PDFDoc
				Using writer As ElementWriter = New ElementWriter
					Using eb As ElementBuilder = New ElementBuilder

						' The following sample illustrates how to create and use tiling patterns
						Dim page As Page = doc.PageCreate
						writer.Begin(page)

						' Begin the text block
						Dim element As Element = eb.CreateTextBegin(Font.Create(doc, Font.StandardType1Font.e_times_bold), 1)
						writer.WriteElement(element)

						element = eb.CreateTextRun("G")
						element.SetTextMatrix(720, 0, 0, 720, 20, 240)
						Dim gs As GState = element.GetGState
						gs.SetTextRenderMode(GState.TextRenderingMode.e_fill_stroke_text)
						gs.SetLineWidth(4)

						' Set the fill color space to the Pattern color space. 
						gs.SetFillColorSpace(ColorSpace.CreatePattern)
						gs.SetFillColor(PatternTest.CreateTilingPattern(doc))


						writer.WriteElement(element)
						writer.WriteElement(eb.CreateTextEnd) ' Finish the text block

						writer.End() ' Save the page
						doc.PagePushBack(page)

						'-----------------------------------------------
						'  The following sample illustrates how to create and use image tiling pattern
						page = doc.PageCreate
						writer.Begin(page)

						eb.Reset()
						element = eb.CreateRect(0, 0, 612, 794)

						' Set the fill color space to the Pattern color space. 
						gs = element.GetGState
						gs.SetFillColorSpace(ColorSpace.CreatePattern)
						gs.SetFillColor(PatternTest.CreateImageTilingPattern(doc))
						element.SetPathFill(True)

						writer.WriteElement(element)

						writer.End() ' save the page
						doc.PagePushBack(page)
						'-----------------------------------------------

						' The following sample illustrates how to create and use PDF shadings
						page = doc.PageCreate
						writer.Begin(page)

						eb.Reset()
						element = eb.CreateRect(0, 0, 612, 794)

						' Set the fill color space to the Pattern color space. 
						gs = element.GetGState
						gs.SetFillColorSpace(ColorSpace.CreatePattern)
						gs.SetFillColor(PatternTest.CreateAxialShading(doc))
						element.SetPathFill(True)

						writer.WriteElement(element)

						writer.End() ' save the page
						doc.PagePushBack(page)

					End Using
				End Using

				doc.Save(output_path + "patterns.pdf", SDFDoc.SaveOptions.e_remove_unused)
			End Using
			Console.WriteLine("Done. Result saved in patterns.pdf...")
		Catch e As PDFNetException
			Console.WriteLine(e.Message)
		End Try
		PDFNet.Terminate()
	End Sub

	Class PatternTest
		'Relative path to the folder containing test files.
		Const input_path As String = "../../../../TestFiles/"



		Shared Function CreateTilingPattern(ByVal doc As PDFDoc) As PatternColor

			Using writer As ElementWriter = New ElementWriter
				Using eb As ElementBuilder = New ElementBuilder

					' Create a new pattern content stream - a heart. ------------
					writer.Begin(doc.GetSDFDoc)
					eb.PathBegin()
					eb.MoveTo(0, 0)
					eb.CurveTo(500, 500, 125, 625, 0, 500)
					eb.CurveTo(-125, 625, -500, 500, 0, 0)
					Dim heart As Element = eb.PathEnd
					heart.SetPathFill(True)

					' Set heart color to red.
					heart.GetGState.SetFillColorSpace(ColorSpace.CreateDeviceRGB)
					heart.GetGState.SetFillColor(New ColorPt(1, 0, 0))
					writer.WriteElement(heart)

					Dim pattern_dict As Obj = writer.End()

					' Initialize pattern dictionary. For details on what each parameter represents please 
					' refer to Table 4.22 (Section '4.6.2 Tiling Patterns') in PDF Reference Manual.
					pattern_dict.PutName("Type", "Pattern")
					pattern_dict.PutNumber("PatternType", 1)

					' TilingType - Constant spacing.
					pattern_dict.PutNumber("TilingType", 1)


					' This is a Type1 pattern - A colored tiling pattern.
					pattern_dict.PutNumber("PaintType", 1)

					' Set bounding box
					pattern_dict.PutRect("BBox", -253, 0, 253, 545)

					' Set the pattern matrix
					pattern_dict.PutMatrix("Matrix", New Matrix2D(0.04, 0, 0, 0.04, 0, 0))

					'Set the desired horizontal and vertical spacing between pattern cells, 
					' measured in the pattern coordinate system.
					pattern_dict.PutNumber("XStep", 1000)
					pattern_dict.PutNumber("YStep", 1000)

					Return New PatternColor(pattern_dict)			 ' finished creating the Pattern resource
				End Using
			End Using
		End Function

		Shared Function CreateImageTilingPattern(ByVal doc As PDFDoc) As PatternColor

			Using writer As ElementWriter = New ElementWriter
				Using eb As ElementBuilder = New ElementBuilder

					' Create a new pattern content stream - a single bitmap object ----------
					writer.Begin(doc.GetSDFDoc)
					Dim img As Image = Image.Create(doc.GetSDFDoc, input_path + "butterfly.png")
					Dim img_element As Element = eb.CreateImage(img, 0, 0, img.GetImageWidth, img.GetImageHeight)
					writer.WritePlacedElement(img_element)
					Dim pattern_dict As Obj = writer.End()

					' Initialize pattern dictionary. For details on what each parameter represents please 
					' refer to Table 4.22 (Section '4.6.2 Tiling Patterns') in PDF Reference Manual.
					pattern_dict.PutName("Type", "Pattern")
					pattern_dict.PutNumber("PatternType", 1)

					' TilingType - Constant spacing.
					pattern_dict.PutNumber("TilingType", 1)

					' This is a Type1 pattern - A colored tiling pattern.
					pattern_dict.PutNumber("PaintType", 1)

					' Set bounding box
					pattern_dict.PutRect("BBox", -253, 0, 253, 545)

					' Set the pattern matrix
					pattern_dict.PutMatrix("Matrix", New Matrix2D(0.3, 0, 0, 0.3, 0, 0))

					' Set the desired horizontal and vertical spacing between pattern cells, 
					' measured in the pattern coordinate system.
					pattern_dict.PutNumber("XStep", 300)
					pattern_dict.PutNumber("YStep", 300)
					Return New PatternColor(pattern_dict)			 ' finished creating the Pattern resource
				End Using
			End Using
		End Function

		Shared Function CreateAxialShading(ByVal doc As PDFDoc) As PatternColor

			' Create a new Shading object ------------
			Dim pattern_dict As Obj = doc.CreateIndirectDict()

			' Initialize pattern dictionary. For details on what each parameter represents 
			' please refer to Tables 4.30 and 4.26 in PDF Reference Manual
			pattern_dict.PutName("Type", "Pattern")
			pattern_dict.PutNumber("PatternType", 2)			 ' 2 stands for shading

			Dim shadingDict As Obj = pattern_dict.PutDict("Shading")
			shadingDict.PutNumber("ShadingType", 2)
			shadingDict.PutName("ColorSpace", "DeviceCMYK")

			' pass the coordinates of the axial shading to the output
			Dim shadingCoords As Obj = shadingDict.PutArray("Coords")
			shadingCoords.PushBackNumber(0)
			shadingCoords.PushBackNumber(0)
			shadingCoords.PushBackNumber(612)
			shadingCoords.PushBackNumber(794)

			' Set the shading Function for axial shading
			Dim funct As Obj = shadingDict.PutDict("Function")
			Dim C0 As Obj = funct.PutArray("C0")
			C0.PushBackNumber(1)
			C0.PushBackNumber(0)
			C0.PushBackNumber(0)
			C0.PushBackNumber(0)

			Dim C1 As Obj = funct.PutArray("C1")
			C1.PushBackNumber(0)
			C1.PushBackNumber(1)
			C1.PushBackNumber(0)
			C1.PushBackNumber(0)

			Dim domain As Obj = funct.PutArray("Domain")
			domain.PushBackNumber(0)
			domain.PushBackNumber(1)

			funct.PutNumber("FunctionType", 2)
			funct.PutNumber("N", 1)

			Return New PatternColor(pattern_dict)
		End Function
	End Class
End Module
```

{% endcode %}
{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.apryse.com/core/get-started/samples/patterntest.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
