Skip to content

Commit 7e87915

Browse files
FEAT: Vertical and horizontal alignment
1 parent 6f90494 commit 7e87915

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

PdfSharpCore/PdfSharpCore.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ PdfSharpCore is a partial port of PdfSharp.Xamarin for .NET Core Additionally Mi
1818
<summary>PdfSharp for .NET Core</summary>
1919
<IsTrimmable>true</IsTrimmable>
2020
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
21+
<Version>1.0.1</Version>
2122
</PropertyGroup>
2223

2324
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">

SampleApp/Program.cs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,43 @@ public static void Main(string[] args)
4040
PdfSharpCore.Drawing.XGraphics? renderer = PdfSharpCore.Drawing.XGraphics.FromPdfPage(pageNewRenderer);
4141

4242
renderer.DrawString(
43-
"Testy Test Test"
43+
"Testy Test Test"
4444
, new PdfSharpCore.Drawing.XFont("Arial", 12)
4545
, PdfSharpCore.Drawing.XBrushes.Black
4646
, new PdfSharpCore.Drawing.XPoint(12, 12)
4747
);
48-
48+
49+
PdfSharpCore.Drawing.Layout.XTextFormatter? formatter = new PdfSharpCore.Drawing.Layout.XTextFormatter(renderer);
50+
51+
var font = new PdfSharpCore.Drawing.XFont("Arial", 12);
52+
var brush = PdfSharpCore.Drawing.XBrushes.Black;
53+
54+
formatter.AllowVerticalOverflow = true;
55+
var originalLayout = new PdfSharpCore.Drawing.XRect(0, 30, 120, 120);
56+
var text = "More and more text boxes to show alignment capabilities"; // " with addipional gline";
57+
var anotherText =
58+
"Text to determine the size of the box I would like to place the text I'm goint to test";
59+
var rect = formatter.GetLayout(
60+
anotherText,
61+
font,
62+
brush,
63+
originalLayout);
64+
rect.Location = new PdfSharpCore.Drawing.XPoint(50, 50);
65+
formatter.AllowVerticalOverflow = false;
66+
67+
// Draw the string
68+
formatter.DrawString(
69+
text,
70+
font,
71+
brush,
72+
rect,
73+
PdfSharpCore.Drawing.XStringFormats.BottomRight
74+
);
75+
76+
// Draw the box to check that the text fits and aligns correctly
77+
var transparentBrush = new PdfSharpCore.Drawing.XSolidBrush(PdfSharpCore.Drawing.XColor.FromArgb(20, brush.Color.R, brush.Color.G, brush.Color.B));
78+
renderer.DrawRectangle(transparentBrush, rect);
79+
4980
SaveDocument(document, outName);
5081

5182
System.Console.WriteLine("Done!");

0 commit comments

Comments
 (0)