PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sun May 05, 2024 6:16 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Wed Dec 03, 2008 1:31 pm 
Offline

Joined: Wed Dec 03, 2008 11:59 am
Posts: 6
Hi,

I am using Migradoc to generate a PDF file on the fly. I would like to add an image on the header and leave some space between the image in the header and the first paragraph in the page.

In order to add the image I have the following code:

Code:

public void DefineContentSection(Document document)
{
            Section section = document.AddSection();
            section.PageSetup.OddAndEvenPagesHeaderFooter = true;
            section.PageSetup.StartingNumber = 1;
            section.PageSetup.HeaderDistance = 0;

            HeaderFooter header = section.Headers.Primary;
            header.Format.SpaceAfter = 100;
            header.AddImage(imageURL);

            header = section.Headers.EvenPage;
            header.AddImage(imageURL);
}


But the first paragraph is located in the middle of the picture. What I would like to have is the header with the image, one or two white lines and then the first paragraph.

I guess there must be a way to point out the height of the header or to indicate the location of the first paragraph in the page, but I haven't found it. Do you know how can I do it?

Thank you in advanced!

_________________
MPasc


Top
 Profile  
Reply with quote  
PostPosted: Wed Dec 03, 2008 1:43 pm 
Offline

Joined: Wed Dec 03, 2008 11:59 am
Posts: 6
I got it!

The solution consists of playing with HeaderDistance and TopMargin.

Here is the code:

Code:
public void DefineContentSection(Document document)
{
            Section section = document.AddSection();
            section.PageSetup.OddAndEvenPagesHeaderFooter = true;
            section.PageSetup.StartingNumber = 1;

            //Sets the height of the top margin
            section.PageSetup.TopMargin = 100;
            //Sets the distance between the border of the page and the image
            section.PageSetup.HeaderDistance = 10;

            HeaderFooter header = section.Headers.Primary;
            header.Format.SpaceAfter = 100;
            header.AddImage(imageURL);

            header = section.Headers.EvenPage;
            header.AddImage(imageURL);
}


I hope it can help someone!!

_________________
MPasc


Top
 Profile  
Reply with quote  
PostPosted: Thu Jan 21, 2010 2:23 am 
Offline

Joined: Fri Jan 15, 2010 12:42 am
Posts: 4
you can do the following also instead of changing headerdistance
Code:
        private void DefineHeaderImage()
        {
            Image headerImage = new Image(@"C:\Report_Header_logo.jpg");
            headerImage.LockAspectRatio = true;
            headerImage.Height = new Unit(2.25, UnitType.Centimeter);
            headerImage.RelativeVertical = RelativeVertical.Page;
            headerImage.Top = 0;
            headerImage.RelativeHorizontal = RelativeHorizontal.Page;
            headerImage.Left = 0;
           
            PdfDocumentObj.LastSection.Headers.Primary.Add(headerImage);
        }



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

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 78 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