Sample C# code for using Apryse SDK to create various patterns and shadings in PDF files. Learn more about our Server SDK and PDF Editing & Manipulation Library.
1//
2// Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
3//
4
5using System;
6using pdftron;
7using pdftron.Common;
8using pdftron.Filters;
9using pdftron.SDF;
10using pdftron.PDF;
11
12namespace PatternTestCS
13{
14 /// <summary>
15 /// This example illustrates how to create PDF patterns and shadings.
16 /// </summary>
17 class PatternTest
18 {
19 private static pdftron.PDFNetLoader pdfNetLoader = pdftron.PDFNetLoader.Instance();
20 static PatternTest() {}
21
22 // Relative path to the folder containing test files.
23 const string input_path = "../../../../TestFiles/";
24 const string output_path = "../../../../TestFiles/Output/";
25
26 static void Main(string[] args)
27 {
28 PDFNet.Initialize(PDFTronLicense.Key);
29 try
30 {
31 using (PDFDoc doc = new PDFDoc())
32 using (ElementWriter writer = new ElementWriter())
33 using (ElementBuilder eb = new ElementBuilder())
34 {
35 // The following sample illustrates how to create and use tiling patterns
36 Page page = doc.PageCreate();
37 writer.Begin(page);
38
39 Element element = eb.CreateTextBegin(Font.Create(doc, Font.StandardType1Font.e_times_bold), 1);
40 writer.WriteElement(element); // Begin the text block
41
42 element = eb.CreateTextRun("G");
43 element.SetTextMatrix(720, 0, 0, 720, 20, 240);
44 GState gs = element.GetGState();
45 gs.SetTextRenderMode(GState.TextRenderingMode.e_fill_stroke_text);
46 gs.SetLineWidth(4);
47
48 // Set the fill color space to the Pattern color space.
49 gs.SetFillColorSpace(ColorSpace.CreatePattern());
50 gs.SetFillColor(CreateTilingPattern(doc));
51
52 writer.WriteElement(element);
53 writer.WriteElement(eb.CreateTextEnd()); // Finish the text block
54
55 writer.End(); // Save the page
56 doc.PagePushBack(page);
57 //-----------------------------------------------
58
59 /// The following sample illustrates how to create and use image tiling pattern
60 page = doc.PageCreate();
61 writer.Begin(page);
62
63 eb.Reset();
64 element = eb.CreateRect(0, 0, 612, 794);
65
66 // Set the fill color space to the Pattern color space.
67 gs = element.GetGState();
68 gs.SetFillColorSpace(ColorSpace.CreatePattern());
69 gs.SetFillColor(CreateImageTilingPattern(doc));
70 element.SetPathFill(true);
71
72 writer.WriteElement(element);
73
74 writer.End(); // Save the page
75 doc.PagePushBack(page);
76 //-----------------------------------------------
77
78 /// The following sample illustrates how to create and use PDF shadings
79 page = doc.PageCreate();
80 writer.Begin(page);
81
82 eb.Reset();
83 element = eb.CreateRect(0, 0, 612, 794);
84
85 // Set the fill color space to the Pattern color space.
86 gs = element.GetGState();
87 gs.SetFillColorSpace(ColorSpace.CreatePattern());
88 gs.SetFillColor(CreateAxialShading(doc));
89 element.SetPathFill(true);
90
91 writer.WriteElement(element);
92
93 writer.End(); // save the page
94 doc.PagePushBack(page);
95 //-----------------------------------------------
96
97 doc.Save(output_path + "patterns.pdf", SDFDoc.SaveOptions.e_remove_unused);
98 Console.WriteLine("Done. Result saved in patterns.pdf...");
99 }
100 }
101 catch (PDFNetException e)
102 {
103 Console.WriteLine(e.Message);
104 }
105 PDFNet.Terminate();
106 }
107
108 static PatternColor CreateTilingPattern(PDFDoc doc)
109 {
110 using (ElementWriter writer = new ElementWriter())
111 using (ElementBuilder eb = new ElementBuilder())
112 {
113 // Create a new pattern content stream - a heart. ------------
114 writer.Begin(doc);
115 eb.PathBegin();
116 eb.MoveTo(0, 0);
117 eb.CurveTo(500, 500, 125, 625, 0, 500);
118 eb.CurveTo(-125, 625, -500, 500, 0, 0);
119 Element heart = eb.PathEnd();
120 heart.SetPathFill(true);
121
122 // Set heart color to red.
123 heart.GetGState().SetFillColorSpace(ColorSpace.CreateDeviceRGB());
124 heart.GetGState().SetFillColor(new ColorPt(1, 0, 0));
125 writer.WriteElement(heart);
126
127 Obj pattern_dict = writer.End();
128
129 // Initialize pattern dictionary. For details on what each parameter represents please
130 // refer to Table 4.22 (Section '4.6.2 Tiling Patterns') in PDF Reference Manual.
131 pattern_dict.PutName("Type", "Pattern");
132 pattern_dict.PutNumber("PatternType", 1);
133
134 // TilingType - Constant spacing.
135 pattern_dict.PutNumber("TilingType", 1);
136
137 // This is a Type1 pattern - A colored tiling pattern.
138 pattern_dict.PutNumber("PaintType", 1);
139
140 // Set bounding box
141 pattern_dict.PutRect("BBox", -253, 0, 253, 545);
142
143 // Set the pattern matrix
144 pattern_dict.PutMatrix("Matrix", new Matrix2D(0.04, 0, 0, 0.04, 0, 0));
145
146 // Set the desired horizontal and vertical spacing between pattern cells,
147 // measured in the pattern coordinate system.
148 pattern_dict.PutNumber("XStep", 1000);
149 pattern_dict.PutNumber("YStep", 1000);
150
151 return new PatternColor(pattern_dict); // finished creating the Pattern resource
152 }
153 }
154
155 static PatternColor CreateImageTilingPattern(PDFDoc doc)
156 {
157 using (ElementWriter writer = new ElementWriter())
158 using (ElementBuilder eb = new ElementBuilder())
159 {
160
161 // Create a new pattern content stream - a single bitmap object ----------
162 writer.Begin(doc);
163 Image img = Image.Create(doc, input_path + "butterfly.png");
164 Element img_element = eb.CreateImage(img, 0, 0, img.GetImageWidth(), img.GetImageHeight());
165 writer.WritePlacedElement(img_element);
166 Obj pattern_dict = writer.End();
167
168 // Initialize pattern dictionary. For details on what each parameter represents please
169 // refer to Table 4.22 (Section '4.6.2 Tiling Patterns') in PDF Reference Manual.
170 pattern_dict.PutName("Type", "Pattern");
171 pattern_dict.PutNumber("PatternType", 1);
172
173 // TilingType - Constant spacing.
174 pattern_dict.PutNumber("TilingType", 1);
175
176 // This is a Type1 pattern - A colored tiling pattern.
177 pattern_dict.PutNumber("PaintType", 1);
178
179 // Set bounding box
180 pattern_dict.PutRect("BBox", -253, 0, 253, 545);
181
182 // Set the pattern matrix
183 pattern_dict.PutMatrix("Matrix", new Matrix2D(0.3, 0, 0, 0.3, 0, 0));
184
185 // Set the desired horizontal and vertical spacing between pattern cells,
186 // measured in the pattern coordinate system.
187 pattern_dict.PutNumber("XStep", 300);
188 pattern_dict.PutNumber("YStep", 300);
189
190 return new PatternColor(pattern_dict); // finished creating the Pattern resource
191 }
192 }
193
194 static PatternColor CreateAxialShading(PDFDoc doc)
195 {
196 // Create a new Shading object ------------
197 Obj pattern_dict = doc.CreateIndirectDict();
198
199 // Initialize pattern dictionary. For details on what each parameter represents
200 // please refer to Tables 4.30 and 4.26 in PDF Reference Manual
201 pattern_dict.PutName("Type", "Pattern");
202 pattern_dict.PutNumber("PatternType", 2); // 2 stands for shading
203
204 Obj shadingDict = pattern_dict.PutDict("Shading");
205 shadingDict.PutNumber("ShadingType", 2);
206 shadingDict.PutName("ColorSpace", "DeviceCMYK");
207
208 // Set the coordinates of the axial shading to the output
209 shadingDict.PutRect("Coords", 0, 0, 612, 794);
210
211 // Set the Functions for the axial shading
212 Obj funct = shadingDict.PutDict("Function");
213 Obj C0 = funct.PutArray("C0");
214 C0.PushBackNumber(1);
215 C0.PushBackNumber(0);
216 C0.PushBackNumber(0);
217 C0.PushBackNumber(0);
218
219 Obj C1 = funct.PutArray("C1");
220 C1.PushBackNumber(0);
221 C1.PushBackNumber(1);
222 C1.PushBackNumber(0);
223 C1.PushBackNumber(0);
224
225 Obj domain = funct.PutArray("Domain");
226 domain.PushBackNumber(0);
227 domain.PushBackNumber(1);
228
229 funct.PutNumber("FunctionType", 2);
230 funct.PutNumber("N", 1);
231
232 return new PatternColor(pattern_dict);
233 }
234 }
235}
1//---------------------------------------------------------------------------------------
2// Copyright (c) 2001-2021 by PDFTron Systems Inc. All Rights Reserved.
3// Consult LICENSE.txt regarding license information.
4//---------------------------------------------------------------------------------------
5
6package main
7import (
8 "fmt"
9 . "pdftron"
10)
11
12import "pdftron/Samples/LicenseKey/GO"
13
14// Relative path to the folder containing the test files.
15var inputPath = "../../TestFiles/"
16var outputPath = "../../TestFiles/Output/"
17
18func CreateTilingPattern(doc PDFDoc) Obj{
19 writer := NewElementWriter()
20 eb := NewElementBuilder()
21
22 // Create a new pattern content stream - a heart. ------------
23 writer.Begin(doc.GetSDFDoc())
24 eb.PathBegin()
25 eb.MoveTo(0.0, 0.0)
26 eb.CurveTo(500.0, 500.0, 125.0, 625.0, 0.0, 500.0)
27 eb.CurveTo(-125.0, 625.0, -500.0, 500.0, 0.0, 0.0)
28 heart := eb.PathEnd()
29 heart.SetPathFill(true)
30
31 // Set heart color to red.
32 heart.GetGState().SetFillColorSpace(ColorSpaceCreateDeviceRGB())
33 heart.GetGState().SetFillColor(NewColorPt(1.0, 0.0, 0.0))
34 writer.WriteElement(heart)
35
36 patternDict := writer.End()
37
38 // Initialize pattern dictionary. For details on what each parameter represents please
39 // refer to Table 4.22 (Section '4.6.2 Tiling Patterns') in PDF Reference Manual.
40 patternDict.PutName("Type", "Pattern")
41 patternDict.PutNumber("PatternType", 1)
42
43 // TilingType - Constant spacing.
44 patternDict.PutNumber("TilingType",1)
45
46 // This is a Type1 pattern - A colored tiling pattern.
47 patternDict.PutNumber("PaintType", 1)
48
49 // Set bounding box
50 patternDict.PutRect("BBox", -253.0, 0.0, 253.0, 545.0)
51
52 // Create and set the matrix
53 patternMtx := NewMatrix2D(0.04,0.0,0.0,0.04,0.0,0.0)
54 patternDict.PutMatrix("Matrix", patternMtx)
55
56 // Set the desired horizontal and vertical spacing between pattern cells,
57 // measured in the pattern coordinate system.
58 patternDict.PutNumber("XStep", 1000)
59 patternDict.PutNumber("YStep", 1000)
60
61 return patternDict // finished creating the Pattern resource
62}
63
64
65
66func CreateImageTilingPattern(doc PDFDoc) Obj{
67 writer := NewElementWriter()
68 eb := NewElementBuilder()
69
70 // Create a new pattern content stream - a single bitmap object ----------
71 writer.Begin(doc.GetSDFDoc())
72 image := ImageCreate(doc.GetSDFDoc(), inputPath + "dice.jpg")
73 imgElement := eb.CreateImage(image, 0.0, 0.0, float64(image.GetImageWidth()), float64(image.GetImageHeight()))
74 writer.WritePlacedElement(imgElement)
75 patternDict := writer.End()
76
77 // Initialize pattern dictionary. For details on what each parameter represents please
78 // refer to Table 4.22 (Section '4.6.2 Tiling Patterns') in PDF Reference Manual.
79 patternDict.PutName("Type", "Pattern")
80 patternDict.PutNumber("PatternType",1)
81
82 // TilingType - Constant spacing.
83 patternDict.PutNumber("TilingType", 1)
84
85 // This is a Type1 pattern - A colored tiling pattern.
86 patternDict.PutNumber("PaintType", 1)
87
88 // Set bounding box
89 patternDict.PutRect("BBox", -253.0, 0.0, 253.0, 545.0)
90
91 // Create and set the matrix
92 patternMtx := NewMatrix2D(0.3,0.0,0.0,0.3,0.0,0.0)
93 patternDict.PutMatrix("Matrix", patternMtx)
94
95 // Set the desired horizontal and vertical spacing between pattern cells,
96 // measured in the pattern coordinate system.
97 patternDict.PutNumber("XStep", 300)
98 patternDict.PutNumber("YStep", 300)
99
100 return patternDict // finished creating the Pattern resource
101}
102
103func CreateAxialShading(doc PDFDoc) Obj{
104 // Create a new Shading object ------------
105 patternDict := doc.CreateIndirectDict()
106
107 // Initialize pattern dictionary. For details on what each parameter represents
108 // please refer to Tables 4.30 and 4.26 in PDF Reference Manual
109 patternDict.PutName("Type", "Pattern")
110 patternDict.PutNumber("PatternType", 2) // 2 stands for shading
111
112 shadingDict := patternDict.PutDict("Shading")
113 shadingDict.PutNumber("ShadingType",2)
114 shadingDict.PutName("ColorSpace","DeviceCMYK")
115
116 // pass the coordinates of the axial shading to the output
117 shadingCoords := shadingDict.PutArray("Coords")
118 shadingCoords.PushBackNumber(0)
119 shadingCoords.PushBackNumber(0)
120 shadingCoords.PushBackNumber(612)
121 shadingCoords.PushBackNumber(794)
122
123 // pass the function to the axial shading
124 function := shadingDict.PutDict("Function")
125 C0 := function.PutArray("C0")
126 C0.PushBackNumber(1)
127 C0.PushBackNumber(0)
128 C0.PushBackNumber(0)
129 C0.PushBackNumber(0)
130
131 C1 := function.PutArray("C1")
132 C1.PushBackNumber(0)
133 C1.PushBackNumber(1)
134 C1.PushBackNumber(0)
135 C1.PushBackNumber(0)
136
137 domain := function.PutArray("Domain")
138 domain.PushBackNumber(0)
139 domain.PushBackNumber(1)
140
141 function.PutNumber("FunctionType", 2)
142 function.PutNumber("N", 1)
143
144 return patternDict
145}
146
147func main(){
148 PDFNetInitialize(PDFTronLicense.Key)
149
150 doc := NewPDFDoc()
151 writer := NewElementWriter()
152 eb := NewElementBuilder()
153
154 // The following sample illustrates how to create and use tiling patterns
155 page := doc.PageCreate()
156 writer.Begin(page)
157
158 element := eb.CreateTextBegin(FontCreate(doc.GetSDFDoc(), FontE_times_bold), 1.0)
159 writer.WriteElement(element) // Begin the text block
160
161 data := "G"
162 element = eb.CreateTextRun(data)
163 element.SetTextMatrix(720.0, 0.0, 0.0, 720.0, 20.0, 240.0)
164 gs := element.GetGState()
165 gs.SetTextRenderMode(GStateE_fill_stroke_text)
166 gs.SetLineWidth(4)
167
168 // Set the fill color space to the Pattern color space.
169 gs.SetFillColorSpace(ColorSpaceCreatePattern())
170 gs.SetFillColor(NewPatternColor(CreateTilingPattern(doc)))
171
172 element.SetPathFill(true)
173
174 writer.WriteElement(element)
175 writer.WriteElement(eb.CreateTextEnd()) // Finish the text block
176
177 writer.End() // Save the page
178 doc.PagePushBack(page)
179
180 //-----------------------------------------------
181 // The following sample illustrates how to create and use image tiling pattern
182
183 page = doc.PageCreate()
184 writer.Begin(page)
185
186 eb.Reset()
187 element = eb.CreateRect(0.0, 0.0, 612.0, 794.0)
188
189 // Set the fill color space to the Pattern color space.
190 gs = element.GetGState()
191 gs.SetFillColorSpace(ColorSpaceCreatePattern())
192 gs.SetFillColor(NewPatternColor(CreateImageTilingPattern(doc)))
193 element.SetPathFill(true)
194
195 writer.WriteElement(element)
196
197 writer.End() // Save the page
198 doc.PagePushBack(page)
199
200 //-----------------------------------------------
201
202 // The following sample illustrates how to create and use PDF shadings
203 page = doc.PageCreate()
204 writer.Begin(page)
205
206 eb.Reset()
207 element = eb.CreateRect(0.0, 0.0, 612.0, 794.0)
208
209 // Set the fill color space to the Pattern color space.
210 gs = element.GetGState()
211 gs.SetFillColorSpace(ColorSpaceCreatePattern())
212 gs.SetFillColor(NewPatternColor(CreateAxialShading(doc)))
213 element.SetPathFill(true)
214
215 writer.WriteElement(element)
216 writer.End() // save the page
217 doc.PagePushBack(page)
218 //-----------------------------------------------
219
220 doc.Save(outputPath + "patterns.pdf", uint(SDFDocE_remove_unused))
221 fmt.Println("Done. Result saved in patterns.pdf...")
222
223 doc.Close()
224 PDFNetTerminate()
225}
1//---------------------------------------------------------------------------------------
2// Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
3// Consult legal.txt regarding legal and license information.
4//---------------------------------------------------------------------------------------
5
6#include <PDF/PDFNet.h>
7#include <PDF/PDFDoc.h>
8#include <PDF/Image.h>
9#include <PDF/ElementBuilder.h>
10#include <PDF/ElementWriter.h>
11#include <PDF/ElementReader.h>
12
13#include <iostream>
14#include "../../LicenseKey/CPP/LicenseKey.h"
15
16using namespace std;
17using namespace pdftron;
18using namespace SDF;
19using namespace PDF;
20
21const string input_path = "../../TestFiles/";
22
23Obj CreateTilingPattern(PDFDoc& doc)
24{
25 ElementWriter writer;
26 ElementBuilder eb;
27
28 // Create a new pattern content stream - a heart. ------------
29 writer.Begin(doc);
30 eb.PathBegin();
31 eb.MoveTo(0, 0);
32 eb.CurveTo(500, 500, 125, 625, 0, 500);
33 eb.CurveTo(-125, 625, -500, 500, 0, 0);
34 Element heart = eb.PathEnd();
35 heart.SetPathFill(true);
36
37 // Set heart color to red.
38 heart.GetGState().SetFillColorSpace(ColorSpace::CreateDeviceRGB());
39 heart.GetGState().SetFillColor(ColorPt(1, 0, 0));
40 writer.WriteElement(heart);
41
42 Obj pattern_dict = writer.End();
43
44 // Initialize pattern dictionary. For details on what each parameter represents please
45 // refer to Table 4.22 (Section '4.6.2 Tiling Patterns') in PDF Reference Manual.
46 pattern_dict.PutName("Type", "Pattern");
47 pattern_dict.PutNumber("PatternType", 1);
48
49 // TilingType - Constant spacing.
50 pattern_dict.PutNumber("TilingType",1);
51
52 // This is a Type1 pattern - A colored tiling pattern.
53 pattern_dict.PutNumber("PaintType", 1);
54
55 // Set bounding box
56 pattern_dict.PutRect("BBox", -253, 0, 253, 545);
57
58 // Create and set the matrix
59 Common::Matrix2D pattern_mtx(0.04,0,0,0.04,0,0);
60 pattern_dict.PutMatrix("Matrix", pattern_mtx);
61
62 // Set the desired horizontal and vertical spacing between pattern cells,
63 // measured in the pattern coordinate system.
64 pattern_dict.PutNumber("XStep", 1000);
65 pattern_dict.PutNumber("YStep", 1000);
66
67 return pattern_dict; // finished creating the Pattern resource
68}
69
70Obj CreateImageTilingPattern(PDFDoc& doc)
71{
72 ElementWriter writer;
73 ElementBuilder eb;
74
75 // Create a new pattern content stream - a single bitmap object ----------
76 writer.Begin(doc);
77 Image image = Image::Create(doc, (input_path + "dice.jpg").c_str());
78 Element img_element = eb.CreateImage(image, 0, 0, image.GetImageWidth(), image.GetImageHeight());
79 writer.WritePlacedElement(img_element);
80 Obj pattern_dict = writer.End();
81
82 // Initialize pattern dictionary. For details on what each parameter represents please
83 // refer to Table 4.22 (Section '4.6.2 Tiling Patterns') in PDF Reference Manual.
84 pattern_dict.PutName("Type", "Pattern");
85 pattern_dict.PutNumber("PatternType",1);
86
87 // TilingType - Constant spacing.
88 pattern_dict.PutNumber("TilingType", 1);
89
90 // This is a Type1 pattern - A colored tiling pattern.
91 pattern_dict.PutNumber("PaintType", 1);
92
93 // Set bounding box
94 pattern_dict.PutRect("BBox", -253, 0, 253, 545);
95
96 // Create and set the matrix
97 Common::Matrix2D pattern_mtx(0.3,0,0,0.3,0,0);
98 pattern_dict.PutMatrix("Matrix", pattern_mtx);
99
100 // Set the desired horizontal and vertical spacing between pattern cells,
101 // measured in the pattern coordinate system.
102 pattern_dict.PutNumber("XStep", 300);
103 pattern_dict.PutNumber("YStep", 300);
104
105 return pattern_dict; // finished creating the Pattern resource
106}
107
108Obj CreateAxialShading(PDFDoc& doc)
109{
110 // Create a new Shading object ------------
111 Obj pattern_dict = doc.CreateIndirectDict();
112
113 // Initialize pattern dictionary. For details on what each parameter represents
114 // please refer to Tables 4.30 and 4.26 in PDF Reference Manual
115 pattern_dict.PutName("Type", "Pattern");
116 pattern_dict.PutNumber("PatternType", 2); // 2 stands for shading
117
118 Obj shadingDict = pattern_dict.PutDict("Shading");
119 shadingDict.PutNumber("ShadingType",2);
120 shadingDict.PutName("ColorSpace","DeviceCMYK");
121
122 // pass the coordinates of the axial shading to the output
123 Obj shadingCoords = shadingDict.PutArray("Coords");
124 shadingCoords.PushBackNumber(0);
125 shadingCoords.PushBackNumber(0);
126 shadingCoords.PushBackNumber(612);
127 shadingCoords.PushBackNumber(794);
128
129 // pass the function to the axial shading
130 Obj function = shadingDict.PutDict("Function");
131 Obj C0 = function.PutArray("C0");
132 C0.PushBackNumber(1);
133 C0.PushBackNumber(0);
134 C0.PushBackNumber(0);
135 C0.PushBackNumber(0);
136
137 Obj C1 = function.PutArray("C1");
138 C1.PushBackNumber(0);
139 C1.PushBackNumber(1);
140 C1.PushBackNumber(0);
141 C1.PushBackNumber(0);
142
143 Obj domain = function.PutArray("Domain");
144 domain.PushBackNumber(0);
145 domain.PushBackNumber(1);
146
147 function.PutNumber("FunctionType", 2);
148 function.PutNumber("N", 1);
149
150
151 return pattern_dict;
152}
153
154
155int main(int argc, char *argv[])
156{
157 PDFNet::Initialize(LicenseKey);
158
159 // Relative path to the folder containing test files.
160 string output_path = "../../TestFiles/Output/";
161
162 try
163 {
164 PDFDoc doc;
165 ElementWriter writer;
166 ElementBuilder eb;
167
168 // The following sample illustrates how to create and use tiling patterns
169 Page page = doc.PageCreate();
170 writer.Begin(page);
171
172 Element element = eb.CreateTextBegin(Font::Create(doc, Font::e_times_bold), 1);
173 writer.WriteElement(element); // Begin the text block
174
175 const char* data = "G";
176 element = eb.CreateTextRun((UChar*)data, UInt32(strlen(data)));
177 element.SetTextMatrix(720, 0, 0, 720, 20, 240);
178 GState gs = element.GetGState();
179 gs.SetTextRenderMode(GState::e_fill_stroke_text);
180 gs.SetLineWidth(4);
181
182 // Set the fill color space to the Pattern color space.
183 gs.SetFillColorSpace(ColorSpace::CreatePattern());
184 gs.SetFillColor(CreateTilingPattern(doc));
185
186 writer.WriteElement(element);
187 writer.WriteElement(eb.CreateTextEnd()); // Finish the text block
188
189 writer.End(); // Save the page
190 doc.PagePushBack(page);
191 //-----------------------------------------------
192
193 /// The following sample illustrates how to create and use image tiling pattern
194 page = doc.PageCreate();
195 writer.Begin(page);
196
197 eb.Reset();
198 element = eb.CreateRect(0, 0, 612, 794);
199
200 // Set the fill color space to the Pattern color space.
201 gs = element.GetGState();
202 gs.SetFillColorSpace(ColorSpace::CreatePattern());
203 gs.SetFillColor(CreateImageTilingPattern(doc));
204 element.SetPathFill(true);
205
206 writer.WriteElement(element);
207
208 writer.End(); // Save the page
209 doc.PagePushBack(page);
210 //-----------------------------------------------
211
212 /// The following sample illustrates how to create and use PDF shadings
213 page = doc.PageCreate();
214 writer.Begin(page);
215
216 eb.Reset();
217 element = eb.CreateRect(0, 0, 612, 794);
218
219 // Set the fill color space to the Pattern color space.
220 gs = element.GetGState();
221 gs.SetFillColorSpace(ColorSpace::CreatePattern());
222 gs.SetFillColor(CreateAxialShading(doc));
223 element.SetPathFill(true);
224
225 writer.WriteElement(element);
226
227 writer.End(); // save the page
228 doc.PagePushBack(page);
229 //-----------------------------------------------
230
231 doc.Save((output_path + "patterns.pdf").c_str(), SDFDoc::e_remove_unused, 0);
232 cout << "Done. Result saved in patterns.pdf..." << endl;
233 }
234 catch(Common::Exception& e)
235 {
236 cout << e << endl;
237 }
238 catch(...)
239 {
240 cout << "Unknown Exception" << endl;
241 }
242
243 PDFNet::Terminate();
244}
1//---------------------------------------------------------------------------------------
2// Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
3// Consult legal.txt regarding legal and license information.
4//---------------------------------------------------------------------------------------
5
6import com.pdftron.common.Matrix2D;
7import com.pdftron.common.PDFNetException;
8import com.pdftron.pdf.*;
9import com.pdftron.sdf.Obj;
10import com.pdftron.sdf.SDFDoc;
11
12
13public class PatternTest {
14
15
16 public static final String input_path = "../../TestFiles/";
17
18
19 static Obj CreateTilingPattern(PDFDoc doc) throws PDFNetException {
20 ElementWriter writer = new ElementWriter();
21 ElementBuilder eb = new ElementBuilder();
22
23 // Create a new pattern content stream - a heart. ------------
24 writer.begin(doc);
25 eb.pathBegin();
26 eb.moveTo(0, 0);
27 eb.curveTo(500, 500, 125, 625, 0, 500);
28 eb.curveTo(-125, 625, -500, 500, 0, 0);
29 Element heart = eb.pathEnd();
30 heart.setPathFill(true);
31
32 // Set heart color to red.
33 heart.getGState().setFillColorSpace(ColorSpace.createDeviceRGB());
34 heart.getGState().setFillColor(new ColorPt(1, 0, 0));
35 writer.writeElement(heart);
36
37 Obj pattern_dict = writer.end();
38
39 // Initialize pattern dictionary. For details on what each parameter represents please
40 // refer to Table 4.22 (Section '4.6.2 Tiling Patterns') in PDF Reference Manual.
41 pattern_dict.putName("Type", "Pattern");
42 pattern_dict.putNumber("PatternType", 1);
43
44 // TilingType - Constant spacing.
45 pattern_dict.putNumber("TilingType", 1);
46
47 // This is a Type1 pattern - A colored tiling pattern.
48 pattern_dict.putNumber("PaintType", 1);
49
50 // Set bounding box
51 pattern_dict.putRect("BBox", -253, 0, 253, 545);
52
53 // Create and set the matrix
54 Matrix2D pattern_mtx = new Matrix2D(0.04, 0, 0, 0.04, 0, 0);
55 pattern_dict.putMatrix("Matrix", pattern_mtx);
56
57 // Set the desired horizontal and vertical spacing between pattern cells,
58 // measured in the pattern coordinate system.
59 pattern_dict.putNumber("XStep", 1000);
60 pattern_dict.putNumber("YStep", 1000);
61
62 return pattern_dict; // finished creating the Pattern resource
63 }
64
65 static Obj CreateImageTilingPattern(PDFDoc doc) throws PDFNetException {
66 ElementWriter writer = new ElementWriter();
67 ElementBuilder eb = new ElementBuilder();
68
69 // Create a new pattern content stream - a single bitmap object ----------
70 writer.begin(doc);
71 Image image = Image.create(doc, (input_path + "dice.jpg"));
72 Element img_element = eb.createImage(image, 0, 0, image.getImageWidth(), image.getImageHeight());
73 writer.writePlacedElement(img_element);
74 Obj pattern_dict = writer.end();
75
76 // Initialize pattern dictionary. For details on what each parameter represents please
77 // refer to Table 4.22 (Section '4.6.2 Tiling Patterns') in PDF Reference Manual.
78 pattern_dict.putName("Type", "Pattern");
79 pattern_dict.putNumber("PatternType", 1);
80
81 // TilingType - Constant spacing.
82 pattern_dict.putNumber("TilingType", 1);
83
84 // This is a Type1 pattern - A colored tiling pattern.
85 pattern_dict.putNumber("PaintType", 1);
86
87 // Set bounding box
88 pattern_dict.putRect("BBox", -253, 0, 253, 545);
89
90 // Create and set the matrix
91 Matrix2D pattern_mtx = new Matrix2D(0.3, 0, 0, 0.3, 0, 0);
92 pattern_dict.putMatrix("Matrix", pattern_mtx);
93
94 // Set the desired horizontal and vertical spacing between pattern cells,
95 // measured in the pattern coordinate system.
96 pattern_dict.putNumber("XStep", 300);
97 pattern_dict.putNumber("YStep", 300);
98
99 return pattern_dict; // finished creating the Pattern resource
100 }
101
102 static Obj CreateAxialShading(PDFDoc doc) throws PDFNetException {
103 // Create a new Shading object ------------
104 Obj pattern_dict = doc.createIndirectDict();
105
106 // Initialize pattern dictionary. For details on what each parameter represents
107 // please refer to Tables 4.30 and 4.26 in PDF Reference Manual
108 pattern_dict.putName("Type", "Pattern");
109 pattern_dict.putNumber("PatternType", 2); // 2 stands for shading
110
111 Obj shadingDict = pattern_dict.putDict("Shading");
112 shadingDict.putNumber("ShadingType", 2);
113 shadingDict.putName("ColorSpace", "DeviceCMYK");
114
115 // pass the coordinates of the axial shading to the output
116 Obj shadingCoords = shadingDict.putArray("Coords");
117 shadingCoords.pushBackNumber(0);
118 shadingCoords.pushBackNumber(0);
119 shadingCoords.pushBackNumber(612);
120 shadingCoords.pushBackNumber(794);
121
122 // pass the function to the axial shading
123 Obj function = shadingDict.putDict("Function");
124 Obj C0 = function.putArray("C0");
125 C0.pushBackNumber(1);
126 C0.pushBackNumber(0);
127 C0.pushBackNumber(0);
128 C0.pushBackNumber(0);
129
130 Obj C1 = function.putArray("C1");
131 C1.pushBackNumber(0);
132 C1.pushBackNumber(1);
133 C1.pushBackNumber(0);
134 C1.pushBackNumber(0);
135
136 Obj domain = function.putArray("Domain");
137 domain.pushBackNumber(0);
138 domain.pushBackNumber(1);
139
140 function.putNumber("FunctionType", 2);
141 function.putNumber("N", 1);
142
143
144 return pattern_dict;
145 }
146
147
148 public static void main(String[] args) {
149 PDFNet.initialize(PDFTronLicense.Key());
150
151 // Relative path to the folder containing test files.
152 String output_path = "../../TestFiles/Output/";
153
154 try (PDFDoc doc = new PDFDoc()) {
155 ElementWriter writer = new ElementWriter();
156 ElementBuilder eb = new ElementBuilder();
157
158 // The following sample illustrates how to create and use tiling patterns
159 Page page = doc.pageCreate();
160 writer.begin(page);
161
162 Element element = eb.createTextBegin(Font.create(doc, Font.e_times_bold), 1);
163 writer.writeElement(element); // Begin the text block
164
165 String data = "G";
166 element = eb.createTextRun(data);
167 element.setTextMatrix(720, 0, 0, 720, 20, 240);
168 GState gs = element.getGState();
169 gs.setTextRenderMode(GState.e_fill_stroke_text);
170 gs.setLineWidth(4);
171
172 // Set the fill color space to the Pattern color space.
173 gs.setFillColorSpace(ColorSpace.createPattern());
174 gs.setFillColor(new PatternColor(CreateTilingPattern(doc)));
175
176 writer.writeElement(element);
177 writer.writeElement(eb.createTextEnd()); // Finish the text block
178
179 writer.end(); // Save the page
180 doc.pagePushBack(page);
181 //-----------------------------------------------
182
183 /// The following sample illustrates how to create and use image tiling pattern
184 page = doc.pageCreate();
185 writer.begin(page);
186
187 eb.reset();
188 element = eb.createRect(0, 0, 612, 794);
189
190 // Set the fill color space to the Pattern color space.
191 gs = element.getGState();
192 gs.setFillColorSpace(ColorSpace.createPattern());
193 gs.setFillColor(new PatternColor(CreateImageTilingPattern(doc)));
194 element.setPathFill(true);
195
196 writer.writeElement(element);
197
198 writer.end(); // Save the page
199 doc.pagePushBack(page);
200 //-----------------------------------------------
201
202 /// The following sample illustrates how to create and use PDF shadings
203 page = doc.pageCreate();
204 writer.begin(page);
205
206 eb.reset();
207 element = eb.createRect(0, 0, 612, 794);
208
209 // Set the fill color space to the Pattern color space.
210 gs = element.getGState();
211 gs.setFillColorSpace(ColorSpace.createPattern());
212
213 gs.setFillColor(new PatternColor(CreateAxialShading(doc)));
214 element.setPathFill(true);
215
216 writer.writeElement(element);
217
218 writer.end(); // save the page
219 doc.pagePushBack(page);
220 //-----------------------------------------------
221
222 doc.save(output_path + "patterns.pdf", SDFDoc.SaveMode.REMOVE_UNUSED, null);
223 System.out.println("Done. Result saved in patterns.pdf...");
224 } catch (Exception e) {
225 e.printStackTrace();
226 }
227
228 PDFNet.terminate();
229 }
230}
1//---------------------------------------------------------------------------------------
2// Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
3// Consult legal.txt regarding legal and license information.
4//---------------------------------------------------------------------------------------
5
6const { PDFNet } = require('@pdftron/pdfnet-node');
7const PDFTronLicense = require('../LicenseKey/LicenseKey');
8
9((exports) => {
10 'use strict';
11
12 exports.runPatternTest = () => {
13 const createTilingPattern = async (doc) => {
14 const writer = await PDFNet.ElementWriter.create();
15 const eb = await PDFNet.ElementBuilder.create();
16
17 // Create a new pattern content stream - a heart. ------------
18 writer.begin(doc);
19 eb.pathBegin();
20 eb.moveTo(0, 0);
21 eb.curveTo(500, 500, 125, 625, 0, 500);
22 eb.curveTo(-125, 625, -500, 500, 0, 0);
23 const heart = await eb.pathEnd();
24 heart.setPathFill(true);
25
26 // Set heart color to red.
27 const gstate = await heart.getGState();
28 gstate.setFillColorSpace(await PDFNet.ColorSpace.createDeviceRGB());
29 gstate.setStrokeColorWithColorPt(await PDFNet.ColorPt.init(1, 0, 0));
30 writer.writeElement(heart);
31
32 const patternDict = await writer.end();
33
34 // Initialize pattern dictionary. For details on what each parameter represents please
35 // refer to Table 4.22 (Section '4.6.2 Tiling Patterns') in PDF Reference Manual.
36 patternDict.putName('Type', 'Pattern');
37 patternDict.putNumber('PatternType', 1);
38
39 // TilingType - Constant spacing.
40 patternDict.putNumber('TilingType', 1);
41
42 // This is a Type1 pattern - A colored tiling pattern.
43 patternDict.putNumber('PaintType', 1);
44
45 // Set bounding box
46 patternDict.putRect('BBox', -253, 0, 253, 545);
47
48 // Create and set the matrix
49 const pattern_mtx = await PDFNet.Matrix2D.create(0.04, 0, 0, 0.04, 0, 0);
50 patternDict.putMatrix('Matrix', pattern_mtx);
51
52 // Set the desired horizontal and vertical spacing between pattern cells,
53 // measured in the pattern coordinate system.
54 patternDict.putNumber('XStep', 1000);
55 await patternDict.putNumber('YStep', 1000);
56
57 return patternDict; // finished creating the Pattern resource
58 }
59
60 const createImageTilingPattern = async (doc) => {
61 const writer = await PDFNet.ElementWriter.create();
62 const eb = await PDFNet.ElementBuilder.create();
63
64 // Create a new pattern content stream - a single bitmap object ----------
65 writer.begin(doc);
66 const image = await PDFNet.Image.createFromFile(doc, '../TestFiles/dice.jpg');
67 const imgElement = await eb.createImageScaled(image, 0, 0, await image.getImageWidth(), await image.getImageHeight());
68 writer.writePlacedElement(imgElement);
69
70 const patternDict = await writer.end();
71
72 // Initialize pattern dictionary. For details on what each parameter represents please
73 // refer to Table 4.22 (Section '4.6.2 Tiling Patterns') in PDF Reference Manual.
74 patternDict.putName('Type', 'Pattern');
75 patternDict.putNumber('PatternType', 1);
76
77 // TilingType - Constant spacing.
78 patternDict.putNumber('TilingType', 1);
79
80 // This is a Type1 pattern - A colored tiling pattern.
81 patternDict.putNumber('PaintType', 1);
82
83 // Set bounding box
84 patternDict.putRect('BBox', -253, 0, 253, 545);
85
86 // Create and set the matrix
87 const pattern_mtx = await PDFNet.Matrix2D.create(0.3, 0, 0, 0.3, 0, 0);
88 patternDict.putMatrix('Matrix', pattern_mtx);
89
90 // Set the desired horizontal and vertical spacing between pattern cells,
91 // measured in the pattern coordinate system.
92 patternDict.putNumber('XStep', 300);
93 await patternDict.putNumber('YStep', 300);
94
95 return patternDict; // finished creating the Pattern resource
96 }
97
98 const createAxialShading = async (doc) => {
99 // Create a new Shading object ------------
100 const patternDict = await doc.createIndirectDict();
101
102 // Initialize pattern dictionary. For details on what each parameter represents
103 // please refer to Tables 4.30 and 4.26 in PDF Reference Manual
104 patternDict.putName('Type', 'Pattern');
105 patternDict.putNumber('PatternType', 2); // 2 stands for shading
106
107 const shadingDict = await patternDict.putDict('Shading');
108 shadingDict.putNumber('ShadingType', 2);
109 shadingDict.putName('ColorSpace', 'DeviceCMYK');
110
111 // pass the coordinates of the axial shading to the output
112 const shadingCoords = await shadingDict.putArray('Coords');
113 shadingCoords.pushBackNumber(0);
114 shadingCoords.pushBackNumber(0);
115 shadingCoords.pushBackNumber(612);
116 shadingCoords.pushBackNumber(794);
117
118 // pass the function to the axial shading
119 const func = await shadingDict.putDict('Function');
120 const C0 = await func.putArray('C0');
121 C0.pushBackNumber(1);
122 C0.pushBackNumber(0);
123 C0.pushBackNumber(0);
124 await C0.pushBackNumber(0);
125
126 const C1 = await func.putArray('C1');
127 C1.pushBackNumber(0);
128 C1.pushBackNumber(1);
129 C1.pushBackNumber(0);
130 await C1.pushBackNumber(0);
131
132 const domain = await func.putArray('Domain');
133 domain.pushBackNumber(0);
134 await domain.pushBackNumber(1);
135
136 func.putNumber('FunctionType', 2);
137 await func.putNumber('N', 1);
138
139 return patternDict;
140 }
141
142 const main = async () => {
143 try {
144 const doc = await PDFNet.PDFDoc.create();
145 const writer = await PDFNet.ElementWriter.create();
146 var eb = await PDFNet.ElementBuilder.create();
147
148 // The following sample illustrates how to create and use tiling patterns
149 var page = await doc.pageCreate();
150 writer.beginOnPage(page);
151
152 var element = await eb.createTextBeginWithFont(await PDFNet.Font.createAndEmbed(doc, PDFNet.Font.StandardType1Font.e_times_bold), 1);
153 writer.writeElement(element); // Begin the text block
154
155 const data = 'G';
156 element = await eb.createNewTextRun(data);
157 element.setTextMatrixEntries(720, 0, 0, 720, 20, 240);
158 var gs = await element.getGState();
159 gs.setTextRenderMode(PDFNet.GState.TextRenderingMode.e_fill_stroke_text);
160 gs.setLineWidth(4);
161
162 // Set the fill color space to the Pattern color space.
163 gs.setFillColorSpace(await PDFNet.ColorSpace.createPattern());
164 var patterColor = await PDFNet.PatternColor.create(await createTilingPattern(doc));
165 gs.setFillColorWithPattern(patterColor);
166
167 writer.writeElement(element);
168 writer.writeElement(await eb.createTextEnd()); // Finish the text block
169
170 writer.end(); // Save the page
171 doc.pagePushBack(page);
172 //-----------------------------------------------
173
174 /// The following sample illustrates how to create and use image tiling pattern
175 page = await doc.pageCreate();
176 writer.beginOnPage(page);
177
178 eb.reset();
179 element = await eb.createRect(0, 0, 612, 794);
180
181 // Set the fill color space to the Pattern color space.
182 gs = await element.getGState();
183 gs.setFillColorSpace(await PDFNet.ColorSpace.createPattern());
184 patterColor = await PDFNet.PatternColor.create(await createImageTilingPattern(doc));
185 gs.setFillColorWithPattern(patterColor);
186 element.setPathFill(true);
187
188 writer.writeElement(element);
189
190 await writer.end(); // Save the page
191 doc.pagePushBack(page);
192 //-----------------------------------------------
193
194 /// The following sample illustrates how to create and use PDF shadings
195 page = await doc.pageCreate();
196 writer.beginOnPage(page);
197
198 eb.reset();
199 element = await eb.createRect(0, 0, 612, 794);
200
201 // Set the fill color space to the Pattern color space.
202 gs = await element.getGState();
203 gs.setFillColorSpace(await PDFNet.ColorSpace.createPattern());
204 patterColor = await PDFNet.PatternColor.create(await createAxialShading(doc));
205 gs.setFillColorWithPattern(patterColor);
206 element.setPathFill(true);
207
208 writer.writeElement(element);
209
210 await writer.end(); // Save the page
211 doc.pagePushBack(page);
212 //-----------------------------------------------
213
214 await doc.save('../TestFiles/Output/patterns.pdf', PDFNet.SDFDoc.SaveOptions.e_remove_unused);
215 console.log('Done. Result saved in patterns.pdf...');
216 } catch (err) {
217 console.log(err);
218 }
219 }
220 PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function(error) {
221 console.log('Error: ' + JSON.stringify(error));
222 }).then(function(){ return PDFNet.shutdown(); });
223 };
224 exports.runPatternTest();
225})(exports);
226 // eslint-disable-next-line spaced-comment
227 //# sourceURL=PatternTest.js
1<?php
2//---------------------------------------------------------------------------------------
3// Copyright (c) 2001-2023 by Apryse Software Inc. All Rights Reserved.
4// Consult LICENSE.txt regarding license information.
5//---------------------------------------------------------------------------------------
6if(file_exists("../../../PDFNetC/Lib/PDFNetPHP.php"))
7include("../../../PDFNetC/Lib/PDFNetPHP.php");
8include("../../LicenseKey/PHP/LicenseKey.php");
9
10// Relative path to the folder containing the test files.
11$input_path = getcwd()."/../../TestFiles/";
12$output_path = $input_path."Output/";
13
14function CreateTilingPattern($doc)
15{
16 $writer = new ElementWriter();
17 $builder = new ElementBuilder();
18
19 // Create a new pattern content stream - a heart. ------------
20 $writer->Begin($doc->GetSDFDoc());
21 $builder->PathBegin();
22 $builder->MoveTo(0, 0);
23 $builder->CurveTo(500, 500, 125, 625, 0, 500);
24 $builder->CurveTo(-125, 625, -500, 500, 0, 0);
25 $heart = $builder->PathEnd();
26 $heart->SetPathFill(true);
27
28 // Set heart color to red.
29 $heart->GetGState()->SetFillColorSpace(ColorSpace::CreateDeviceRGB());
30 $heart->GetGState()->SetFillColor(new ColorPt(1.0, 0.0, 0.0));
31 $writer->WriteElement($heart);
32
33 $pattern_dict = $writer->End();
34
35 // Initialize pattern dictionary. For details on what each parameter represents please
36 // refer to Table 4.22 (Section '4.6.2 Tiling Patterns') in PDF Reference Manual.
37 $pattern_dict->PutName("Type", "Pattern");
38 $pattern_dict->PutNumber("PatternType", 1);
39
40 // TilingType - Constant spacing.
41 $pattern_dict->PutNumber("TilingType",1);
42
43 // This is a Type1 pattern - A colored tiling pattern.
44 $pattern_dict->PutNumber("PaintType", 1);
45
46 // Set bounding box
47 $pattern_dict->PutRect("BBox", -253, 0, 253, 545);
48
49 // Create and set the matrix
50 $pattern_mtx = new Matrix2D(0.04,0.0,0.0,0.04,0.0,0.0);
51 $pattern_dict->PutMatrix("Matrix", $pattern_mtx);
52
53 // Set the desired horizontal and vertical spacing between pattern cells,
54 // measured in the pattern coordinate system.
55 $pattern_dict->PutNumber("XStep", 1000);
56 $pattern_dict->PutNumber("YStep", 1000);
57
58 return $pattern_dict; // finished creating the Pattern resource
59}
60
61function CreateImageTilingPattern($doc)
62{
63 $writer = new ElementWriter();
64 $builder = new ElementBuilder();
65
66 // Create a new pattern content stream - a single bitmap object ----------
67 $writer->Begin($doc->GetSDFDoc());
68 global $input_path;
69 $image = Image::Create($doc->GetSDFDoc(), $input_path."dice.jpg");
70 $img_element = $builder->CreateImage($image, 0.0, 0.0, (double)$image->GetImageWidth(), (double)$image->GetImageHeight());
71 $writer->WritePlacedElement($img_element);
72 $pattern_dict = $writer->End();
73
74 // Initialize pattern dictionary. For details on what each parameter represents please
75 // refer to Table 4.22 (Section '4.6.2 Tiling Patterns') in PDF Reference Manual.
76 $pattern_dict->PutName("Type", "Pattern");
77 $pattern_dict->PutNumber("PatternType",1);
78
79 // TilingType - Constant spacing.
80 $pattern_dict->PutNumber("TilingType", 1);
81
82 // This is a Type1 pattern - A colored tiling pattern.
83 $pattern_dict->PutNumber("PaintType", 1);
84
85 // Set bounding box
86 $pattern_dict->PutRect("BBox", -253, 0, 253, 545);
87
88 // Create and set the matrix
89 $pattern_mtx = new Matrix2D(0.3,0.0,0.0,0.3,0.0,0.0);
90 $pattern_dict->PutMatrix("Matrix", $pattern_mtx);
91
92 // Set the desired horizontal and vertical spacing between pattern cells,
93 // measured in the pattern coordinate system.
94 $pattern_dict->PutNumber("XStep", 300);
95 $pattern_dict->PutNumber("YStep", 300);
96
97 return $pattern_dict; // finished creating the Pattern resource
98}
99
100function CreateAxialShading($doc)
101{
102 // Create a new Shading object ------------
103 $pattern_dict = $doc->CreateIndirectDict();
104
105 // Initialize pattern dictionary. For details on what each parameter represents
106 // please refer to Tables 4.30 and 4.26 in PDF Reference Manual
107 $pattern_dict->PutName("Type", "Pattern");
108 $pattern_dict->PutNumber("PatternType", 2); // 2 stands for shading
109
110 $shadingDict = $pattern_dict->PutDict("Shading");
111 $shadingDict->PutNumber("ShadingType",2);
112 $shadingDict->PutName("ColorSpace","DeviceCMYK");
113
114 // pass the coordinates of the axial shading to the output
115 $shadingCoords = $shadingDict->PutArray("Coords");
116 $shadingCoords->PushBackNumber(0);
117 $shadingCoords->PushBackNumber(0);
118 $shadingCoords->PushBackNumber(612);
119 $shadingCoords->PushBackNumber(794);
120
121 // pass the function to the axial shading
122 $function = $shadingDict->PutDict("Function");
123 $C0 = $function->PutArray("C0");
124 $C0->PushBackNumber(1);
125 $C0->PushBackNumber(0);
126 $C0->PushBackNumber(0);
127 $C0->PushBackNumber(0);
128
129 $C1 = $function->PutArray("C1");
130 $C1->PushBackNumber(0);
131 $C1->PushBackNumber(1);
132 $C1->PushBackNumber(0);
133 $C1->PushBackNumber(0);
134
135 $domain = $function->PutArray("Domain");
136 $domain->PushBackNumber(0);
137 $domain->PushBackNumber(1);
138
139 $function->PutNumber("FunctionType", 2);
140 $function->PutNumber("N", 1);
141
142
143 return $pattern_dict;
144}
145
146//---------------------------------------------------------------------------------------
147
148 PDFNet::Initialize($LicenseKey);
149 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.
150
151 $doc = new PDFDoc();
152 $writer = new ElementWriter();
153 $builder = new ElementBuilder();
154
155 // The following sample illustrates how to create and use tiling patterns
156 $page = $doc->PageCreate();
157 $writer->Begin($page);
158
159 $element = $builder->CreateTextBegin(Font::Create($doc->GetSDFDoc(), Font::e_times_bold), 1.0);
160 $writer->WriteElement($element); // Begin the text block
161
162 $data = "G";
163 $element = $builder->CreateTextRun($data);
164 $element->SetTextMatrix(720.0, 0.0, 0.0, 720.0, 20.0, 240.0);
165 $gs = $element->GetGState();
166 $gs->SetTextRenderMode(GState::e_fill_stroke_text);
167 $gs->SetLineWidth(4);
168
169 // Set the fill color space to the Pattern color space.
170 $gs->SetFillColorSpace(ColorSpace::CreatePattern());
171 $gs->SetFillColor(new PatternColor(CreateTilingPattern($doc)));
172
173 $writer->WriteElement($element);
174 $writer->WriteElement($builder->CreateTextEnd()); // Finish the text block
175
176 $writer->End(); // Save the page
177 $doc->PagePushBack($page);
178 //-----------------------------------------------
179
180 /// The following sample illustrates how to create and use image tiling pattern
181 $page = $doc->PageCreate();
182 $writer->Begin($page);
183
184 $builder->Reset();
185 $element = $builder->CreateRect(0, 0, 612, 794);
186
187 // Set the fill color space to the Pattern color space.
188 $gs = $element->GetGState();
189 $gs->SetFillColorSpace(ColorSpace::CreatePattern());
190 $gs->SetFillColor(new PatternColor(CreateImageTilingPattern($doc)));
191 $element->SetPathFill(true);
192
193 $writer->WriteElement($element);
194
195 $writer->End(); // Save the page
196 $doc->PagePushBack($page);
197 //-----------------------------------------------
198
199 /// The following sample illustrates how to create and use PDF shadings
200 $page = $doc->PageCreate();
201 $writer->Begin($page);
202
203 $builder->Reset();
204 $element = $builder->CreateRect(0, 0, 612, 794);
205
206 // Set the fill color space to the Pattern color space.
207 $gs = $element->GetGState();
208 $gs->SetFillColorSpace(ColorSpace::CreatePattern());
209 $gs->SetFillColor(new PatternColor(CreateAxialShading($doc)));
210 $element->SetPathFill(true);
211
212 $writer->WriteElement($element);
213
214 $writer->End(); // save the page
215 $doc->PagePushBack($page);
216 //-----------------------------------------------
217
218 $doc->Save($output_path."patterns.pdf", SDFDoc::e_remove_unused);
219 PDFNet::Terminate();
220 echo "Done. Result saved in patterns.pdf...\n";
221?>
1#---------------------------------------------------------------------------------------
2# Copyright (c) 2001-2023 by Apryse Software Inc. All Rights Reserved.
3# Consult LICENSE.txt regarding license information.
4#---------------------------------------------------------------------------------------
5
6import site
7site.addsitedir("../../../PDFNetC/Lib")
8import sys
9from PDFNetPython import *
10
11sys.path.append("../../LicenseKey/PYTHON")
12from LicenseKey import *
13
14# Relative path to the folder containing the test files.
15input_path = "../../TestFiles/"
16output_path = "../../TestFiles/Output/"
17
18def CreateTilingPattern(doc):
19 writer = ElementWriter()
20 eb = ElementBuilder()
21
22 # Create a new pattern content stream - a heart. ------------
23 writer.Begin(doc.GetSDFDoc())
24 eb.PathBegin()
25 eb.MoveTo(0, 0)
26 eb.CurveTo(500, 500, 125, 625, 0, 500)
27 eb.CurveTo(-125, 625, -500, 500, 0, 0)
28 heart = eb.PathEnd()
29 heart.SetPathFill(True)
30
31 # Set heart color to red.
32 heart.GetGState().SetFillColorSpace(ColorSpace.CreateDeviceRGB())
33 heart.GetGState().SetFillColor(ColorPt(1, 0, 0))
34 writer.WriteElement(heart)
35
36 pattern_dict = writer.End()
37
38 # Initialize pattern dictionary. For details on what each parameter represents please
39 # refer to Table 4.22 (Section '4.6.2 Tiling Patterns') in PDF Reference Manual.
40 pattern_dict.PutName("Type", "Pattern")
41 pattern_dict.PutNumber("PatternType", 1)
42
43 # TilingType - Constant spacing.
44 pattern_dict.PutNumber("TilingType",1)
45
46 # This is a Type1 pattern - A colored tiling pattern.
47 pattern_dict.PutNumber("PaintType", 1)
48
49 # Set bounding box
50 pattern_dict.PutRect("BBox", -253, 0, 253, 545)
51
52 # Create and set the matrix
53 pattern_mtx = Matrix2D(0.04,0,0,0.04,0,0)
54 pattern_dict.PutMatrix("Matrix", pattern_mtx)
55
56 # Set the desired horizontal and vertical spacing between pattern cells,
57 # measured in the pattern coordinate system.
58 pattern_dict.PutNumber("XStep", 1000)
59 pattern_dict.PutNumber("YStep", 1000)
60
61 return pattern_dict # finished creating the Pattern resource
62
63
64
65
66def CreateImageTilingPattern(doc):
67 writer = ElementWriter()
68 eb = ElementBuilder()
69
70 # Create a new pattern content stream - a single bitmap object ----------
71 writer.Begin(doc.GetSDFDoc())
72 image = Image.Create(doc.GetSDFDoc(), input_path + "dice.jpg")
73 img_element = eb.CreateImage(image, 0, 0, image.GetImageWidth(), image.GetImageHeight())
74 writer.WritePlacedElement(img_element)
75 pattern_dict = writer.End()
76
77 # Initialize pattern dictionary. For details on what each parameter represents please
78 # refer to Table 4.22 (Section '4.6.2 Tiling Patterns') in PDF Reference Manual.
79 pattern_dict.PutName("Type", "Pattern")
80 pattern_dict.PutNumber("PatternType",1)
81
82 # TilingType - Constant spacing.
83 pattern_dict.PutNumber("TilingType", 1)
84
85 # This is a Type1 pattern - A colored tiling pattern.
86 pattern_dict.PutNumber("PaintType", 1)
87
88 # Set bounding box
89 pattern_dict.PutRect("BBox", -253, 0, 253, 545)
90
91 # Create and set the matrix
92 pattern_mtx = Matrix2D(0.3,0,0,0.3,0,0)
93 pattern_dict.PutMatrix("Matrix", pattern_mtx)
94
95 # Set the desired horizontal and vertical spacing between pattern cells,
96 # measured in the pattern coordinate system.
97 pattern_dict.PutNumber("XStep", 300)
98 pattern_dict.PutNumber("YStep", 300)
99
100 return pattern_dict # finished creating the Pattern resource
101
102
103def CreateAxialShading(doc):
104 # Create a new Shading object ------------
105 pattern_dict = doc.CreateIndirectDict()
106
107 # Initialize pattern dictionary. For details on what each parameter represents
108 # please refer to Tables 4.30 and 4.26 in PDF Reference Manual
109 pattern_dict.PutName("Type", "Pattern")
110 pattern_dict.PutNumber("PatternType", 2) # 2 stands for shading
111
112 shadingDict = pattern_dict.PutDict("Shading")
113 shadingDict.PutNumber("ShadingType",2)
114 shadingDict.PutName("ColorSpace","DeviceCMYK")
115
116 # pass the coordinates of the axial shading to the output
117 shadingCoords = shadingDict.PutArray("Coords")
118 shadingCoords.PushBackNumber(0)
119 shadingCoords.PushBackNumber(0)
120 shadingCoords.PushBackNumber(612)
121 shadingCoords.PushBackNumber(794)
122
123 # pass the function to the axial shading
124 function = shadingDict.PutDict("Function")
125 C0 = function.PutArray("C0")
126 C0.PushBackNumber(1)
127 C0.PushBackNumber(0)
128 C0.PushBackNumber(0)
129 C0.PushBackNumber(0)
130
131 C1 = function.PutArray("C1")
132 C1.PushBackNumber(0)
133 C1.PushBackNumber(1)
134 C1.PushBackNumber(0)
135 C1.PushBackNumber(0)
136
137 domain = function.PutArray("Domain")
138 domain.PushBackNumber(0)
139 domain.PushBackNumber(1)
140
141 function.PutNumber("FunctionType", 2)
142 function.PutNumber("N", 1)
143
144 return pattern_dict
145
146
147def main():
148 PDFNet.Initialize(LicenseKey)
149
150 doc = PDFDoc()
151 writer = ElementWriter()
152 eb = ElementBuilder()
153
154 # The following sample illustrates how to create and use tiling patterns
155 page = doc.PageCreate()
156 writer.Begin(page)
157
158 element = eb.CreateTextBegin(Font.Create(doc.GetSDFDoc(), Font.e_times_bold), 1)
159 writer.WriteElement(element) # Begin the text block
160
161 data = "G"
162 element = eb.CreateTextRun(data)
163 element.SetTextMatrix(720, 0, 0, 720, 20, 240)
164 gs = element.GetGState()
165 gs.SetTextRenderMode(GState.e_fill_stroke_text)
166 gs.SetLineWidth(4)
167
168 # Set the fill color space to the Pattern color space.
169 gs.SetFillColorSpace(ColorSpace.CreatePattern())
170 gs.SetFillColor(PatternColor(CreateTilingPattern(doc)))
171
172 element.SetPathFill(True)
173
174 writer.WriteElement(element)
175 writer.WriteElement(eb.CreateTextEnd()) # Finish the text block
176
177 writer.End() # Save the page
178 doc.PagePushBack(page)
179
180 #-----------------------------------------------
181 # The following sample illustrates how to create and use image tiling pattern
182
183 page = doc.PageCreate()
184 writer.Begin(page)
185
186 eb.Reset()
187 element = eb.CreateRect(0, 0, 612, 794)
188
189 # Set the fill color space to the Pattern color space.
190 gs = element.GetGState()
191 gs.SetFillColorSpace(ColorSpace.CreatePattern())
192 gs.SetFillColor(PatternColor(CreateImageTilingPattern(doc)))
193 element.SetPathFill(True)
194
195 writer.WriteElement(element)
196
197 writer.End() # Save the page
198 doc.PagePushBack(page)
199
200 #-----------------------------------------------
201
202 # The following sample illustrates how to create and use PDF shadings
203 page = doc.PageCreate()
204 writer.Begin(page)
205
206 eb.Reset()
207 element = eb.CreateRect(0, 0, 612, 794)
208
209 # Set the fill color space to the Pattern color space.
210 gs = element.GetGState()
211 gs.SetFillColorSpace(ColorSpace.CreatePattern())
212 gs.SetFillColor(PatternColor(CreateAxialShading(doc)))
213 element.SetPathFill(True)
214
215 writer.WriteElement(element)
216 writer.End() # save the page
217 doc.PagePushBack(page)
218 #-----------------------------------------------
219
220 doc.Save(output_path + "patterns.pdf", SDFDoc.e_remove_unused)
221 print("Done. Result saved in patterns.pdf...")
222
223 doc.Close()
224 PDFNet.Terminate()
225
226if __name__ == '__main__':
227 main()
1#---------------------------------------------------------------------------------------
2# Copyright (c) 2001-2023 by Apryse Software Inc. All Rights Reserved.
3# Consult LICENSE.txt regarding license information.
4#---------------------------------------------------------------------------------------
5
6require '../../../PDFNetC/Lib/PDFNetRuby'
7include PDFNetRuby
8require '../../LicenseKey/RUBY/LicenseKey'
9
10$stdout.sync = true
11
12# Relative path to the folder containing the test files.
13$input_path = "../../TestFiles/"
14$output_path = "../../TestFiles/Output/"
15
16def CreateTilingPattern(doc)
17 writer = ElementWriter.new
18 eb = ElementBuilder.new
19
20 # Create a new pattern content stream - a heart. ------------
21 writer.Begin(doc.GetSDFDoc)
22 eb.PathBegin
23 eb.MoveTo(0, 0)
24 eb.CurveTo(500, 500, 125, 625, 0, 500)
25 eb.CurveTo(-125, 625, -500, 500, 0, 0)
26 heart = eb.PathEnd
27 heart.SetPathFill(true)
28
29 # Set heart color to red.
30 heart.GetGState.SetFillColorSpace(ColorSpace.CreateDeviceRGB)
31 heart.GetGState.SetFillColor(ColorPt.new(1, 0, 0))
32 writer.WriteElement(heart)
33
34 pattern_dict = writer.End
35
36 # Initialize pattern dictionary. For details on what each parameter represents please
37 # refer to Table 4.22 (Section '4.6.2 Tiling Patterns') in PDF Reference Manual.
38 pattern_dict.PutName("Type", "Pattern")
39 pattern_dict.PutNumber("PatternType", 1)
40
41 # TilingType - Constant spacing.
42 pattern_dict.PutNumber("TilingType",1)
43
44 # This is a Type1 pattern - A colored tiling pattern.
45 pattern_dict.PutNumber("PaintType", 1)
46
47 # Set bounding box
48 pattern_dict.PutRect("BBox", -253, 0, 253, 545)
49
50 # Create and set the matrix
51 pattern_mtx = Matrix2D.new(0.04,0,0,0.04,0,0)
52 pattern_dict.PutMatrix("Matrix", pattern_mtx)
53
54 # Set the desired horizontal and vertical spacing between pattern cells,
55 # measured in the pattern coordinate system.
56 pattern_dict.PutNumber("XStep", 1000)
57 pattern_dict.PutNumber("YStep", 1000)
58
59 return pattern_dict # finished creating the Pattern resource
60end
61
62def CreateImageTilingPattern(doc)
63 writer = ElementWriter.new
64 eb = ElementBuilder.new
65
66 # Create a new pattern content stream - a single bitmap object ----------
67 writer.Begin(doc.GetSDFDoc)
68 image = Image.Create(doc.GetSDFDoc, $input_path + "dice.jpg")
69 img_element = eb.CreateImage(image, 0, 0, image.GetImageWidth, image.GetImageHeight)
70 writer.WritePlacedElement(img_element)
71 pattern_dict = writer.End
72
73 # Initialize pattern dictionary. For details on what each parameter represents please
74 # refer to Table 4.22 (Section '4.6.2 Tiling Patterns') in PDF Reference Manual.
75 pattern_dict.PutName("Type", "Pattern")
76 pattern_dict.PutNumber("PatternType",1)
77
78 # TilingType - Constant spacing.
79 pattern_dict.PutNumber("TilingType", 1)
80
81 # This is a Type1 pattern - A colored tiling pattern.
82 pattern_dict.PutNumber("PaintType", 1)
83
84 # Set bounding box
85 pattern_dict.PutRect("BBox", -253, 0, 253, 545)
86
87 # Create and set the matrix
88 pattern_mtx = Matrix2D.new(0.3,0,0,0.3,0,0)
89 pattern_dict.PutMatrix("Matrix", pattern_mtx)
90
91 # Set the desired horizontal and vertical spacing between pattern cells,
92 # measured in the pattern coordinate system.
93 pattern_dict.PutNumber("XStep", 300)
94 pattern_dict.PutNumber("YStep", 300)
95
96 return pattern_dict # finished creating the Pattern resource
97end
98
99def CreateAxialShading(doc)
100 # Create a new Shading object ------------
101 pattern_dict = doc.CreateIndirectDict
102
103 # Initialize pattern dictionary. For details on what each parameter represents
104 # please refer to Tables 4.30 and 4.26 in PDF Reference Manual
105 pattern_dict.PutName("Type", "Pattern")
106 pattern_dict.PutNumber("PatternType", 2) # 2 stands for shading
107
108 shadingDict = pattern_dict.PutDict("Shading")
109 shadingDict.PutNumber("ShadingType",2)
110 shadingDict.PutName("ColorSpace","DeviceCMYK")
111
112 # pass the coordinates of the axial shading to the output
113 shadingCoords = shadingDict.PutArray("Coords")
114 shadingCoords.PushBackNumber(0)
115 shadingCoords.PushBackNumber(0)
116 shadingCoords.PushBackNumber(612)
117 shadingCoords.PushBackNumber(794)
118
119 # pass the function to the axial shading
120 function = shadingDict.PutDict("Function")
121 c0 = function.PutArray("C0")
122 c0.PushBackNumber(1)
123 c0.PushBackNumber(0)
124 c0.PushBackNumber(0)
125 c0.PushBackNumber(0)
126
127 c1 = function.PutArray("C1")
128 c1.PushBackNumber(0)
129 c1.PushBackNumber(1)
130 c1.PushBackNumber(0)
131 c1.PushBackNumber(0)
132
133 domain = function.PutArray("Domain")
134 domain.PushBackNumber(0)
135 domain.PushBackNumber(1)
136
137 function.PutNumber("FunctionType", 2)
138 function.PutNumber("N", 1)
139
140 return pattern_dict
141end
142
143 PDFNet.Initialize(PDFTronLicense.Key)
144
145 doc = PDFDoc.new
146 writer = ElementWriter.new
147 eb = ElementBuilder.new
148
149 # The following sample illustrates how to create and use tiling patterns
150 page = doc.PageCreate
151 writer.Begin(page)
152
153 element = eb.CreateTextBegin(Font.Create(doc.GetSDFDoc, Font::E_times_bold), 1)
154 writer.WriteElement(element) # Begin the text block
155
156 data = "G"
157 element = eb.CreateTextRun(data)
158 element.SetTextMatrix(720, 0, 0, 720, 20, 240)
159 gs = element.GetGState
160 gs.SetTextRenderMode(GState::E_fill_stroke_text)
161 gs.SetLineWidth(4)
162
163 # Set the fill color space to the Pattern color space.
164 gs.SetFillColorSpace(ColorSpace.CreatePattern)
165 gs.SetFillColor(PatternColor.new(CreateTilingPattern(doc)))
166
167 element.SetPathFill(true)
168
169 writer.WriteElement(element)
170 writer.WriteElement(eb.CreateTextEnd) # Finish the text block
171
172 writer.End # Save the page
173 doc.PagePushBack(page)
174
175 #-----------------------------------------------
176 # The following sample illustrates how to create and use image tiling pattern
177
178 page = doc.PageCreate
179 writer.Begin(page)
180
181 eb.Reset
182 element = eb.CreateRect(0, 0, 612, 794)
183
184 # Set the fill color space to the Pattern color space.
185 gs = element.GetGState
186 gs.SetFillColorSpace(ColorSpace.CreatePattern)
187 gs.SetFillColor(PatternColor.new(CreateImageTilingPattern(doc)))
188 element.SetPathFill(true)
189
190 writer.WriteElement(element)
191
192 writer.End # Save the page
193 doc.PagePushBack(page)
194
195 #-----------------------------------------------
196
197 # The following sample illustrates how to create and use PDF shadings
198 page = doc.PageCreate
199 writer.Begin(page)
200
201 eb.Reset
202 element = eb.CreateRect(0, 0, 612, 794)
203
204 # Set the fill color space to the Pattern color space.
205 gs = element.GetGState
206 gs.SetFillColorSpace(ColorSpace.CreatePattern)
207 gs.SetFillColor(PatternColor.new(CreateAxialShading(doc)))
208 element.SetPathFill(true)
209
210 writer.WriteElement(element)
211 writer.End # save the page
212 doc.PagePushBack(page)
213 #-----------------------------------------------
214
215 doc.Save($output_path + "patterns.pdf", SDFDoc::E_remove_unused)
216 puts "Done. Result saved in patterns.pdf..."
217
218 doc.Close
219 PDFNet.Terminate
1Imports System
2Imports PDFTRON
3Imports PDFTRON.Common
4Imports PDFTRON.Filters
5Imports PDFTRON.SDF
6Imports PDFTRON.PDF
7Module PatternTestVB
8 Dim pdfNetLoader As PDFNetLoader
9 Sub New()
10 pdfNetLoader = pdftron.PDFNetLoader.Instance()
11 End Sub
12
13 ' <summary>
14 ' This example illustrates how to create PDF patterns and shadings.
15 ' </summary>
16 Sub Main()
17
18 Const output_path As String = "../../../../TestFiles/Output/"
19 PDFNet.Initialize(PDFTronLicense.Key)
20 Try
21 Using doc As PDFDoc = New PDFDoc
22 Using writer As ElementWriter = New ElementWriter
23 Using eb As ElementBuilder = New ElementBuilder
24
25 ' The following sample illustrates how to create and use tiling patterns
26 Dim page As Page = doc.PageCreate
27 writer.Begin(page)
28
29 ' Begin the text block
30 Dim element As Element = eb.CreateTextBegin(Font.Create(doc, Font.StandardType1Font.e_times_bold), 1)
31 writer.WriteElement(element)
32
33 element = eb.CreateTextRun("G")
34 element.SetTextMatrix(720, 0, 0, 720, 20, 240)
35 Dim gs As GState = element.GetGState
36 gs.SetTextRenderMode(GState.TextRenderingMode.e_fill_stroke_text)
37 gs.SetLineWidth(4)
38
39 ' Set the fill color space to the Pattern color space.
40 gs.SetFillColorSpace(ColorSpace.CreatePattern)
41 gs.SetFillColor(PatternTest.CreateTilingPattern(doc))
42
43
44 writer.WriteElement(element)
45 writer.WriteElement(eb.CreateTextEnd) ' Finish the text block
46
47 writer.End() ' Save the page
48 doc.PagePushBack(page)
49
50 '-----------------------------------------------
51 ' The following sample illustrates how to create and use image tiling pattern
52 page = doc.PageCreate
53 writer.Begin(page)
54
55 eb.Reset()
56 element = eb.CreateRect(0, 0, 612, 794)
57
58 ' Set the fill color space to the Pattern color space.
59 gs = element.GetGState
60 gs.SetFillColorSpace(ColorSpace.CreatePattern)
61 gs.SetFillColor(PatternTest.CreateImageTilingPattern(doc))
62 element.SetPathFill(True)
63
64 writer.WriteElement(element)
65
66 writer.End() ' save the page
67 doc.PagePushBack(page)
68 '-----------------------------------------------
69
70 ' The following sample illustrates how to create and use PDF shadings
71 page = doc.PageCreate
72 writer.Begin(page)
73
74 eb.Reset()
75 element = eb.CreateRect(0, 0, 612, 794)
76
77 ' Set the fill color space to the Pattern color space.
78 gs = element.GetGState
79 gs.SetFillColorSpace(ColorSpace.CreatePattern)
80 gs.SetFillColor(PatternTest.CreateAxialShading(doc))
81 element.SetPathFill(True)
82
83 writer.WriteElement(element)
84
85 writer.End() ' save the page
86 doc.PagePushBack(page)
87
88 End Using
89 End Using
90
91 doc.Save(output_path + "patterns.pdf", SDFDoc.SaveOptions.e_remove_unused)
92 End Using
93 Console.WriteLine("Done. Result saved in patterns.pdf...")
94 Catch e As PDFNetException
95 Console.WriteLine(e.Message)
96 End Try
97 PDFNet.Terminate()
98 End Sub
99
100 Class PatternTest
101 'Relative path to the folder containing test files.
102 Const input_path As String = "../../../../TestFiles/"
103
104
105
106 Shared Function CreateTilingPattern(ByVal doc As PDFDoc) As PatternColor
107
108 Using writer As ElementWriter = New ElementWriter
109 Using eb As ElementBuilder = New ElementBuilder
110
111 ' Create a new pattern content stream - a heart. ------------
112 writer.Begin(doc.GetSDFDoc)
113 eb.PathBegin()
114 eb.MoveTo(0, 0)
115 eb.CurveTo(500, 500, 125, 625, 0, 500)
116 eb.CurveTo(-125, 625, -500, 500, 0, 0)
117 Dim heart As Element = eb.PathEnd
118 heart.SetPathFill(True)
119
120 ' Set heart color to red.
121 heart.GetGState.SetFillColorSpace(ColorSpace.CreateDeviceRGB)
122 heart.GetGState.SetFillColor(New ColorPt(1, 0, 0))
123 writer.WriteElement(heart)
124
125 Dim pattern_dict As Obj = writer.End()
126
127 ' Initialize pattern dictionary. For details on what each parameter represents please
128 ' refer to Table 4.22 (Section '4.6.2 Tiling Patterns') in PDF Reference Manual.
129 pattern_dict.PutName("Type", "Pattern")
130 pattern_dict.PutNumber("PatternType", 1)
131
132 ' TilingType - Constant spacing.
133 pattern_dict.PutNumber("TilingType", 1)
134
135
136 ' This is a Type1 pattern - A colored tiling pattern.
137 pattern_dict.PutNumber("PaintType", 1)
138
139 ' Set bounding box
140 pattern_dict.PutRect("BBox", -253, 0, 253, 545)
141
142 ' Set the pattern matrix
143 pattern_dict.PutMatrix("Matrix", New Matrix2D(0.04, 0, 0, 0.04, 0, 0))
144
145 'Set the desired horizontal and vertical spacing between pattern cells,
146 ' measured in the pattern coordinate system.
147 pattern_dict.PutNumber("XStep", 1000)
148 pattern_dict.PutNumber("YStep", 1000)
149
150 Return New PatternColor(pattern_dict) ' finished creating the Pattern resource
151 End Using
152 End Using
153 End Function
154
155 Shared Function CreateImageTilingPattern(ByVal doc As PDFDoc) As PatternColor
156
157 Using writer As ElementWriter = New ElementWriter
158 Using eb As ElementBuilder = New ElementBuilder
159
160 ' Create a new pattern content stream - a single bitmap object ----------
161 writer.Begin(doc.GetSDFDoc)
162 Dim img As Image = Image.Create(doc.GetSDFDoc, input_path + "butterfly.png")
163 Dim img_element As Element = eb.CreateImage(img, 0, 0, img.GetImageWidth, img.GetImageHeight)
164 writer.WritePlacedElement(img_element)
165 Dim pattern_dict As Obj = writer.End()
166
167 ' Initialize pattern dictionary. For details on what each parameter represents please
168 ' refer to Table 4.22 (Section '4.6.2 Tiling Patterns') in PDF Reference Manual.
169 pattern_dict.PutName("Type", "Pattern")
170 pattern_dict.PutNumber("PatternType", 1)
171
172 ' TilingType - Constant spacing.
173 pattern_dict.PutNumber("TilingType", 1)
174
175 ' This is a Type1 pattern - A colored tiling pattern.
176 pattern_dict.PutNumber("PaintType", 1)
177
178 ' Set bounding box
179 pattern_dict.PutRect("BBox", -253, 0, 253, 545)
180
181 ' Set the pattern matrix
182 pattern_dict.PutMatrix("Matrix", New Matrix2D(0.3, 0, 0, 0.3, 0, 0))
183
184 ' Set the desired horizontal and vertical spacing between pattern cells,
185 ' measured in the pattern coordinate system.
186 pattern_dict.PutNumber("XStep", 300)
187 pattern_dict.PutNumber("YStep", 300)
188 Return New PatternColor(pattern_dict) ' finished creating the Pattern resource
189 End Using
190 End Using
191 End Function
192
193 Shared Function CreateAxialShading(ByVal doc As PDFDoc) As PatternColor
194
195 ' Create a new Shading object ------------
196 Dim pattern_dict As Obj = doc.CreateIndirectDict()
197
198 ' Initialize pattern dictionary. For details on what each parameter represents
199 ' please refer to Tables 4.30 and 4.26 in PDF Reference Manual
200 pattern_dict.PutName("Type", "Pattern")
201 pattern_dict.PutNumber("PatternType", 2) ' 2 stands for shading
202
203 Dim shadingDict As Obj = pattern_dict.PutDict("Shading")
204 shadingDict.PutNumber("ShadingType", 2)
205 shadingDict.PutName("ColorSpace", "DeviceCMYK")
206
207 ' pass the coordinates of the axial shading to the output
208 Dim shadingCoords As Obj = shadingDict.PutArray("Coords")
209 shadingCoords.PushBackNumber(0)
210 shadingCoords.PushBackNumber(0)
211 shadingCoords.PushBackNumber(612)
212 shadingCoords.PushBackNumber(794)
213
214 ' Set the shading Function for axial shading
215 Dim funct As Obj = shadingDict.PutDict("Function")
216 Dim C0 As Obj = funct.PutArray("C0")
217 C0.PushBackNumber(1)
218 C0.PushBackNumber(0)
219 C0.PushBackNumber(0)
220 C0.PushBackNumber(0)
221
222 Dim C1 As Obj = funct.PutArray("C1")
223 C1.PushBackNumber(0)
224 C1.PushBackNumber(1)
225 C1.PushBackNumber(0)
226 C1.PushBackNumber(0)
227
228 Dim domain As Obj = funct.PutArray("Domain")
229 domain.PushBackNumber(0)
230 domain.PushBackNumber(1)
231
232 funct.PutNumber("FunctionType", 2)
233 funct.PutNumber("N", 1)
234
235 Return New PatternColor(pattern_dict)
236 End Function
237 End Class
238End Module
Did you find this helpful?
Trial setup questions?
Ask experts on DiscordNeed other help?
Contact SupportPricing or product questions?
Contact Sales