@@ -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