Text formatting in TOA object's Long Citation

We are looking into using the Aspose Word TOA object to create our Table of Authority. We require the formatting to be as such:

Davis v. Tarrant Cnty., Tex.
565 F.3d 214 (5th Cir. 2009), cert. denied, 558 U.S. 1024, 130 S. Ct. 624, 175 L. Ed.
2d 478 (5th Cir. 2009)… 5, 8

Where “Davis v. Tarrent Cnty, Tex” and “cert. denied” are in italics. How can we get the “cert. denied” to be in italics in the long citation line?

Thanks!

@ILSTech,

To ensure a timely and accurate response, please ZIP and attach the following resources here for testing:

  • Your simplified input Word document
  • Aspose.Words 19.6 generated output DOCX file showing the undesired behavior (if any)
  • Your expected DOCX Word document. We will investigate the structure of your expected document as to how you want your final output be generated like. You can create expected document by using MS Word.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you code to achieve the same by using Aspose.Words. Thanks for your cooperation.

AsposeWordTOATest.zip (162.6 KB)
Documents.zip (51.7 KB)

I’ve attached a project and two documents for your review.
The “2_06 - Dulweber’s MTD-TOA.docx” is the output we are wanting (see red highlighted entry)
Notice that the title line is in italics and on it’s own line, the description paragraph is indented on the next line and the “cert. denied” text is in italics. We are wanting to keep this format but use the TOA object instead of building this out manually. I’m not seeing how to achieve the formatting by specifying the Long Citation string in the example project. Please advise on how to achieve this.

Thanks!

@ILSTech,

Please also list the complete steps that you performed in MS Word to create the expected document (2_06 - Dulweber’s MTD-TOA.docx). Essentially, you can perform the same steps programmatically by using Aspose.Words to get the desired output.

We use a Mail Merge process to create the “2_06 - Dulweber’s MTD-TOA.docx” file. I’ll attach the templates for your review. The problem we have is that initially we know what page numbers to use in the TOA, however, if our process re-formats the document or a user edits the document, then it’s possible for the page numbers to become incorrect. We are wanting to use the TOA object if possible to eliminate this problem, however, we must keep the formatting that is in the “2_06 - Dulweber’s MTD-TOA.docx” file per Blue Book specifications. The question remains is can we format the lines using the TOA object to match the format in “2_06 - Dulweber’s MTD-TOA.docx” document? If so, please provide an example of how to do this.

Thanks

Document Templates.zip (39.4 KB)

@ILSTech,

We are checking this scenario and will get back to you soon.

@ILSTech,

Please check the following example code that makes some parts of FieldTA italic:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

FieldToa fieldToa = (FieldToa)builder.InsertField(FieldType.FieldTOA, false);
fieldToa.EntryCategory = "1";
fieldToa.UseHeading = true;
fieldToa.RemoveEntryFormatting = true;

builder.Font.Color = Color.Red;
builder.Font.Name = "Arial Black";

builder.InsertBreak(BreakType.PageBreak);

FieldTA fieldTA = InsertToaEntry(builder, "1", "Davis v. Tarrant Cnty., Tex. 565 F.3d 214 (5th Cir. 2009), cert. denied, 558 U.S. 1024, 130 S. Ct. 624, 175 L. Ed. 2d 478 (5th Cir. 2009)");
doc.UpdateFields();

Paragraph para = (Paragraph)fieldTA.Start.GetAncestor(NodeType.Paragraph);

FindReplaceOptions findReplaceOptions = new FindReplaceOptions(FindReplaceDirection.Backward);
findReplaceOptions.ReplacingCallback = new Replacer(true);

// Make some parts of FieldTA italic
para.Range.Replace("Davis v. Tarrant Cnty., Tex.", "", findReplaceOptions);
para.Range.Replace("cert. denied", "", findReplaceOptions);
            
doc.Save("E:\\Temp\\19.6.docx"); 

private static FieldTA InsertToaEntry(DocumentBuilder builder, string entryCategory, string longCitation)
{
    FieldTA field = (FieldTA)builder.InsertField(FieldType.FieldTOAEntry, false);
    field.EntryCategory = entryCategory;
    field.LongCitation = longCitation;

    builder.InsertBreak(BreakType.PageBreak);

    return field;
}

public class Replacer : IReplacingCallback
{
    public bool IsItalic;
    public Replacer(bool flag)
    {
        IsItalic = flag;
    }

    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;
    }

    ReplaceAction IReplacingCallback.Replacing(ReplacingArgs e)
    {
        // This is a Run node that contains either the beginning or the complete match.
        Node currentNode = e.MatchNode;

        // The first (and may be the only) run can contain text  before the match,
        // in this case it is necessary to split the run.
        if (e.MatchOffset > 0)
            currentNode = SplitRun((Run)currentNode, e.MatchOffset);

        // This array is used to store all nodes of the match for  further highlighting.
        ArrayList runs = new ArrayList();

        // Find all runs that contain parts of the match string.
        int remainingLength = e.Match.Value.Length;
        while ((remainingLength > 0) &&
                (currentNode != null) &&
                (currentNode.GetText().Length <= remainingLength))
        {
            runs.Add(currentNode);
            remainingLength = remainingLength - currentNode.GetText().Length;

            // Select the next Run node.
            // Have to loop because there could be other nodes such as BookmarkStart etc.
            do
            {
                currentNode = currentNode.NextSibling;

            }
            while ((currentNode != null) && (currentNode.NodeType != NodeType.Run));
        }

        // Split the last run that contains the match if there is any text left.            
        if ((currentNode != null) && (remainingLength > 0))
        {
            SplitRun((Run)currentNode,
            remainingLength);

            runs.Add(currentNode);
        }
               
        foreach (Run run in runs)
        {
            run.Font.Italic = IsItalic;
        }

        return ReplaceAction.Skip;
    }
}

Hope, this helps.

Documents.zip (42.0 KB)

We are still not getting the desired output. Please see 7zip file attached with two docx files. The output of the example code you gave me is in the 19.6.docx file. The output we need is in the 2_06-Dulweber’s MTD-TOA.docx. See the red highlighted entry on the first page of the TOA.

The example code you sent does not change the TOA entry to be italic, but it does change the title on second page (Show paragraph marks on). We need to get the same formatting in the TOA as in the example (red highlighted entry) document.

To me it’s starting to look like this can’t be done in Aspose; hope I’m wrong.

Please advise.

@ILSTech,

We are checking this scenario and will get back to you soon.

@ILSTech,

I have used the previous code and generated an output document by using Aspose.Words for .NET 19.7 and attached it here for your reference (see 19.7.zip (5.4 KB)). Also, as shown in following screenshot, the code makes some parts of TA field italic:

You can build logic on this code to get the desired output. Please let me know if I can be of any further assistance.