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

Add header and footer on each page
https://forum.pdfsharp.net/viewtopic.php?f=2&t=3579
Page 1 of 1

Author:  matkarl [ Tue Apr 25, 2017 2:10 pm ]
Post subject:  Add header and footer on each page

Hi!
I am usingPDFsharp-MigraDoc-GDI.

How can I add a header and a footer on each page?

I am generating my pdf with PdfSharp like:

PdfDocument pdfDocument = PdfGenerator.GeneratePdf(html, PageSize.A4);

Then I use it to attach to an email:

byte[] fileContents = null;
using (MemoryStream stream = new MemoryStream())
{
pdfDocument.Save(stream, false);
fileContents = stream.ToArray();
// Send mail
stream.Dispose();
}

As I understand it, I can only add headers with MigraDoc?
But if I generate, using MigraDoc, I can't save to stream...


Much grateful for guidance.. :)

Author:  Thomas Hoevel [ Tue Apr 25, 2017 3:25 pm ]
Post subject:  Re: Add header and footer on each page

Hi!
matkarl wrote:
But if I generate, using MigraDoc, I can't save to stream...
Why not? MigraDoc uses PdfDocument to create the PDF and you can save to a Stream as you show in your code snippet.
Just use the PdfDocument property of the PdfDocumentRenderer class.

matkarl wrote:
I am generating my pdf with PdfSharp like:
PdfDocument pdfDocument = PdfGenerator.GeneratePdf(html, PageSize.A4);
PdfGenerator is not part of PDFsharp. I never used that 3ed party tool and cannot help with its usage.

Author:  matkarl [ Tue May 02, 2017 7:49 am ]
Post subject:  Re: Add header and footer on each page

Thank you for the reply, Thomas!

But I still do not know how to achieve what I want to...

How do I pass the HTML that I want to be rendered in the PDF?

Like I previously did with
Code:
PdfGenerator.GeneratePdf(html, PageSize.A4);


And how do I add headers and footers to the pages?
PdfDocument has no
Code:
AddSection()
method...

Some explaining lines of code would be appreciated! :D

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