Text font properties are incorrect after importing Word document into DOM using .NET

Hi team,


I am initializing word Aspose Word object with Word template file (.dotx).

ProcessingDocument = new Document(documentStream, new LoadOptions() { LoadFormat = LoadFormat.Dotx});

I want to apply heading font style and format from the specified template.

How can I achieve this?

For example , I have Sample2.dotx as template and when I start building doc, heading 1 text should take font from template.

i.e Trebuchet MS (Headings) and Font Size should be 14 in given case.
See attached file for example.

Thanks and Regards
Nakul

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");
Hi Nakul,

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.

The workaround of this issue is, to convert the document to DOC format first and then retrieve the font settings. Please see the highlighted code in my last post.

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

The forum you requested does not exist.

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…


I am able to access link using priority account.

Thanks,
Nakul

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,


When shall i expect fix for this solution.
This has been posted as priority issue.

Thanks and Regards,
Nakul
Hi Nakul,

Thanks for your query. I am afraid this issue WORDSNET-6173 had been postponed till a later date due to some other important issues and new features. I have requested the development team to share the ETA. As soon as any information is shared by them, I will be more than happy to share that with you.

We apologize for your inconvenience.

Hi Tahir,


This is priority issue and affecting our production.

Please provide fix as soon as possible,

I have already provided priority forum link in previous post.

Thanks and Regards,
Nakul
Hi Nakul,

Thanks for your inquiry. I am afraid, I can't provide you any reliable estimate at the moment. However, I have requested the development team to share the ETA. As soon as any information is shared by them, I will be more than happy to share that with you.

We apologize for your inconvenience.

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

I just took latest update for Aspose.word

It looks this issue has been resolved with 11.8.0.0

Thanks for support.

Thanks and Regards,
Nakul
Hi Nakul,

Please accept my apologies for your inconvenience.

Thanks for your inquiry. I am still waiting for the response from our development team. I have requested again for ETA of this issue from development team. As soon as any information is shared by them, I will be more than happy to share that with you.

We appreciate your patience.

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)