@@ -128,6 +128,7 @@ public function save($pFilename = null)
128
128
$ rID = PHPWord_Media::countSectionMediaElements () + 6 ;
129
129
$ _sections = $ this ->_document ->getSections ();
130
130
131
+ $ footers = array ();
131
132
foreach ($ _sections as $ section ) {
132
133
$ _headers = $ section ->getHeaders ();
133
134
foreach ($ _headers as $ index => &$ _header ) {
@@ -139,12 +140,14 @@ public function save($pFilename = null)
139
140
}
140
141
141
142
$ _footer = $ section ->getFooter ();
142
- $ _cFtrs ++;
143
- $ _footer ->setRelationId (++$ rID );
144
- $ _footerCount = $ _footer ->getFooterCount ();
145
- $ _footerFile = 'footer ' . $ _footerCount . '.xml ' ;
146
- $ sectionElements [] = array ('target ' => $ _footerFile , 'type ' => 'footer ' , 'rID ' => $ rID );
147
- $ objZip ->addFromString ('word/ ' . $ _footerFile , $ this ->getWriterPart ('footer ' )->writeFooter ($ _footer ));
143
+ $ footers [++$ _cFtrs ] = $ _footer ;
144
+ if (!is_null ($ _footer )) {
145
+ $ _footer ->setRelationId (++$ rID );
146
+ $ _footerCount = $ _footer ->getFooterCount ();
147
+ $ _footerFile = 'footer ' . $ _footerCount . '.xml ' ;
148
+ $ sectionElements [] = array ('target ' => $ _footerFile , 'type ' => 'footer ' , 'rID ' => $ rID );
149
+ $ objZip ->addFromString ('word/ ' . $ _footerFile , $ this ->getWriterPart ('footer ' )->writeFooter ($ _footer ));
150
+ }
148
151
}
149
152
150
153
if (PHPWord_Footnote::countFootnoteElements () > 0 ) {
@@ -159,7 +162,15 @@ public function save($pFilename = null)
159
162
160
163
// build docx file
161
164
// Write dynamic files
162
- $ objZip ->addFromString ('[Content_Types].xml ' , $ this ->getWriterPart ('contenttypes ' )->writeContentTypes ($ this ->_imageTypes , $ this ->_objectTypes , $ _cHdrs , $ _cFtrs ));
165
+ $ objZip ->addFromString (
166
+ '[Content_Types].xml ' ,
167
+ $ this ->getWriterPart ('contenttypes ' )->writeContentTypes (
168
+ $ this ->_imageTypes ,
169
+ $ this ->_objectTypes ,
170
+ $ _cHdrs ,
171
+ $ footers
172
+ )
173
+ );
163
174
$ objZip ->addFromString ('_rels/.rels ' , $ this ->getWriterPart ('rels ' )->writeRelationships ($ this ->_document ));
164
175
$ objZip ->addFromString ('docProps/app.xml ' , $ this ->getWriterPart ('docprops ' )->writeDocPropsApp ($ this ->_document ));
165
176
$ objZip ->addFromString ('docProps/core.xml ' , $ this ->getWriterPart ('docprops ' )->writeDocPropsCore ($ this ->_document ));
0 commit comments