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

Free Support Forum - aspose.com

Null current story after linking header to previous one

Hi support,

I’m trying to link a header to the previous one. Here is my code:

Document wordDoc = new Document();
DocumentBuilder docBuild = new DocumentBuilder(wordDoc);

docBuild.write(“sec1”);
Node curNode = (Node)docBuild.getCurrentParagraph();

docBuild.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);
docBuild.write(“H1”);

docBuild.moveToHeaderFooter(HeaderFooterType.FOOTER_PRIMARY);
docBuild.write(“F1”);

docBuild.moveTo(curNode);

docBuild.insertBreak(BreakType.SECTION_BREAK_NEW_PAGE);

docBuild.write(“sec2”);
Node cur1Node = (Node)docBuild.getCurrentParagraph();

docBuild.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);
HeaderFooter header = (HeaderFooter) docBuild.getCurrentStory();
header.isLinkedToPrevious(true);

docBuild.moveToHeaderFooter(HeaderFooterType.FOOTER_PRIMARY);
docBuild.write(“F2”);

docBuild.moveTo(cur1Node);

wordDoc.save(“C:\Temp\docHeaderFooter1.doc”);

…but I get a null pointer exception when I try to move to footer. I’ve note that after “header.isLinkedToPrevious(true);”, the current story turns to null.

Thank you for looking into this,
Milan

Hi Milan,

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

Thanks for your request. I managed to reproduce the problem and created new issue #7845 in our defect database. I will notify you as soon as it is fixed.

As a workaround, you can try using the following code:

docBuild.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);

HeaderFooter header = (HeaderFooter)docBuild.getCurrentStory();

header.isLinkedToPrevious(true);

docBuild.moveToDocumentEnd();

docBuild.moveToHeaderFooter(HeaderFooterType.FOOTER_PRIMARY);

docBuild.write("F2");

Best regards.

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


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