PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

XTextFormatter - Right or Center Alignment?
https://forum.pdfsharp.net/viewtopic.php?f=2&t=3570
Page 1 of 1

Author:  RBrNx [ Wed Apr 12, 2017 10:10 am ]
Post subject:  XTextFormatter - Right or Center Alignment?

Hi there,

In my project using PDFSharp 1.50 Beta 3 I am using the
Code:
XGraphics DrawString()
method to draw strings onto the PDFs that I am creating, however I noticed that this method does not play nicely with new lines (\n). After some googling I found out that using the XTextFormatter DrawString() method would correctly parse the newline characters, which is great.

I did notice that the
Quote:
XTextFormatter DrawString()
method only supports TopLeft Formatting at this moment in time, is there any workaround for getting Right or Center alignment with newlines?

Thanks, RBrNx

Author:  TH-Soft [ Wed Apr 12, 2017 7:28 pm ]
Post subject:  Re: XTextFormatter - Right or Center Alignment?

Hi!

Did you try the Alignment property of XtextFormatter?
See also:
http://pdfsharp.net/wiki/TextLayout-sample.ashx

Author:  RBrNx [ Thu Apr 13, 2017 8:25 am ]
Post subject:  Re: XTextFormatter - Right or Center Alignment?

TH-Soft wrote:
Hi!

Did you try the Alignment property of XtextFormatter?
See also:
http://pdfsharp.net/wiki/TextLayout-sample.ashx


Hi there, yes that was the first thing I tried, unfortunately when you use anything other than

Code:
XStringFormats.TopLeft


It throws the exception
Code:
Only TopLeft alignment is currently implemented.


I was wondering if anyone had implemented the other alignments or knew of an easy way to do it?

Author:  RBrNx [ Thu Apr 13, 2017 9:43 am ]
Post subject:  Re: XTextFormatter - Right or Center Alignment?

TH-Soft wrote:
Hi!

Did you try the Alignment property of XtextFormatter?
See also:
http://pdfsharp.net/wiki/TextLayout-sample.ashx


Apologies I misread your post! Keeping the XStringFormats value as TopLeft, I was also able to set the XTextFormatter.Alignment to Left/Right/Center and this worked fantastic!

Thanks for your help

RBrNx

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/