6

I'm using PDFSharp/Migradoc to generate PDFs from my web application, and I've managed to get a background image working for the first page of the document.

I start by creating a single section in the document, then rendering an image to this. I then write the document content to paragraph objects inside the same section object.

However, I need to show a different background image for all subsequent pages in the document.

Is this possible? If so, how can I do it?

Answer: In the interest of providing a complete answer, here is the basic code that will get this working:

Section section = this.document.AddSection();

section.PageSetup.DifferentFirstPageHeaderFooter = true;
section.PageSetup.OddAndEvenPagesHeaderFooter = false;

Image firstPageImage = section.Headers.FirstPage.AddImage("firstPage.jpg");
// ...configure image...
Image otherPageImage = section.Headers.Primary.AddImage("everyOtherPage.jpg");
// ...configure image...
johnnyRose
  • 7,310
  • 17
  • 40
  • 61
Robert
  • 1,487
  • 1
  • 14
  • 26

1 Answers1

1

If you draw the background image as part of the Header or Footer, then you can use the default Header with the "normal" picture and a different first page header for the first page.

  • Hi; thanks for the answer. Can you confirm that if I render the image to the header, then it will take up the entire page? – Robert Jan 24 '11 at 19:38
  • Nevermind - I managed to get it working. I posted the code so others might learn from it. – Robert Jan 24 '11 at 20:10