leora leora - 1 year ago 127
C# Question

Is there any way to have a different color page backcolor when using PDFsharp / Migradoc?

I am generating a PDF file from a C# app using MigraDoc /PDFsharp I am trying to figure out if I can have the entire page color black (instead of the default white). I see how I can change styles for font, etc but I don't see where I can change the background color of the entire page.

Please let me know if this is possible. I see that I can have background images (so I guess I can create a solid color image but figured there would be an easier way. I can't find anything after lots of googling)

Answer Source

I can think of two ways I'd consider worth trying.

One way is using PDFsharp to call AddPage() for each new page and draw a rectangle in the color you like before calling RenderPage() to draw the MigraDoc content.

Here's a sample that draws nine MigraDoc pages in thumbnail size on a single PDFsharp page:
You would call AddPage/RenderPage to draw each page in full size.

Another way that uses MigraDoc only: add a TextFrame() to the page header and set the FillFormat of that TextFrame to your background color. Set the TextFrame to fill the whole page.
This should work and it requires only MigraDoc (no PDFsharp code required).

I think I'd use the first method.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download