We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Footnotes don't have there corresponding numbers visible

Hi,

I create my wordfiles by inserting html code.
By using this code, i can parse my footnotes from the html:
doc.Range.Replace(new Regex(@“someregex”), new ReplaceEvaluator(ReplaceFootnote), false);

private static ReplaceAction ReplaceFootnote(object sender, ReplaceEvaluatorArgs e)
{
DocumentBuilder builder = new DocumentBuilder((Document)e.MatchNode.Document);
builder.MoveTo(e.MatchNode);
Footnote footnote = new Footnote(builder.Document, FootnoteType.Footnote);
builder.CurrentParagraph.AppendChild(footnote);
footnote.Paragraphs.Add(new Paragraph(builder.Document));
footnote.FirstParagraph.Runs.Add(new Run(builder.Document, e.Match.Groups[1].Value));
e.Replacement = “”;
return ReplaceAction.Replace;
}

The footnotes are appearing almost correctly, only the numbers in footnote itself doesn’t appear. But they do appear in paragraph text.

So, does somebody know how i can show the footnote numbers before the footnote at the bottom of the page ?

Thanks

Hi

Thanks for your request. I managed to reproduce the problem on my side. You will be notified as soon as it is resolved.

Best regards.

Hi,

Is there already a kind of solution for this ?

thx

Hi

Thanks for your request. Unfortunately, the issue is still unresolved. You will be notified as soon as it is fixed.

Best regards,

Hi,

I just tested our application with the new release (8.1.0) and i saw that this issue isn’t fixed yet.
Do you have any idea when this issue will be fixed ?

Thanks,

Hi

Thanks for your inquiry. Unfortunately, the issue is still unresolved and currently I cannot provide you any reliable estimate regarding this issue. You will be notified as soon as it is fixed.

Best regards,

Hi Andrey,

I’m still waiting for a fix for this issue.

As a workaround:
How can i loop into my pages and footnotes, so i can add everytime a number manually? I don’t see anything in the PageInfo object.

Thanks

Hi

Thanks for your inquiry. Unfortunately, currently I cannot suggest you any way to work this problem around. You should just wait for the fix of the original issue.

I added your request to my monthly report, so its priority will be increased. You will be notified as soon as it is fixed.

Best regards,

Hi Tom,

Thanks for your inquiry.

Please use the DocumentBuilder.InsertFootnote method instead. This will insert the corresponding numbers correctly down the bottom of the page.

Thanks,

Hi Adam,
Thank you for your reply.

Your solutions works for 50%, but maybe you can give me hints to let it work completely.

I create a huge book (over 1000 pages), by creating sections (chapters) and inserting html in those sections.

1: Position of footnote in the text
When I’m finished inserting html, i use this function to lookup footnotes in de text and replace them by real footnotes:
doc.Range.Replace(new Regex(@“VDBstartfootnoteVDB(?.*?)VDBendfootnoteVDB”), new ReplaceEvaluator(ReplaceFootnote), false);

The ReplaceFootnote function looks now like this:
private static ReplaceAction ReplaceFootnote(object sender, ReplaceEvaluatorArgs e)
{
DocumentBuilder builder = new DocumentBuilder((Document)e.MatchNode.Document);
builder.MoveTo(e.MatchNode);
builder.InsertFootnote(FootnoteType.Footnote, e.Match.Groups[1].Value);
e.Replacement = “”;
return ReplaceAction.Replace;
}

The result when exporting a chapter is this:
http://preview.vandenbroele.be/vademecum/footnote.docx
You’ll see that the number of the footnote starts at the beginning of the line, while it should be between the round brackets.

2: Errors when saving the document
In the example above, i exported just one article, but if i export the whole book, i get an error while saving the document in the codebehind of the webapp:
“Footnotes are only allowed inside the main text of the document.”

Maybe this error is caused by just a small number of footnotes in the whole document. So maybe i can find them and correct them.

Hi Tom,

Thanks for this additional information and supplying your output document.

This appears to be happening because the builder will insert the footnote at the start of a run and the text containing your place holder and the text before it is all one run. To achieve this functionality you need to split the runs around the place holder and brackets and then insert the footnote. Please see the code below that achieves this.

private static void ReplaceAction ReplaceFootnote(object sender, ReplaceEvaluatorArgs e)

{

DocumentBuilder builder = new DocumentBuilder((Document)e.MatchNode.Document);

// Split the left bracket and the place holder text. Method will return the “after run”, the newly split run to the right of the split point.

Run replaceHolderRun = SplitRun((Run)e.MatchNode, e.MatchOffset);

// Split the place holder run at however long the match text is, this will split the right bracket into it’s own run.

SplitRun(replaceHolderRun, e.Match.Length);

// Move to the place holder.

builder.MoveTo(replaceHolderRun);

// Insert footnote

builder.InsertFootnote(FootnoteType.Footnote, e.Match.Groups[1].Value);

// Remove the replaceholder run manually now as the match node has been effectively changed.

replaceHolderRun.Remove();

// Skip the replace instead now as the original MatchNode has been invalidated.

return ReplaceAction.Skip;

}

///

/// Splits text of the specified run into two runs.

/// Inserts the new run just after the specified run.

///

private static Run SplitRun(Run run, int position)

{

Run afterRun = (Run)run.Clone(true);

afterRun.Text = run.Text.Substring(position);

run.Text = run.Text.Substring(0, position);

run.ParentNode.InsertAfter(afterRun, run);

return afterRun;

}

It should work properly although I cannot be sure without your original template (before the replacing is executed). If you have any issues, could you please attach that for me.

Regarding the exception, judging from the error it appears the replace method is trying to insert a footnote into a header or footer. Could you please attach your full template here (all attachments to this forum can only be downloaded by you and the Aspose staff) and I will take a closer look.

Thanks,

Thank you Adam,
You saved the day!

The second problem seems to be resolved as well (don’t know why)

Just one more question:
With my first way of working, i could assign a style to the footnote, but with your function insertfootnote(footnotetype, text), i cannot assign a style to it.

The style i assigned, reduces the fontsize. Can i still do this?

Hi Tom,

It’s great it’s working now.

Sure, it just takes a bit of modification to the code above. Please see the sample code below which shows how to change the size of the the footnote text inserted through DocumentBuilder. You may want to change it a bit to use styles instead of direct font size.

Footnote footnote = builder.InsertFootnote(FootnoteType.Footnote, e.Match.Groups[1].Value);

foreach (Run run in footnote.GetChildNodes(NodeType.Run, true))

run.Font.Size = 8;

Thanks,

Thank you Adam,

It seems to work fine!