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

Free Support Forum - aspose.com

Use pictures in hidden TOC-fields

is it possible to use pictures together with hidden toc-fields.
I use the following code to set hidden text for TOC like this:

builder.InsertField("TC \"My header\" \\l 1","");

So i want to insert picture (or a kind of Wingding-Symbol) before the text “Myheader”, how can i do this?

Hi
Thanks for your inquiry. There is no direct way to achieve this. But you can edit field code after inserting. For example see the following code:

// Create document
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Insert TOC
builder.InsertTableOfContents(@"\f \h \z");
// Insert page break
builder.InsertBreak(BreakType.PageBreak);
// Insert TC field
builder.InsertField("TC \\l 1", "");
// There is no dirrect way to insert image into TC field
// So we get Start of TC field and insert imaged After TC text
NodeCollection fieldStarts = builder.CurrentParagraph.GetChildNodes(NodeType.FieldStart, true);
// Loop therough all fieldStarts and dearch for TC field
FieldStart tcStart = null;
foreach (FieldStart start in fieldStarts)
{
    if (start.FieldType == FieldType.FieldTOCEntry)
    {
        tcStart = start;
        break;
    }
}
// Now we should split field code
Run fieldCode = (Run)tcStart.NextSibling;
// Create another run
Run tcStartRun = (Run)fieldCode.Clone(true);
tcStartRun.Text = "TC ";
fieldCode.Text = fieldCode.Text.Replace("TC", "");
fieldCode.ParentNode.InsertBefore(tcStartRun, fieldCode);
// Move document builder cursor to fieldCode run
builder.MoveTo(fieldCode);
// Insert image
builder.Write("\"");
builder.InsertImage(@"Test034\test.jpg");
// Insert text
builder.Write("My Header\"");
// Save document
doc.Save(@"Test034\out.doc");

Don’t forget to update fields in the document.
Hope this helps.
Best regards.

This is not exactly what i want, because it works for 1 level heading (not more) and the image does not be visible on field-def-page.
i need the following TOC:
Heading1
Heading2
Heading3

------------------------------------------
And it is important that the is invisible on the field-definition page (like its text)

Hi
Thanks for your inquiry. This code works for each level. Please try using the following code:

public void Test034()
{
    // Create document
    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);
    // Insert TOC
    builder.InsertTableOfContents(@"\f \h \z");
    // Insert page break
    builder.InsertBreak(BreakType.PageBreak);
    InsertTocEntry(builder, "First level", 1);
    builder.Writeln();
    InsertTocEntry(builder, "Second level", 2);
    builder.Writeln();
    InsertTocEntry(builder, "Third level", 3);
    builder.Writeln();
    // Save document
    doc.Save(@"Test034\out.xml", SaveFormat.WordML);
}
private void InsertTocEntry(DocumentBuilder builder, string text, int level)
{
    // Insert TC field
    FieldStart tcStart = builder.InsertField("TC ", null);
    // Now we should split field code
    Run fieldCode = (Run)tcStart.NextSibling;
    // Create empty run
    Run emptyRun = (Run)fieldCode.Clone(true);
    emptyRun.Text = string.Empty;
    FieldEnd tcEnd = (FieldEnd)fieldCode.NextSibling;
    // Insert empty run after Field end
    tcEnd.ParentNode.InsertAfter(emptyRun, tcEnd);
    // Move document builder cursor to tcEnd 
    builder.MoveTo(tcEnd);
    // Insert image
    builder.Write(" \"");
    // Insert image
    switch (level)
    {
        case 1:
            builder.InsertImage(@"Test034\1.jpg");
            break;
        case 2:
            builder.InsertImage(@"Test034\2.jpg");
            break;
        case 3:
            builder.InsertImage(@"Test034\3.jpg");
            break;
    }
    // Insert text and level
    builder.Write(string.Format("{0}\" \\l {1}", text, level));
    // Move DocumentBuilder cursor to the end of field
    builder.MoveTo(emptyRun);
}

Also I managed to reproduce the issue with images inside T^C field. I created new issue #5765 in our defect database. As a workaround you can save the document tin WML, RTF or DOCX format.
Best regards.

hello,
when can i get a fix for this, its urgent!!!
greetings

Hi
Thanks for your inquiry. Unfortunately I can’t provide you any estimate at the moment. Please expect a reply within few weeks.
Best regards.

A fix for the issue(s) you’ve reported (filed as 5765) will be released in the next release at the end of this month. You will be notified.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.

The issues you have found earlier (filed as WORDSNET-1765) have been fixed in this .NET update and in this Java update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.