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

Newbie - overlapping text
https://forum.pdfsharp.net/viewtopic.php?f=2&t=3655
Page 1 of 1

Author:  NickL [ Tue Sep 05, 2017 4:54 pm ]
Post subject:  Newbie - overlapping text

Hi, I must be missing something really obvious, so apologies in advance. I am trying to add a header and a footer to my page, and then some text.

First I do some setup:
Code:
            _document = new MigraDoc.DocumentObjectModel.Document();

            // Add a single section and set the page size and margin
            _section = _document.AddSection();
            _section.PageSetup.PageFormat = PageFormat.A4;
            _section.PageSetup.TopMargin = Unit.FromCentimeter(1.5);
            _section.PageSetup.BottomMargin = Unit.FromCentimeter(1.5);

Header and footer are along these lines:

Code:
            var location = _section.Headers.FirstPage;
            // Add a paragraph, set the alignment and add the logo
            var headerLogo = location.AddParagraph();
            headerLogo.Format.Alignment = ParagraphAlignment.Center;
            headerLogo.Format.Font.Name = "Century Gothic";
            headerLogo.Format.Font.Size = 9;


Then the text is like this:
Code:
            var a1 = _section.AddParagraph();
            a1.AddText("Address will go here");


So a very simple example. What I am finding is that the "Address will go here" is at the very top of the page, it isn't pushed down below the header. I have tried _section.Elements.AddParagraph too, with no difference.

Also, if I add multiple paragraphs, the text goes all over the footer, rather than a page break being inserted.

As I said, I must be doing something stupid. Pointers welcome. Thanks.

Author:  TH-Soft [ Tue Sep 05, 2017 5:57 pm ]
Post subject:  Re: Newbie - overlapping text

Hi!

Your header must be small enough to fit into the top border. Same for footer and bottom border.
1.5 cm obviously are not enough in your case, so increase top and bottom margins as needed.

Author:  NickL [ Tue Sep 05, 2017 7:40 pm ]
Post subject:  Re: Newbie - overlapping text

TH-Soft wrote:
increase top and bottom margins as needed.

Thank you. It hadn't crossed my mind that the header and footer are effectively inside the margin.

Obvious now!

Thanks again,

Nick

Author:  NickL [ Tue Sep 05, 2017 7:58 pm ]
Post subject:  Re: Newbie - overlapping text

FOUND AN ANSWER HERE - IGNORE ME!

Sorry folks, a follow up question.....

I have now increased the top and bottom margin settings so that they are larger than the depth of the header and footer on the first page. The main text is now where I'd expect it to be, in between the header/footer and not overlapping.

The problem occurs on the second page. There, the header is much smaller. I have different first page headers set up - and that is working fine, the primary header appears on page 2 as expected. The problem is that the same margin applies to page 2, even though the header is much shorter - so there's a big gap between the header and the text.

I'm wondering whether I need to have the second page as a separate section, but that rather defeats the object of being able to specify different headers for the first page.

Thanks,

Nick

Author:  Thomas Hoevel [ Wed Sep 06, 2017 7:20 am ]
Post subject:  Re: Newbie - overlapping text

Hi!

My approach to that problem with respect to header: set top margin for the second page and start the first page with an empty paragraph large enough to prevent overlapping.

This approach does not work with a large first page footer.

Author:  NickL [ Wed Sep 06, 2017 7:23 am ]
Post subject:  Re: Newbie - overlapping text

Thanks Thomas, it was your suggestion that I found just after I'd posted (and went back and added a link to help others find it).

Fortunately, I only have the issue with the header, not the footer. It is working fine now.

Thanks for all the support and guidance.

:-)

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