Skip to content

Support for footnote. #1

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

Open
julienfr112 opened this issue Jan 3, 2014 · 18 comments
Open

Support for footnote. #1

julienfr112 opened this issue Jan 3, 2014 · 18 comments

Comments

@julienfr112
Copy link

A footnote is two thing :

  • in the document.xml, at the place of the referecence :
<w:r>
  <w:rPr>
    <w:rStyle w:val="FootnoteReference"/>
  </w:rPr>
  <w:footnoteReference w:id="1"/>
</w:r>
  • in the footnote.xml the content of the footnote :
<w:footnote w:id="1">
  <w:p w:rsidRDefault="00D935D7" w:rsidR="00D935D7">
    <w:pPr>
      <w:pStyle w:val="FootnoteText"/>
    </w:pPr>
    <w:r>
      <w:rPr>
        <w:rStyle w:val="FootnoteReference"/>
      </w:rPr>
      <w:footnoteRef/>
    </w:r>
    <w:r>
      <w:t xml:space="preserve"> Note</w:t>
    </w:r>
  </w:p>
</w:footnote>
@scanny
Copy link
Contributor

scanny commented Jan 3, 2014

@julienfr112 check out the notation I added above, makes the XML much more readable :)

It's just adding triple-backticks on a line by themselves before and after the indented code, and an optional language name, 'xml' in this case.

@julienfr112
Copy link
Author

Good to know, thank you !

@scanny scanny added this to the later milestone May 1, 2014
@ludoo
Copy link

ludoo commented May 20, 2014

Added a first shot at (end|foot)notes support in #53

@Huyston
Copy link

Huyston commented Feb 6, 2015

How this is going? There is an api available yet for footenotes? If not, there is any workarounds till its done?
I need a simple function that adds a footenote reference at the end of a run, and a footenote text at the bottom of the same page. Something like
run.add_footenote('Footnote text')
Thanks in advance! And great job :)

@scanny
Copy link
Contributor

scanny commented Feb 10, 2015

Hi @Huyston. Haven't gotten to this yet, might be a while. You might look at the work @ludoo did in #53 to see if that can work for you. There are a lot of features on the docket to add so might be a while before I get to this one.

The first challenge is to get access to the notes part, then you can parse through the XML it contains. Looks like Ludovico has solutions to those problems, so you may be able to use his as is or extend it to meet your purposes.

@scanny scanny removed this from the later milestone Apr 9, 2016
@wildmichael
Copy link

wildmichael commented Sep 25, 2018

Four years later, and I need this 😄
👍 from me for this issue!

@noamloewenstern
Copy link

@scanny
Hey, I've started working with python-docx, and i'ts great.
I've been looking for ways to add FootNotes, and have seen the problem I'm facing is not new reading this issue.

  1. Possible to merge the Read-Only-Footnotes functionality added by ludoo? (at Initial read-only support for notes, style objects #53 (comment))
  2. Adding the Write-Footnotes functionality as Huyston requested? ( at Support for footnote. #1 (comment))
  3. Can either you @scanny or @ludoo help me figure out how to add new FootNotes to a new/existing docx file?
    The API usage will be best, something like "run.add_footenote('Footnote text')",
    but can't, well, is there any other way to do it programmatically other than opening up the xml-file after it as been compiled as docx, and adding hardcoded-string to that file?
    An Example of usage will be very appreciated.
    Thanks so much.

@bobbayj
Copy link

bobbayj commented Dec 18, 2019

@BayooG has added some low-level support for writing footnotes at #624. I believe it also contains some API usage, like text.paragraph.add_footnote(text)

@scanny please merge and add support for these!!

@xrisk
Copy link

xrisk commented Feb 12, 2020

the problem i’m facing right now: assigning text to a run removes all footnote references. any easy way to get around this? i don’t need to edit footnotes – just keep existing ones intact.

@xrisk
Copy link

xrisk commented Feb 12, 2020

fwiw: #53 worked for me. i was able to modify Runs without losing associated references. of course, i had to modify the code a little bit because the library didn’t even support editing Run text back then.

link to my branch in case anyone needs it: https://github.com/xrisk/python-docx/tree/footnotes

@br-rkdrnf
Copy link

I just uploaded PR to provide access to footnotes and endnotes. It might be helpful if you check my PR.
#860

@br-rkdrnf
Copy link

@xrisk You should not assign text to runs directly or it will remove all child elements a run have. Currently, you should inspect and change child elements of a run individually and prevent changing content of footnoteReference element.

@fathoni
Copy link

fathoni commented Aug 17, 2021

Looking forward to these PRs being merged as well. That would be a great news :)

@LeeJongKyu
Copy link

LeeJongKyu commented Sep 16, 2021

Dear @ludoo or @scanny
I understand how to use footnote :)
And then, I want to know how can I insert the footnote in a table??

when I insert cell content, I make the content like this code,

hdr_cells = table.rows[0].cells

hdr_cells[0].paragraphs[0].add_run('Cell').normal = True
hdr_cells[0].paragraphs[0].style = 'Table_title'
hdr_cells[0].paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.CENTER

I want to insert footnote 'cell'

How can I insert the footnote?
please help me

@Barsovski
Copy link

Barsovski commented Feb 21, 2022

What about footnotes guys?
Any good official python-docx news about this missing useful feature since 2020? Or i miss something?
@BayooG no longer keeps the project up to date

pix pushed a commit to pix/python-docx that referenced this issue Aug 19, 2022
@AlexanderBorg
Copy link

Patiently waiting in mid-2023 :-)

@buhtz
Copy link

buhtz commented Jun 7, 2023

Patiently waiting in mid-2023 :-)

Don't wait. Implement it yourself and offer it to the community via opening a PR.
I understand your situation but please also understand the situation of the maintainer of that project.

Please see #1154

alberto743 pushed a commit to alberto743/python-docx that referenced this issue Jun 15, 2023
@davinoregan
Copy link

davinoregan commented Jan 31, 2025

The bayoo-docx fork works like a charm in adding footnotes - major snaps for BayooG in developing this. But I am now trying to embed hyperlinks within the text of footnotes. Others (here and here) have done this for text within the main body of a word doc (the word/document.xml), but is there a way to do it in footnotes? It seems the hiccup with available code is that some of the docx functions (Document() and relate_to()) only apply to the word/document.xml and documents.xml.rels files, whereas to manipulate footnotes you need to access footnotes.xml and footnotes.xml.rels. Questions:

  1. Is it possible to simply modify python-docx so that its functions work on different parts of hte underlying xml files within the zip file that is Word document? That way i can iterate through the paragraphs in a footnote.xml file instead of the document.xml?

  2. Or is there code where someone has done this manually, using lxml or something similar to manipulate the footnotes.xml and footnotes.xml.rels files?

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

No branches or pull requests