Blank Pages in MigraDoc due to section.PageSetup.SectionStart = BreakType.BreakOdd/EvenPage

StackOverflow https://stackoverflow.com/questions/15405601

  •  23-03-2022
  •  | 
  •  

Question

I'm generating a price guide from a database - lots of the functionality required has been worked out, but the system is generating blank pages, which I believe is correct, but I wonder if there is a workaround for it.

Put simply, I have used section.PageSetup.SectionStart to ensure that a new section starts on a right hand page. The left hand page when skipped in this fashion is blank. The problem is that the previous section has a header for it's left hand pages, the new section has a header for it's left hand pages. The headers contain the pretty backgrounds.

Either one background or the other would be better than a blank page, but the blank page is acceptable - I'm just looking for perfection :)

Can the skipped pages have headers/backgrounds from either section?

Was it helpful?

Solution

Can the skipped pages have headers/backgrounds from either section?

No, AFAIK you cannot have this automatically.

In our application, we use a different way of adding backgrounds: every section gets a tag that indicates which background has to be used. We render the pages in a loop of our own, adding the backgrounds before the page is rendered.

See the Mix MigraDoc and PDFsharp sample on using RenderPage:
http://www.pdfsharp.net/wiki/MixMigraDocAndPdfSharp-sample.ashx

Here's a code snippet:

// Check tags of all pages
for (int idx = 0; idx < pageCount; idx++)
{
  DocumentObject[] docObjects = docRenderer.GetDocumentObjectsFromPage(idx + 1);
  if (docObjects != null && docObjects.Length > 0)
  {
    Section section = docObjects[0].Section;
    DocumentSectionTag sectionTag = null;
    if (section != null)
      sectionTag = section.Tag as DocumentSectionTag;
    if (sectionTag != null && sectionTag.Name != sectionName)
    { 
      // Your code to handle the background information goes here

DocumentSectionTag is a class we defined to transport the information we need. Our page backgrounds are pages from a PDF file, so we only need the page number.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top