Hi team,
The generated doc should look like attached file.
Hi Nakul,
Thanks for your query. In your case, please use following code snippet for your requirement. Hope this helps you. Please let us know if you have any more queries.
Document doc = new Document(MyDir + "Sample2.dotx");
MemoryStream stream = new MemoryStream();
doc.Save(stream, SaveFormat.Doc);
doc = new Document(stream);
Paragraph para = (Paragraph)doc.FirstSection.HeadersFooters[0].GetChild(NodeType.Paragraph, 1, true);
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Font.Size = para.Runs[0].Font.Size;
builder.Font.Name = para.Runs[0].Font.Name;
<span style=“font-family: “Courier New”; background: none repeat scroll 0% 0% yellow;” lang=“EN-GB”><span style=“font-family: “Courier New”;” lang=“EN-GB”>
// Insrt a table of contents at the beginning of the document.
builder.InsertTableOfContents("\\o \"1-3\" \\h \\z \\u");
// Build a document with complex structure by applying different heading styles thus creating TOC entries.
builder.Writeln("Heading 1");
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading1;
builder.PushFont();
builder.Font.Color = Color.White;
builder.Writeln("Heading 1 in TOC");
builder.PopFont();
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Normal;
builder.Writeln("Heading 2");
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading1;
builder.PushFont();
builder.Font.Color = Color.White;
builder.Writeln("Heading 2 in TOC");
doc.UpdateFields();
doc.Save(MyDir + "AsposeOut.docx");
Further to my last reply, the Paragraph.Runs[0].Font.Name do not return correct font name. We had already logged this issue in our issue tracking system as WORDSNET-6173. I have linked this forum thread to the same issue and you will be notified via this forum thread once this issue is resolved.
We apologize for your inconvenience.
Thanks for looking into the issue.
I would expect the result as generated in attached document.
Please resolve it as early as possible as it is affected in our production environment.
Nakul
Hi Nakul,
I have replied the following priority forum thread. Please use the workaround mentioned at this link.
Link is displaying below message
Not Found: Forum Not Found
Hi Nakul,
Thanks for your query. As per your post at this link you have shared a Priority Support forum link. So I share the same link for your reference.The Aspose.Words Normal Support users can not access Priority Support forum.
https://forum.aspose.com/t/53242
Ok…
Hi Nakul,
Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.
Hi Tahir,
Please notify me once you release a fix for this
Regards,
Nakul
Hi Nakul,
Thanks for your inquiry. I am afraid this issue WORDSNET-6173 had been postponed till a later date due to some other important issues and new features. We will inform you as soon as there are any further developments.
We apologize for your inconvenience.
Hi Tahir,
Hi Tahir,
Hi Tahir,
I did some modifications in my code.
I am able to get Heading 1 level font and color as per template.
But Heading 2 and above are not matching with word template used.
Could you please help me in this.
Please find below code used to set font level
ParagraphFormat paragraphFormat = ProcessingDocumentBuilder.ParagraphFormat;
paragraphFormat.ClearFormatting();
ProcessingDocumentBuilder.PopFont();
ProcessingDocumentBuilder.Font.ClearFormatting();
switch (headingLevel)
{
case HeadingLevel.Heading1:
ProcessingDocumentBuilder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading1;
break;
case HeadingLevel.Heading2:
ProcessingDocumentBuilder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading2;
break;
case HeadingLevel.Heading3:
ProcessingDocumentBuilder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading3;
break;
case HeadingLevel.Heading4:
ProcessingDocumentBuilder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading4;
break;
case HeadingLevel.Heading5:
ProcessingDocumentBuilder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading5;
break;
case HeadingLevel.NormalText:
ProcessingDocumentBuilder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Normal;
break;
default:
paragraphFormat.StyleName = “Normal”;
break;
}
ProcessingDocumentBuilder.PushFont();
As I see in generated code font and font color are not applied from used template from Heading 2 onward.
Please find template and output for verification.
Thanks and Regards,
Nakul
The issues you have found earlier (filed as WORDSNET-6173) have been fixed in this .NET update and this Java update.
This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(2)