For the attached Word document the Aspose code is shoing multiple OLR print commands for the same page. MS Word is showing a single OLE command.
We are using version 11.7
The test app. shows the issue.
Is there a work around for this?
John
For the attached Word document the Aspose code is shoing multiple OLR print commands for the same page. MS Word is showing a single OLE command.
We are using version 11.7
The test app. shows the issue.
Is there a work around for this?
John
Hi John,
Thanks for your query. I have tested the scenario and have not found the shared issue while using following code snippet.There are four Print commands in your document. Please execute the following code snippet by using latest version of Aspose.Words for .NET and share your findings with us.
I will review your code and will share my findings with you.
Document doc = new Document(MyDir + "396242-unsupportedOLE.doc");
NodeCollection nodes = doc.GetChildNodes(NodeType.FieldStart, true, true);
foreach(FieldStart start in nodes)
{
if (start.FieldType == Aspose.Words.Fields.FieldType.FieldPrint)
{
Console.WriteLine(GetFieldCode(start));
}
}
private static string GetFieldCode(Aspose.Words.Fields.FieldStart fieldStart)
{
StringBuilder builder = new StringBuilder();
for (Node node = fieldStart; node != null && node.NodeType != NodeType.FieldSeparator && node.NodeType != NodeType.FieldEnd; node = node.NextPreOrder(node.Document))
{
// Use the text only of Run nodes to avoid duplication.
if (node.NodeType == NodeType.Run)
builder.Append(node.GetText());
}
return builder.ToString();
}
It looks like the pure code snippit for OLE produces the correct output, so the issue is the code for determining the page where the code snippet exists. How do we correctly determine the page number on which the OLE resides?
Attached is the code we are using and that works on 99% of the documents.
Thanks,
John
Hi John,
Thanks for your inquiry.
I have spotted the same behavior as well. The issue occurs because one page has many continuous sections on it. For some reason the first section on the page has no first page header footer whereas the previous section does. The two are not linked however there is no appropriate node imported into the DOM. I’m not sure if this is a bug with Aspose.Words or is just some quirky Microsoft Word behavior.
In any case a general type of work around for this is to include the following code in the same loop as the other checks. I’m not 100% sure this will work for all situations but hopefully it will.
if ((headerFooter.HeaderFooterType == HeaderFooterType.HeaderFirst ||
headerFooter.HeaderFooterType == HeaderFooterType.FooterFirst) &&
section.PageSetup.SectionStart == SectionStart.OddPage)
continue;
Hopefully this helps.
Thanks,