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

Issues with border alignment using MigraDoc
https://forum.pdfsharp.net/viewtopic.php?f=2&t=4344
Page 1 of 1

Author:  cp5615 [ Thu May 26, 2022 8:40 pm ]
Post subject:  Issues with border alignment using MigraDoc

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 218 times

Author:  TH-Soft [ Mon May 30, 2022 8:56 am ]
Post subject:  Re: Issues with border alignment using MigraDoc

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.

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