Hello,
We have the following Problem and i really would appreciate your help:
Right now we are using the python docx library, but we want to use or thinking to use the aspose API. So the process looks the following:
- Text from Word file gets extracted into a txt file.
- This txt gets edited.
- The edited Text is converted to a word file. Here the problem is that the footnotes are not in the same place.
Attached you find two documents. The original file is called Test_ASPOSE. This File has a paragraph with two footnotes. However when we extract the text, edit it slighltly (“multilateral”), then the footnotes move to the end of the paragraph (as shown in the modified_2 file), although the first footnote should come after the first sentence.
Controlling Seminar Final_Test_modified_2.docx (24,2 KB)
Controlling Seminar Final_Test_ASPOSE.docx (23,4 KB)
How can we solve this problem with the Aspose software API?
It is possible to solve it with the sdk, but we are not sure how and if it is possible to solve it with the API?
@Wilczynskk97
We will appreciate it if you please share your sample code with us. It will help us to investigate and address the issue.
@tilal.ahmad
So right now we are using the python docx library, but we want to use or thinking to use the aspose API.
Your collegue from Aspose.Words told me that it is possible with the following code. However i just wanted to know if it is possibile for Aspose Cloud.
placeholder_text = “[FOOTNOTE]”
doc = aw.Document(“C:\Temp\in.docx”)
footnotes will be stored separately so we could restore them later.
footnotes = []
replace footnotes with placeholder text.
for n in doc.get_child_nodes(aw.NodeType.FOOTNOTE, True) :
n.parent_node.insert_after(aw.Run(doc, placeholder_text), n)
footnotes.append(n.to_string(aw.SaveFormat.TEXT).strip())
n.remove()
Save the document as TXT.
doc.save(“C:\Temp\tmp.txt”)
Here the TXT document might be edited.
…
Open document from txt
doc_from_txt = aw.Document(“C:\Temp\tmp.txt”)
builder = aw.DocumentBuilder(doc_from_txt)
Replace placeholders with themsefs to make them to be represented as a separate Run.
doc_from_txt.range.replace(placeholder_text, placeholder_text);
Loop through runs and put footnotes where required.
index = 0;
for r in doc_from_txt.get_child_nodes(aw.NodeType.RUN, True) :
run = r.as_run()
if(run.text == placeholder_text) :
builder.move_to(run)
builder.insert_footnote(aw.notes.FootnoteType.FOOTNOTE, footnotes[index])
index = index + 1
run.remove()
doc_from_txt.save(“C:\Temp\out.docx”)
@Wilczynskk97
Please note that the Aspose.Words Cloud API supports all the features supported in Aspose.Words for Net(On-premise API). However, you need to call a separate API for each document element/operation. Please find documentation on how to read and add footnotes, add/update paragraphs/runs, replace text, and use document conversion APIs. The documentation includes the Aspose.Words Cloud SDK for Python sample code. However, you can also check unit tests from the Aspose.Words Cloud SDK for Python. Hopefully, these will help you accomplish the task using the Asose.Words Cloud API.
Hello @tilal.ahmad,
unfortunately we are still facing problems regaring the number of API Calls. Is it possible to do API Calls not on a run level but on a paragraph level while still keeping the footnotes in place after editing the text?
@Wilczynskk97
Please share some more details about the issues you are facing.
Please note that, as per the Aspose.Words DOM, for text editing, we need to update the run objects.