Skip to content

Commit 668d423

Browse files
FIX: Code cleanup
1 parent 326e080 commit 668d423

File tree

1 file changed

+29
-17
lines changed

1 file changed

+29
-17
lines changed

SampleApp/Program.cs

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,26 +37,26 @@ public static void Main(string[] args)
3737

3838
const string outName = "test1.pdf";
3939

40-
PdfSharpCore.Pdf.PdfDocument? document = new PdfSharpCore.Pdf.PdfDocument();
40+
PdfDocument? document = new PdfDocument();
4141

42-
PdfSharpCore.Pdf.PdfPage? pageNewRenderer = document.AddPage();
42+
PdfPage? pageNewRenderer = document.AddPage();
4343

44-
PdfSharpCore.Drawing.XGraphics? renderer = PdfSharpCore.Drawing.XGraphics.FromPdfPage(pageNewRenderer);
44+
XGraphics? renderer = XGraphics.FromPdfPage(pageNewRenderer);
4545

4646
renderer.DrawString(
4747
"Testy Test Test"
48-
, new PdfSharpCore.Drawing.XFont("Arial", 12)
49-
, PdfSharpCore.Drawing.XBrushes.Black
50-
, new PdfSharpCore.Drawing.XPoint(12, 12)
48+
, new XFont("Arial", 12)
49+
, XBrushes.Black
50+
, new XPoint(12, 12)
5151
);
5252

53-
PdfSharpCore.Drawing.Layout.XTextFormatter? formatter = new PdfSharpCore.Drawing.Layout.XTextFormatter(renderer);
53+
XTextFormatter? formatter = new XTextFormatter(renderer);
5454

55-
var font = new PdfSharpCore.Drawing.XFont("Arial", 12);
56-
var brush = PdfSharpCore.Drawing.XBrushes.Black;
55+
var font = new XFont("Arial", 12);
56+
var brush = XBrushes.Black;
5757

5858
formatter.AllowVerticalOverflow = true;
59-
var originalLayout = new PdfSharpCore.Drawing.XRect(0, 30, 120, 120);
59+
var originalLayout = new XRect(0, 30, 120, 120);
6060
var text = "More and more text boxes to show alignment capabilities"; // " with addipional gline";
6161
var anotherText =
6262
"Text to determine the size of the box I would like to place the text I'm goint to test";
@@ -65,21 +65,33 @@ public static void Main(string[] args)
6565
font,
6666
brush,
6767
originalLayout);
68-
rect.Location = new PdfSharpCore.Drawing.XPoint(50, 50);
68+
rect.Location = new XPoint(50, 50);
6969
formatter.AllowVerticalOverflow = false;
7070

71-
// Draw the string
71+
// Prepare brush to draw the box that demostrates the text fits and aligns correctly
72+
var translucentBrush = new XSolidBrush(XColor.FromArgb(20, 0, 0, 0));
73+
74+
// Draw the string with default alignments
7275
formatter.DrawString(
7376
text,
7477
font,
7578
brush,
76-
rect,
77-
PdfSharpCore.Drawing.XStringFormats.BottomRight
79+
rect
7880
);
81+
// For checking purposes
82+
renderer.DrawRectangle(translucentBrush, rect);
83+
84+
rect.Location = new XPoint(300, 50);
85+
86+
// Draw the string with custom alignments
87+
formatter.DrawString(text, font, brush, rect, new TextFormatAlignment()
88+
{
89+
Horizontal = XParagraphAlignment.Center,
90+
Vertical = XVerticalAlignment.Middle
91+
});
7992

80-
// Draw the box to check that the text fits and aligns correctly
81-
var transparentBrush = new PdfSharpCore.Drawing.XSolidBrush(PdfSharpCore.Drawing.XColor.FromArgb(20, brush.Color.R, brush.Color.G, brush.Color.B));
82-
renderer.DrawRectangle(transparentBrush, rect);
93+
// For checking purposes
94+
renderer.DrawRectangle(translucentBrush, rect);
8395

8496
SaveDocument(document, outName);
8597

0 commit comments

Comments
 (0)