PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Tue Mar 19, 2024 11:46 am

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 May 26, 2022 8:40 pm 
Offline

Joined: Thu May 26, 2022 8:15 pm
Posts: 1
Hello.

I am very new to both PDFsharp as well as MigraDoc. I have recently been working on a project generating pdf forms, and a coworker of mine recommended MigraDoc. The issue that I have been dealing with the last day or two is an alignment issue with a border. The purpose of the border(s) is to to act as a wall separating two different tables, I assume just for aesthetic reasons. For some reason, the borders (and only these borders) are all shifted slightly to the right, making the whole thing look somewhat goofy. I have attached a picture of the code that I am using for the borders, as well as a picture of the output I have been getting. I guess I will also include the code in this message.
Note: the following code is the same format that I have been using for all of the borders, they all just use different names for the paragraph and border objects.
Code:
            //Border #1
            double height = (1.0);
            MigraDoc.DocumentObjectModel.Color hrFillColor = new MigraDoc.DocumentObjectModel.Color(0, 0, 0);       //.Color(250, 250, 250, 250);
            Color hrBorderColor = new Color(0, 0, 0);

            Paragraph p = mainSection.AddParagraph();
            Border newBorder = new Border {Style = BorderStyle.Single, Color = hrBorderColor};

            p.Format = new ParagraphFormat
            {
                Alignment = ParagraphAlignment.Center,
                Font = new Font("Courier New", new Unit(height)),
                Shading = new Shading { Visible = true, Color = hrFillColor },
                SpaceAfter = 0,
                Borders = new Borders
                {
                    Bottom = newBorder,
                    Left = newBorder.Clone(),
                    Right = newBorder.Clone(),
                    Top = newBorder.Clone()
                }
            };


I have tried multiple different things, including changing the alignment to Left and going back through to make sure all the paragraph alignments prior were set to Center, and that the mainsection's alignment is set to Center. I have also tried my best to look through this forum pretty carefully, and I just can not find a solution. Please help me lol, once again I am only a day or two into learning this stuff and I apologize if my question is silly or if my code is bad.


Attachments:
Content.zip [164.8 KiB]
Downloaded 168 times
Top
 Profile  
Reply with quote  
PostPosted: Mon May 30, 2022 8:56 am 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 906
Location: CCAA
Hi!
cp5615 wrote:
For some reason, the borders (and only these borders) are all shifted slightly to the right, making the whole thing look somewhat goofy.
I didn't look at your ZIP file yet.

FYI: Tables are by default shifted to the left so that text inside tables aligns with text outside table.
Therefore table borders will be shifted to the left while paragraph borders are at the normal position.

You can set the indentation of tables to 0. Borders should then be aligned, but text inside tables will be indented.

Instead of creating a dummy paragraph for the border, you can create a dummy table just for the border, thus avoiding the alignment problem. The table only needs a single cell and can have a minimal height.

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


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 42 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:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group