Skip to content

MS Word footnote fix #125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 14, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions Classes/PHPWord/Writer/Word2007.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public function save($pFilename = null)
$rID = PHPWord_Media::countSectionMediaElements() + 6;
$_sections = $this->_document->getSections();

$footers = array();
foreach ($_sections as $section) {
$_headers = $section->getHeaders();
foreach ($_headers as $index => &$_header) {
Expand All @@ -139,8 +140,8 @@ public function save($pFilename = null)
}

$_footer = $section->getFooter();
$footers[++$_cFtrs] = $_footer;
if (!is_null($_footer)) {
$_cFtrs++;
$_footer->setRelationId(++$rID);
$_footerCount = $_footer->getFooterCount();
$_footerFile = 'footer' . $_footerCount . '.xml';
Expand All @@ -161,7 +162,15 @@ public function save($pFilename = null)

// build docx file
// Write dynamic files
$objZip->addFromString('[Content_Types].xml', $this->getWriterPart('contenttypes')->writeContentTypes($this->_imageTypes, $this->_objectTypes, $_cHdrs, $_cFtrs));
$objZip->addFromString(
'[Content_Types].xml',
$this->getWriterPart('contenttypes')->writeContentTypes(
$this->_imageTypes,
$this->_objectTypes,
$_cHdrs,
$footers
)
);
$objZip->addFromString('_rels/.rels', $this->getWriterPart('rels')->writeRelationships($this->_document));
$objZip->addFromString('docProps/app.xml', $this->getWriterPart('docprops')->writeDocPropsApp($this->_document));
$objZip->addFromString('docProps/core.xml', $this->getWriterPart('docprops')->writeDocPropsCore($this->_document));
Expand Down
16 changes: 9 additions & 7 deletions Classes/PHPWord/Writer/Word2007/ContentTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
class PHPWord_Writer_Word2007_ContentTypes extends PHPWord_Writer_Word2007_WriterPart
{

public function writeContentTypes($_imageTypes, $_objectTypes, $_cHdrs, $_cFtrs)
public function writeContentTypes($_imageTypes, $_objectTypes, $_cHdrs, $footers)
{
// Create XML writer
$objWriter = null;
Expand Down Expand Up @@ -153,12 +153,14 @@ public function writeContentTypes($_imageTypes, $_objectTypes, $_cHdrs, $_cFtrs)
);
}

for ($i = 1; $i <= $_cFtrs; $i++) {
$this->_writeOverrideContentType(
$objWriter,
'/word/footer' . $i . '.xml',
'application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml'
);
for ($i = 1; $i <= count($footers); $i++) {
if (!is_null($footers[$i])) {
$this->_writeOverrideContentType(
$objWriter,
'/word/footer' . $i . '.xml',
'application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml'
);
}
}


Expand Down
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Changes in branch for release 0.7.1 :
- Feature: (ivanlanin) GH-99 - General: Basic support for TextRun on ODT and RTF
- Feature: (ivanlanin) - Reader: Initial effort for Word2007
- Feature: (ivanlanin) - MemoryImage: Allow remote image when allow_url_open = on
- Bugfix: (ivanlanin) - Footnote: Corrupt DOCX reported by MS Word when sections > 1 and not every sections have footnote
- QA: (Progi1984) - UnitTests

Changes in branch for release 0.7.0 :
Expand Down