Write on Auto Generated Extra Page Created after a Section Break (Next Odd page) in Word Document using C# .NET

We have a section break(on next odd page) at the end of a table. So if rendering of the table finishes on an odd page, the next section will start at the next odd page and a blank even-numbered page will be created in between. We want to print “This page is intentionally blank” on that extra page if it’s created. How can we do this?

Also the extra page is inheriting our footer and header information, but we want it to be purely blank but have the "This page is intentionally blank"​.

page 7 - blank page with the default text and no header and footer - page 9

@javidp84,

Thanks for your inquiry. Have you tried the latest version of Aspose.Words for .NET i.e. 19.10 on your end? In case the problem still remains, please ZIP and upload your input Word document and Aspose.Words generated PDF file showing the undesired behavior here for testing. We will then investigate the issue on our end and provide you more information.

the question was about “How” to do it, rather than reporting a bug!

@javidp84,

To ensure a timely and accurate response, please ZIP and attach the following resources here for testing:

  • Your simplified input document
  • Aspose.Words 19.10 generated output DOCX file showing the undesired behavior (if any)
  • Your expected DOCX Word document showing the correct output. You can create expected document by using MS Word.

As soon as you get these pieces of information ready, we will start investigation into your scenario and provide you code to achieve the same output by using Aspose.Words. Thanks for your cooperation.

Desired-Generated-CSharpPrj.zip (5.3 MB)

Please find the Desire document, Generated Document and the C# Prj in the attachments!

@javidp84,

We are working on your query and will get back to you soon.

@javidp84,

We have logged your requirement in our issue tracking system. Your ticket number is WORDSNET-19485. We will further look into the details of this requirement and will keep you updated on the status of the linked issue. We apologize for any inconvenience.

@awais.hafeez

Any news on this?

@javidp84,

Unfortunately, your issue (WORDSNET-19485) is not resolved yet. We are currently doing analysis on this issue to determine the root cause. We will inform you via this thread as soon as this issue will be resolved in future. We apologize for any inconvenience.

@awais.hafeez,

Any updates on this ticket?

@javidp84,

Unfortunately, we have not finished the work on WORDSNET-19485 yet. We have completed the initial analysis of this issue and will inform you via this thread as soon as we have any further updates on it. We apologize for any inconvenience.

any response on this? It’s been more than 3 months…

@javidp84,

Unfortunately, your issue is not resolved yet and there is no further news about this issue. We will keep you posted on any further updates and let you know via this thread when this issue will be resolved in future. We apologize for your inconvenience.

How can we help to prioritize this?

@javidp84,

Please check if the following code is acceptable for you and if it produces the desired output? Output DOCX and PDF files are attached here for your reference:

C# .NET Code:

Document doc = new Document("E:\\Temp\\Desired-Generated-CSharpPrj\\sample.docx");

// Change the type of section break to SectionStart.NewPage to be able 
// to manipulate the view of the header and footer of the blank page.            
doc.FirstSection.PageSetup.SectionStart = SectionStart.NewPage;

// Let's preserve continuous numeration and the view of the header and footer of further text.
Section secondSection = doc.Sections[1];
foreach (HeaderFooter headerFooter in doc.FirstSection.HeadersFooters)
    secondSection.HeadersFooters.Add(headerFooter.Clone(true));

// Create a section without header and footer, 
// with a single paragraph: "This page is intentionally left blank".

Run dummyRun = new Run(doc);
dummyRun.Text = "This page is intentionally left blank";

Paragraph dummyPara = new Paragraph(doc);
dummyPara.ParagraphFormat.Alignment = ParagraphAlignment.Center;
dummyPara.Runs.Add(dummyRun);

Section dummySection = new Section(doc);
dummySection.PageSetup.SectionStart = SectionStart.NewPage;
dummySection.HeadersFooters.LinkToPrevious(false);
dummySection.AppendChild(new Body(doc));
dummySection.Body.Paragraphs.Add(dummyPara);

// Insert blank section.
doc.Sections.Insert(1, dummySection);

ReportingEngine engine = new ReportingEngine();

Letter letter = new Letter();
for (int i = 0; i < 30; i++)
    letter.LetterTypes.Add(new LetterType() { name = "lettertype" + i });

engine.BuildReport(doc, letter, "Letter");

// Calculate the page number of the blank section. Remove this page, if the page number is odd.
Aspose.Words.Layout.LayoutCollector lc = new Aspose.Words.Layout.LayoutCollector(doc);
if (lc.GetStartPageIndex(dummyRun) % 2 != 0)
    doc.Sections.Remove(dummySection);

doc.Save("E:\\Temp\\20.1.pdf");
doc.Save("E:\\Temp\\20.1.docx");

public class LetterType
{
    public string name { get; set; }
}
public class Letter
{
    public Letter()
    {
        LetterTypes = new List<LetterType>();
    }
    public List<LetterType> LetterTypes { get; set; }
}