Docx file conversion to PDF splits first page into 2 pages

I have an issue where the first page of a DOCX file is split into 2 PDF pages.
I have attached the input and output files as examples.
the code I used was as follows

static public void ConvertToPdf(string sFileIn, string sFileOut)
{
    Aspose.Words.Document document = new Aspose.Words.Document(sFileIn);
    document.Save(sFileOut, Aspose.Words.SaveFormat.Pdf);
}

Hi Thaddeus,

Thanks for your inquiry. 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 as WORDSNET-14131. Our product team will further look into the details of this problem and we will keep you updated on the status of correction. We apologize for your inconvenience.

Best regards,

Hi,

It is to update you that our product team has completed the analysis of this issue and the root cause has been identified. However, because of complexity, the implementation of the fix of this issue has been postponed.

The issue occurs because Aspose.Words currently wraps the main story contents around a floating shape in the header, and MS Word does not.

In the attached simplified 14131s.docx there is a thin vertical line in the header. This line has wrapping type Through and left and right distance from text is set to 9 points. So Aspose.Words treats the line as a floater of 18 points wide. The floater occupies the whole column height and there is not enough space for the problematic table to the right of the floater. So Aspose.Words pushes the table to the second page.

It seems, MS Word ignores distance from text for the vertical line shape in the document. Changing distance from text does not affect MS Word layout. However, if the shape wrapping type is changed to Square, MS Word starts to take distance from text into account, and layout of the first page in MS Word becomes similar to Aspose.Words.

Also, if the document is re-saved via MS Word 2013 without maintaining compatibility, MS Word starts to honor distance from text, and the first page layout becomes similar to Aspose.Words.

We do currently not understand why in this particular case MS Word disregards distance from text for tight (through) wrapped shapes in compatibility mode.

You may make the shapes in the header not wrapped as a workaround.

Best regards,

“However, because of complexity, the implementation of the fix of this issue has been postponed.”

Is this going to be fixed eventually? Is there a time frame for this fix? My company has a priority support contract, would it expedite the process if I opened this issue using that process?

Hi Dan,

I am afraid, currently there are no reliable estimates available.

I am also in coordination with product team to get answer pertaining to your queries. Soon you will be updated with the required information.

Best regards,

Hi Dan,

I am afraid, we won’t be able to share a reliable estimate at this time and raising to priority support level will not make any difference either. The issue is about a very specific MS Word behavior. The difficult part here is to figure out the condition on which MS Word ignores “distance from text” in shape properties. Until our product team provides some solution for this issue, you may make the problematic shape not-wrapped as a workaround. We apologize for your inconvenience.

Best regards,

Our customer is still asking if there will ever be a fix for this issue?

Is there any pre processing I can do programatically to remove this spacing issue from the document prior to converting to PDF?

Hi Dan,

We are in coordination with product team to get answer pertaining to your queries. Soon you will be updated with the required information.

Best regards,

Hi Dan,

As the text does not wrap around the problematic shapes in MS Word, the shapes can be just made not-wrapped programmatically as a workaround. Please see the following example code:

Document doc = new Document(MyDir + @"in.docx");
// Go through all sections and make tight-wrapped shapes in headers/footers not wrapped.
foreach (Section section in doc.Sections)
{
    foreach (HeaderFooter headerFooter in section.HeadersFooters)
    {
        NodeCollection shapes = headerFooter.GetChildNodes(NodeType.Shape, true);
        foreach (Shape shape in shapes)
        {
            bool isTightWrapped = (shape.WrapType == WrapType.Tight) || (shape.WrapType == WrapType.Through);
            if (isTightWrapped)
            {
                shape.WrapType = WrapType.None;
            }
        }
    }
}
doc.Save(MyDir + @"16.12.0.pdf");

Hope, this helps.

Best regards,

I am trying to test this example and I cannot resolve Section? has the class name changed?

Hi Dan,

There is no change in this regard. You just need to add following namespace at the top:

using Aspose.Words;

Best regards,