PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Tue Oct 17, 2017 3:00 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Tue Sep 05, 2017 4:54 pm 
Offline

Joined: Tue Sep 05, 2017 4:42 pm
Posts: 4
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.


Top
 Profile  
Reply with quote  
PostPosted: Tue Sep 05, 2017 5:57 pm 
Offline
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 287
Location: CCAA
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.

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


Top
 Profile  
Reply with quote  
PostPosted: Tue Sep 05, 2017 7:40 pm 
Offline

Joined: Tue Sep 05, 2017 4:42 pm
Posts: 4
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


Top
 Profile  
Reply with quote  
PostPosted: Tue Sep 05, 2017 7:58 pm 
Offline

Joined: Tue Sep 05, 2017 4:42 pm
Posts: 4
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


Top
 Profile  
Reply with quote  
PostPosted: Wed Sep 06, 2017 7:20 am 
Offline
empira Employee
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 2719
Location: Cologne, Germany
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.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Wed Sep 06, 2017 7:23 am 
Offline

Joined: Tue Sep 05, 2017 4:42 pm
Posts: 4
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.

:-)


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

All times are UTC


Who is online

Users browsing this forum: Bing [Bot] and 10 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:  
Powered by phpBB® Forum Software © phpBB Group