We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Index was out of range when calling UpdatePageLayout()

The attached Word document is generated with Aspose.Words. When trying to convert it to PDF using the code below, we get the error "Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index".

var doc = new Aspose.Words.Document(filename);

doc.UpdateFields();

doc.UpdatePageLayout(); <-- throws the error

doc.Save(pdf filename, Aspose.Words.SaveFormat.Pdf);

Any work-arounds?

/Uffe

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. I managed to reproduce the problem on my side. Your request has been linked to the appropriate issue. You will be notified as soon as it is fixed. The problem occurs because your document contains a field without field code. As a workaround please try using the following code:

// Open document.

Document doc = new Document(@"Test092\in.docx");

// Get all FieldStart from the document.

Node[] fieldStarts = doc.GetChildNodes(NodeType.FieldStart, true).ToArray();

// Loop through all FieldStart.

foreach (FieldStart fieldStart in fieldStarts)

{

//Check if there is FieldEnd after FieldStar

if (fieldStart.NextSibling.NodeType == NodeType.FieldEnd)

{

fieldStart.NextSibling.Remove();

fieldStart.Remove();

}

}

doc.SaveToPdf(@"Test092\out.pdf");

Hope this helps.

Best regards,

The issues you have found earlier (filed as 11327) have been fixed in this update.


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