Components for Developers
© 2000-2012, Two Pilots

PDF Library Download Features Manual Tutorials FAQ Pricing HTML2PDF-X Pilot History In the Lab

PDF Creator Pilot documentation

Download CHM version of this manual.
Patterns
AddColoredPattern

See Also Example
Collapse All

This method creates a colored pattern in a PDF document and returns its number. A colored pattern is a pattern whose color is self-contained.

Syntax

LONG AddColoredPattern (
PatternTilingType tilingType
)
Parameters
tilingType
Pattern tiling type that controls adjustments to the spacing of tiles relative to the device pixel grid

Return value
Number of the pattern

Remarks

The return value is an identifier in the document's patterns collection and can be used in the SetPattern and SwitchToPattern methods.

Example

Filling Shapes with a Pattern

Delphi
[copy to clipboard]
{ PDF object is supposed to be created }
pattern := PDF.AddColoredPattern(pttConstantSpacing);

{ compose a pattern }
PDF.SwitchToPattern(pattern);
PDF.PageHeight := 10;
PDF.PageWidth := 10;
PDF.SetColorSpaceType(cstDefaultRGB);
PDF.SetColorFill(1, 0, 0, 0); { we may use color, as we compose colored pattern }
PDF.DrawRectangle(0, 0, 5, 5, 0);
PDF.Fill;
PDF.SetColorFill(0, 1, 0, 0);
PDF.DrawRectangle(5, 0, 5, 5, 0);
PDF.Fill;
PDF.SetColorFill(0, 0, 1, 0);
PDF.DrawRectangle(0, 5, 5, 5, 0);
PDF.Fill;
PDF.SetColorFill(1, 0.5f, 0, 0);
PDF.DrawRectangle(5, 5, 5, 5, 0);
PDF.Fill;
PDF.SwitchToCurrentPage;

PDF.SetPattern(pattern);
{ now all paths will be filled with created pattern }

helvetica := PDF.AddBuiltInFont(bfHelveticaBoldOblique, false, false);
PDF.UseFont(helvetica, 58);
PDF.ShowTextAt(50, 50, 'Pattern-filled text');
PDF.DrawCircle(200, 200, 80);
PDF.FillAndStroke;
PDF.SaveToFile('test.pdf', true);
C/C++
[copy to clipboard]
// PDF object is supposed to be created
long pattern = PDF->AddColoredPattern(pttConstantSpacing);

// compose a pattern
PDF->SwitchToPattern(pattern);
PDF->PageHeight = 10;
PDF->PageWidth = 10;
PDF->SetColorSpaceType(cstDefaultRGB);
PDF->SetColorFill(1, 0, 0, 0); //we may use color, as we compose colored pattern
PDF->DrawRectangle(0, 0, 5, 5, 0);
PDF->Fill();
PDF->SetColorFill(0, 1, 0, 0);
PDF->DrawRectangle(5, 0, 5, 5, 0);
PDF->Fill();
PDF->SetColorFill(0, 0, 1, 0);
PDF->DrawRectangle(0, 5, 5, 5, 0);
PDF->Fill();
PDF->SetColorFill(1, 0.5f, 0, 0);
PDF->DrawRectangle(5, 5, 5, 5, 0);
PDF->Fill();
PDF->SwitchToCurrentPage();

PDF->SetPattern(pattern);
// now all paths will be filled with created pattern

long helvetica = PDF->AddBuiltInFont(bfHelveticaBoldOblique, false, false);
PDF->UseFont(helvetica, 58);
PDF->ShowTextAt(50, 50, "Pattern-filled text");
PDF->DrawCircle(200, 200, 80);
PDF->FillAndStroke();
PDF->SaveToFile("test.pdf", true);
C#
[copy to clipboard]
// PDF object is supposed to be created
long pattern = PDF.AddColoredPattern(PatternTilingType.pttConstantSpacing);

// compose a pattern
PDF.SwitchToPattern(pattern);
PDF.PageHeight = 10;
PDF.PageWidth = 10;
PDF.SetColorSpaceType(ColorSpaceType.cstDefaultRGB);
PDF.SetColorFill(1, 0, 0, 0); //we may use color, as we compose colored pattern
PDF.DrawRectangle(0, 0, 5, 5, 0);
PDF.Fill();
PDF.SetColorFill(0, 1, 0, 0);
PDF.DrawRectangle(5, 0, 5, 5, 0);
PDF.Fill();
PDF.SetColorFill(0, 0, 1, 0);
PDF.DrawRectangle(0, 5, 5, 5, 0);
PDF.Fill();
PDF.SetColorFill(1, 0.5f, 0, 0);
PDF.DrawRectangle(5, 5, 5, 5, 0);
PDF.Fill();
PDF.SwitchToCurrentPage();

PDF.SetPattern(pattern);
// now all paths will be filled with created pattern

long helvetica = PDF.AddBuiltInFont(BuiltInFont.bfHelveticaBoldOblique, false, false);
PDF.UseFont(helvetica, 58);
PDF.ShowTextAt(50, 50, "Pattern-filled text");
PDF.DrawCircle(200, 200, 80);
PDF.FillAndStroke();
PDF.SaveToFile("test.pdf", true);
Visual Basic
[copy to clipboard]
' PDF object is supposed to be created
pattern = PDF.AddColoredPattern(1) 'pttConstantSpacing

' compose a pattern
PDF.SwitchToPattern pattern
PDF.PageHeight = 10
PDF.PageWidth = 10
PDF.SetColorSpaceType 1 'cstDefaultRGB
PDF.SetColorFill 1, 0, 0, 0 ' will may use color, as we compose colored pattern
PDF.DrawRectangle 0, 0, 5, 5, 0
PDF.Fill
PDF.SetColorFill 0, 1, 0, 0
PDF.DrawRectangle 5, 0, 5, 5, 0
PDF.Fill
PDF.SetColorFill 0, 0, 1, 0
PDF.DrawRectangle 0, 5, 5, 5, 0
PDF.Fill
PDF.SetColorFill 1, .5, 0, 0
PDF.DrawRectangle 5, 5, 5, 5, 0
PDF.Fill
PDF.SwitchToCurrentPage

PDF.SetPattern pattern
' now all paths will be filled with created pattern

helvetica = PDF.AddBuiltInFont(9, false, false) 'bfHelveticaBoldOblique
PDF.UseFont helvetica, 58
PDF.ShowTextAt 50, 50, "Pattern-filled text"
PDF.DrawCircle 200, 200, 80
PDF.FillAndStroke
PDF.SaveToFile "test.pdf", true

See Also

PDF Library Download Features Manual Tutorials FAQ Pricing HTML2PDF-X Pilot History In the Lab

 

 

PDF Library | Virtual Printer | Converters to PDF

Support | Blog | Forum | Contacts

© 2000-2012, Two Pilots