The code provided in the following tutorial is not working for me. It never adds footnote right next to a particular word in a paragraph. It always adds the footnote at the end of the paragraph. Is the code provided in the tutorial below correct or do we need to modify it?
"e-iceblue.com/Tutorials/Spire.Doc/Spire.Doc-Program-Guide/Footnote/Insert-a-footnote-in-a-paragraph.html"
Here is my code.
- Code: Select all
Document document1 = new Document();
document1.LoadFromFile("C:\\PDF\\SampleDoc.docx", FileFormat.Docx2010);
Paragraph paragraph1 = document1.Sections[0].Paragraphs[0];
Footnote footnote1 = paragraph1.AppendFootnote(FootnoteType.Footnote);
DocumentObject obj=null;
for (int i = 0; i < paragraph1.ChildObjects.Count; i++)
{
obj=paragraph1.ChildObjects[0];
if (obj.DocumentObjectType == DocumentObjectType.TextRange)
{
TextRange textRange = obj as TextRange;
// Find the word "Spire.Doc" in paragraph1
if (textRange.Text == "Spire.Doc")
{
//Set bold format for the word "Spire.Doc"
textRange.CharacterFormat.Bold = true;
//Insert footnote1 after the word "Spire.Doc"
paragraph1.ChildObjects.Insert(i + 1, footnote1);
break;
}
}
}
TextRange text = footnote1.TextBody.AddParagraph().AppendText("Welcome to evaluate Spire.Doc");
text.CharacterFormat.FontName = "Arial Black";
text.CharacterFormat.FontSize = 10;
text.CharacterFormat.TextColor = Color.DarkGray;
footnote1.MarkerCharacterFormat.FontName = "Calibri";
footnote1.MarkerCharacterFormat.FontSize = 12;
footnote1.MarkerCharacterFormat.Bold = true;
footnote1.MarkerCharacterFormat.TextColor = Color.DarkGreen;
document1.SaveToFile("C:\\PDF\\SampleDocNew.docx", FileFormat.Docx2010);
Here is the text from the updated word doc with footnote. FootNote was added at the end of the paragraph and not after the word "Spire.Doc" as intended.
Evaluation Warning : The document was created with Spire.Doc for .NET.
Spire.Doc clone a finalized loan write-up so that appears as a new editable loan write-up, but all previously entered information from the original write-up that was cloned has been pre-populated including all footnotes and excluding ancillary documents.