I'm using the latest non pre release version of PDFSharp / Migradoc, downloaded via nuget into Visual Studio 2013 community edition
A weird one - The problem is shown in the screenshots, but fundamentally is this:
When I have several lines of text in a paragraph (lines are separated by line breaks) that is right aligned, the text on each line seems to overflow the border of the paragraph by a factor of half a horizontal character width per space character in the string on that line.
The problem does not occur for left aligned paragraphs with line breaks, only right aligned.
I.E a right aligned paragraph containing three lines like this
One
One Two
One Two Three
Will be perfectly aligned to the paragraph border on the first line, out by half a character width on the second line, and a whole character with on the third line, etc!
Can you tell me if I'm doing something fundamentally wrong here or if this is a bug? I would like the right aligned text to perfectly align.
I have a workaround of adding spaces to every string so that each string has an equal number of space characters, but this is not ideal obviously!
It doesn't seem to be a problem on left aligned paragraphs.
Thanks for any help you can give.
Here's a snippet of my code to give you an idea - I've included with the workaround and without, and also the styles and frames I've defined at the bottom, just in case there's an issue there (although removing the styles and just calling AddText() the issue still remained for me).
Code:
without workaround (I have made the data anonymous)
Code:
var paragraph = _businessAddressFrame.AddParagraph();
paragraph.Format.Borders.Style = BorderStyle.Dot;
paragraph.Format.Alignment = ParagraphAlignment.Right;
paragraph.Style = "AddressHeader";
paragraph.AddLineBreak();
paragraph.AddFormattedText("A fake Address Header", "AddressHeader");
paragraph.AddLineBreak();
paragraph.AddFormattedText("1st Floor", "AddressNormal");
paragraph.AddLineBreak();
paragraph.AddFormattedText("Fake House", "AddressNormal");
paragraph.AddLineBreak();
paragraph.AddFormattedText("11-13 FakeStreet", "AddressNormal");
paragraph.AddLineBreak();
paragraph.AddFormattedText("Fake Town", "AddressNormal");
paragraph.AddLineBreak();
paragraph.AddFormattedText("XXXX XXX", "AddressNormal");
paragraph.AddLineBreak();
paragraph.AddFormattedText("Telephone", "AddressHeader");
paragraph.AddLineBreak();
paragraph.AddFormattedText("00000 555555", "AddressNormal");
paragraph.AddLineBreak();
paragraph.AddFormattedText("Facsimile", "AddressHeader");
paragraph.AddLineBreak();
paragraph.AddFormattedText("00000 777777", "AddressNormal");
paragraph.AddLineBreak();
paragraph.AddFormattedText("Email", "AddressHeader");
paragraph.AddLineBreak();
paragraph.AddFormattedText("info@fakeemailaddress.co.uk", "AddressNormal");
with workaround (I have made the data anonymous)
Code:
var paragraph = _businessAddressFrame.AddParagraph();
paragraph.Format.Borders.Style = BorderStyle.Dot;
paragraph.Format.Alignment = ParagraphAlignment.Right;
paragraph.Style = "AddressHeader";
paragraph.AddLineBreak();
paragraph.AddFormattedText("A fake Address Header", "AddressHeader");
paragraph.AddLineBreak(); paragraph.AddSpace(2);
paragraph.AddFormattedText("1st Floor", "AddressNormal");
paragraph.AddLineBreak(); paragraph.AddSpace(2);
paragraph.AddFormattedText("Fake House", "AddressNormal");
paragraph.AddLineBreak(); paragraph.AddSpace(2);
paragraph.AddFormattedText("11-13 FakeStreet", "AddressNormal");
paragraph.AddLineBreak(); paragraph.AddSpace(2);
paragraph.AddFormattedText("Fake Town", "AddressNormal");
paragraph.AddLineBreak(); paragraph.AddSpace(2);
paragraph.AddFormattedText("XXXX XXX", "AddressNormal");
paragraph.AddLineBreak(); paragraph.AddSpace(3);
paragraph.AddFormattedText("Telephone", "AddressHeader");
paragraph.AddLineBreak(); paragraph.AddSpace(2);
paragraph.AddFormattedText("00000 555555", "AddressNormal");
paragraph.AddLineBreak(); paragraph.AddSpace(3);
paragraph.AddFormattedText("Facsimile", "AddressHeader");
paragraph.AddLineBreak(); paragraph.AddSpace(2);
paragraph.AddFormattedText("00000 777777", "AddressNormal");
paragraph.AddLineBreak(); paragraph.AddSpace(3);
paragraph.AddFormattedText("Email", "AddressHeader");
paragraph.AddLineBreak(); paragraph.AddSpace(3);
paragraph.AddFormattedText("info@fakeemailaddress.co.uk", "AddressNormal");
The _businessAddressFrame is created like this, so seems to have plenty of width:
Code:
private void CreateBusinessAddressFrame(Section section)
{
_businessAddressFrame = section.AddTextFrame();
_businessAddressFrame.Height = "5.5cm";
_businessAddressFrame.Width = "8cm";
_businessAddressFrame.RelativeHorizontal = RelativeHorizontal.Margin;
_businessAddressFrame.RelativeVertical = RelativeVertical.Margin;
_businessAddressFrame.Top = "2.0cm";
_businessAddressFrame.MarginRight = "0.0cm";
_businessAddressFrame.Left = ShapePosition.Right;
}
and the formatted text styles are like this
Code:
//Create a new style called address header based on normal
style = _document.Styles.AddStyle("AddressHeader", "Normal");
style.Font.Color = new Color(14, 118, 188);
style.Font.Bold = true;
//Create a new style called address header based on normal
style = _document.Styles.AddStyle("AddressNormal", "Normal");
style.Font.Color = Colors.Black;