Skip to content
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

add Footnote on TemplateProcessor #2356

Open
kirkrob opened this issue Dec 11, 2022 · 0 comments
Open

add Footnote on TemplateProcessor #2356

kirkrob opened this issue Dec 11, 2022 · 0 comments

Comments

@kirkrob
Copy link

kirkrob commented Dec 11, 2022

Is your feature request related to a problem? Please describe.

allow adding a footnote using TemplateProcessor

Describe the solution you'd like

read word/footnotes.xml inside the word file (.docx) and add the footnotes, then inside word/document.xml reference those footnotes

A clear and concise description of what you want to happen.

example

   $TemplateProcess = new TemplateProcessor(example.docx');

    $Text = new TextRun(array('alignment' => Jc::CENTER, 'spaceBefore' => converter::pointToTwip(0), 'spaceAfter' => converter::pointToTwip(0), 'lineHeight' => '1.5'));
    $Text->addText('example text', array('bold' => true, 'size' => 14));
    $footnote = $Text->addFootnote();
    $footnote->addText('example Footnote 1', array('italic'=> true,'size' => 9));
    $TemplateProcess->setComplexBlock('reference1', $Text);

    $TemplateProcess->saveAs('TemplateSetComplexValueWithFootNote.docx');

Describe alternatives you've considered

Edit Files: src/PhpWord/TemplateProcessor.php

need on new TemplateProcessor

  • add protected $tempDocumentFootNotes = ''; // to store xml from word/footnotes.xml
  • add protected function getDocumentContentFootNotes() // return 'word/footnotes.xml';
  • add $this->tempDocumentFootNotes = $this->zipClass->getFromName($this->getDocumentContentFootNotes()); on public function __construct($documentTemplate) // for read xml and store in $tempDocumentFootNotes

need on $TemplateProcess->setComplexBlock

  • add private function isFoteNote($complexType) // to know if there are notes in what you want to save
  • add private function WriteFoteNote($complexType) // add to $tempDocumentFootNotes the note
  • add private function insertFootNote($xml,$pos) // insert xml footnote into tempDocumentFootNotes

need on $TemplateProcess->saveAs($fileName) specifically in public function save()

  • use again protected function getDocumentContentFootNotes() // return 'word/footnotes.xml';
  • add protected function saveFootNote($fileName, $xml) $fileName get from getDocumentContentFootNotes() and $xml get from $this->tempDocumentFootNotes

Edit Files: src/PhpWord/Writer/Word2007/Element/Footnote.php

  • add public function writeNote($Id)
  • add protected $elementNode = 'w:footnote';
  • add protected $refStyle = 'FootnoteReference';
  • add protected $refNode = 'w:footnoteRef';

Additional context

attached

  • modified src/PhpWord/Writer/Word2007/Element/Footnote.php on code.zip
  • modified src/PhpWord/Writer/Word2007/Element/Footnote.php on code.zip
  • input word file
  • output word file

Code.zip
example.docx
TemplateSetComplexValueWithFootNote.docx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant