diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx index c2c1b604e2b7..caff49110a1a 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx @@ -249,6 +249,7 @@ RTFDocumentImpl::RTFDocumentImpl(uno::Reference const& x m_bNeedPap(true), m_bNeedCr(false), m_bNeedPar(true), + m_bNeedFinalPar(false), m_aListTableSprms(), m_aSettingsTableAttributes(), m_aSettingsTableSprms(), @@ -481,6 +482,12 @@ void RTFDocumentImpl::sectBreak(bool bFinal = false) // If there is no paragraph in this section, then insert a dummy one, as required by Writer if (m_bNeedPar) dispatchSymbol(RTF_PAR); + // It's allowed to not have a non-table paragraph at the end of an RTF doc, add it now if required. + if (m_bNeedFinalPar && bFinal) + { + dispatchFlag(RTF_PARD); + dispatchSymbol(RTF_PAR); + } while (m_nHeaderFooterPositions.size()) { std::pair aPair = m_nHeaderFooterPositions.front(); @@ -1437,6 +1444,7 @@ int RTFDocumentImpl::dispatchSymbol(RTFKeyword nKeyword) m_bNeedPap = true; if (!m_aStates.top().aFrame.inFrame()) m_bNeedPar = false; + m_bNeedFinalPar = false; } break; case RTF_SECT: @@ -1541,6 +1549,7 @@ int RTFDocumentImpl::dispatchSymbol(RTFKeyword nKeyword) tableBreak(); m_bNeedPap = true; + m_bNeedFinalPar = true; m_aTableBuffer.clear(); m_aStates.top().nCells = 0; m_aStates.top().aTableCellsSprms.clear(); diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.hxx b/writerfilter/source/rtftok/rtfdocumentimpl.hxx index 93ed15d55398..9bb994d9fd35 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.hxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.hxx @@ -444,6 +444,8 @@ namespace writerfilter { /// If we need to emit a CR at the end of substream. bool m_bNeedCr; bool m_bNeedPar; + /// If set, an empty paragraph will be added at the end of the document. + bool m_bNeedFinalPar; /// The list table and list override table combined. RTFSprms m_aListTableSprms; /// The settings table attributes.