Docx to Pdf conversion issue with odd/even page break using Java

Hello,

It seems that Aspose.Word’s conversion to PDF has a bug whereby, if there is an even or odd section break, a blank page won’t always be added and the page numbering can be wrong.

I’ve attached an RTF file that demonstrates this problem - if you open the RTF file in Word, you will note the following:

  1. There are three pages at the start each with a section break after them, and each set to have no header or footer for their first page (i.e. they are three single-page sections with no header or footer).

  2. After the third page there is an “even page” section break.

  3. The fourth page is set to have its page numbering restart at 1, meaning that the fourth page would be an odd number (page 1).

  4. Thus, in Word, a blank page is inserted before the fourth section and the fourth section - the “CHAPTER ONE” page - has a footer with the page number given as 2. This is all correct.

However, if you convert this RTF document to PDF format using Aspose.Words, no blank page is inserted between the third and fourth pages, and the “CHAPTER ONE” document, despite starting after an “even page” section break, has a footer giving the page number as 1. This is incorrect, obviously.

Note that even if you insert another section break with another blank page between the third and fourth pages, the problem persists.

The quickest way of seeing what I mean is to open the RTF file in Word and look at the footer of the “CHAPTER ONE” page, then compare that with a PDF file generated by converting the RTF document using Aspose.

Is there anything I can do to the RTF to workaround this?

Thanks!

Hi Keith,

Thanks for your query. I have tested the scenario and have not found the blank page issue. However, I have managed to reproduce the page number issue at my end. I have logged this issue in our issue tracking system and you will be updated via this forum thread once this issue is resolved.
Please use the latest version of Aspose.Words for Java 11.0.0.

I can also reproduce this issue using Words for .Net version 11.5.0.

If I load two single page docx files and merge with SectionStart.OddPage the resulting docx file has page 1 and page 3 with a blank page 2. As required.

Saving the merged documents as pdf only produces a two page pdf.

But if the destination docx is opened in Word 2010 and then saved as pdf the resulting document has three pages.

static void Main(string[] args)
{
    var destDoc = new Document();
    destDoc.RemoveAllChildren();
    var sourceDoc1 = new Document(@"..\..\Source1.docx");
    sourceDoc1.FirstSection.HeadersFooters.LinkToPrevious(false);
    sourceDoc1.FirstSection.PageSetup.SectionStart = SectionStart.OddPage;
    sourceDoc1.FirstSection.PageSetup.PageStartingNumber = 1;
    sourceDoc1.FirstSection.PageSetup.RestartPageNumbering = true;
    destDoc.AppendDocument(sourceDoc1, ImportFormatMode.KeepSourceFormatting);
    var sourceDoc2 = new Document(@"..\..\Source2.docx");
    sourceDoc2.FirstSection.HeadersFooters.LinkToPrevious(false);
    sourceDoc2.FirstSection.PageSetup.SectionStart = SectionStart.OddPage;
    sourceDoc2.FirstSection.PageSetup.PageStartingNumber = 1;
    sourceDoc2.FirstSection.PageSetup.RestartPageNumbering = true;
    destDoc.AppendDocument(sourceDoc1, ImportFormatMode.UseDestinationStyles);
    foreach (Section section in destDoc.Sections)
    {
        section.PageSetup.MirrorMargins = true;
    }
    destDoc.UpdatePageLayout();
    destDoc.Save(@"..\..\Destination.docx");
    destDoc.Save(@"..\..\Destination.pdf");
}

Full source is attached.

Thanks.

Hi John,

Thanks for sharing the information. I have managed to reproduce the same issue at my side. I have logged this issue as WORDSNET-6587 in our issue tracking system. I have linked this forum thread to the same issue and you will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

The issues you have found earlier (filed as WORDSNET-6587) have been fixed in this .NET update and this Java update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.

The issues you have found earlier (filed as WORDSNET-5825) have been fixed in this .NET update and this Java update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.