forked from Uzi-Granot/PdfFileWriter
-
Notifications
You must be signed in to change notification settings - Fork 1
3.3 Tiling Pattern Resource
OgreTransporter edited this page Mar 2, 2020
·
1 revision
The DefineTilingPatternResource
method defines background pattern resource for the example area. The pattern is the word “PdfFileWriter” in white over light blue background. The pattern is made of two lines of repeating the key word. The two lines are skewed by half word length.
If you want to find interesting patterns, search the internet for catalogs of companies making floor or wall tiles.
// Define Tiling Pattern Resource
private void DefineTilingPatternResource()
{
// create empty tiling pattern
WaterMark = new PdfTilingPattern(Document);
// the pattern will be PdfFileWriter laied out in brick pattern
string Mark = "PdfFileWriter";
// text width and height for Arial bold size 18 points
double FontSize = 18.0;
double TextWidth = ArialBold.TextWidth(FontSize, Mark);
double TextHeight = ArialBold.LineSpacing(FontSize);
// text base line
double BaseLine = ArialBold.DescentPlusLeading(FontSize);
// the overall pattern box (we add text height value as left and right text margin)
double BoxWidth = TextWidth + 2 * TextHeight;
double BoxHeight = 4 * TextHeight;
WaterMark.SetTileBox(BoxWidth, BoxHeight);
// save graphics state
WaterMark.SaveGraphicsState();
// fill the pattern box with background light blue color
WaterMark.SetColorNonStroking(Color.FromArgb(230, 244, 255));
WaterMark.DrawRectangle(0, 0, BoxWidth, BoxHeight, PaintOp.Fill);
// set fill color for water mark text to white
WaterMark.SetColorNonStroking(Color.White);
// draw PdfFileWriter at the bottom center of the box
WaterMark.DrawText(ArialBold, FontSize, BoxWidth / 2, BaseLine, TextJustify.Center, Mark);
// adjust base line upward by half height
BaseLine += BoxHeight / 2;
// draw the right half of PdfFileWriter shifted left by half width
WaterMark.DrawText(ArialBold, FontSize, 0.0, BaseLine, TextJustify.Center, Mark);
// draw the left half of PdfFileWriter shifted right by half width
WaterMark.DrawText(ArialBold, FontSize, BoxWidth, BaseLine, TextJustify.Center, Mark);
// restore graphics state
WaterMark.RestoreGraphicsState();
return;
}
This page is a copy from https://www.codeproject.com/Articles/570682/PDF-File-Writer-Csharp-Class-Library by Uzi Granot. The article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL). All rights to the texts and source code remain with Uzi Granot.