0

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?

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Mark Rabjohn
  • 1,643
  • 14
  • 30

1 Answers1

0

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.

  • Just curious, looking at the code for a bit, the NeedsEmptyPage and InsertEmptyPage are where the magic happens, but how hard would it be to implement an "InsertEmptySectionPage" that adds the alignment page but with the correct header and footer config. Perhaps append an additional pagebreak to the previous section and then have TopDownFormatter render just the pagebreak element, does that seem feasible? – Mark Rabjohn Mar 14 '13 at 22:30