PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Mar 28, 2024 4:11 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Thu Jan 08, 2015 6:05 pm 
Offline

Joined: Tue Jan 06, 2015 1:33 pm
Posts: 3
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;


Attachments:
File comment: This is a temp fix I've managed, adding extra spaces to make sure each line has an equal number of spaces
With Workaround (aligned but still overflowing).PNG
With Workaround (aligned but still overflowing).PNG [ 34 KiB | Viewed 7428 times ]
File comment: This shows the problem I'm having
Illustrating the problem.PNG
Illustrating the problem.PNG [ 33.77 KiB | Viewed 7428 times ]
Top
 Profile  
Reply with quote  
PostPosted: Thu Jul 02, 2015 9:26 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3095
Location: Cologne, Germany
Hi!

I'm sorry for the late reply, but your question must have slipped through.

Today I tried your code with MigraDoc 1.32, both GDI+ and WPF builds. I couldn't not replicate the problem.
So maybe the cause of the problem is with something you do not show here.

Please provide an SSCCE for further examination.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 53 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group