Blank page added when converting DOCX to PDF using C# | Section Start Odd Page

We’re experiencing a problem when converting this document into a .pdf file (using version 20.3.0.0). The attached test file is just a part of a larger document that causes the problem. The attached file has all the unnecessary data removed from it leaving just enough for you to observe the problem. When converting it into a .pdf there’s a blank page inserted between the two pages if we use the foreach loop to set the RestartPageNumbering property of its sections to false. If you convert the document without the foreach loop, then the resulting .pdf file is just fine.

Test.zip (25.1 KB)

// Set license
var license = new License();
license.SetLicense("Aspose.Total.lic");

// Create from file
var document = new Document("Test.docx");

// Make page numbers continuous between sections
foreach (Section section in document)
{
	section.PageSetup.RestartPageNumbering = false;
}

// Save the document as pdf
document.Save("Test.pdf", SaveFormat.Pdf);

@bushprakash1,

We tested the scenario and have managed to reproduce the same problem on our end. For the sake of correction, we have logged this problem in our issue tracking system. The ID of this issue is WORDSNET-20121. We will further look into the details of this problem and will keep you updated on the status of correction. We apologize for your inconvenience.

@bushprakash1,

Regarding WORDSNET-20121, we have completed the work on your issue and concluded to close this issue with “Not a Bug” status. Please check below the analysis details:

Aspose.Words works as designed in this scenario. A blank even page is provided to satisfy “Section start: Odd Page” section property.

MS Word behaves in the same way. If the output of this scenario is saved to DOCX, MS Word will generate an extra blank page on saving to PDF or in Print Preview. The generated page will not show in the editor though which might be confusing. Aspose.Words imitates MS Word’s behavior on saving to PDF. The same will happen if continuous numbering is set for section 2 via MS Word UI.

The source document has two sections. Section start: odd page is set for both sections. Originally section 2 has starting page number 1 set explicitly. So the document has 2 pages, both numbered 1. Section 2 starts from page 2 which has page number 1 defined by the section properties. So far so good.

After that your code changes section properties, section 2 still starts on page 2, but now page numbering continues and page 2 actually has page number 2. The number conflicts with “Section start: Odd page” property, so MS Word provides a blank page before the beginning of section 2 on Printing or saving to PDF. Aspose.Words imitates the behavior.

So, you may please update your code to set section start to “new page” for sections starting from odd/even pages to work around the issue.