Hi there,
Please take a look at the following code:
Document doc = new Document(str_path + "cisco_font_template.dot");
doc.AttachedTemplate = str_path + "cisco_font_template.dot";
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertHtml(
"<table border='0' cellpadding='0' cellspacing='0' width='100%'>" +
"<tr>" +
"<td>Times: The Quick Brown Fox Jumps Over The Lazy Dog!</td>" +
"</tr>" +
"<tr>" +
"<td><font style='font-family: Arial;'>Arial: The Quick Brown Fox Jumps Over The Lazy Dog!</font></td>" +
"</tr>" +
"<tr>" +
"<td><font style='font-family: Cisco-Regular;'>Cisco: The Quick Brown Fox Jumps Over The Lazy Dog!</font></td>" +
"</tr>" +
"</table>");
doc.Save("test.doc", SaveFormat.Doc, SaveType.OpenInBrowser, Response);
I’m having problem showing the Cisco-Regular font which i have included in the template file. I have checked the embed font option when saving the template. Please help.
Hi
Thanks for your request. Could you please attach your template for testing? I will investigate the issue and provide you more information.
Best regards.
Attached is the template as requested.
Also, how do you call a template using memory stream in C#? I need this part to prevent the issue of the same template unable to open as it might be already in use by other users. I found the following code in one of the threads but its in VB. I try to convert it to C# but can’t get it to work. Please help.
Dim fileBytes As Byte() = IO.File.ReadAllBytes("template.dot")
Dim docStream As IO.MemoryStream = New IO.MemoryStream(fileBytes)
Dim document As Document = New Document(docStream)
Regarding font problem, I cannot see any problems here. Font name is correct. Maybe font is not embedded into the document. See the following link to learn how to embed fonts into the document: https://www.barcodefaq.com/knowledge-base/embed-truetype-fonts/
Best regards.
Thanks for the memory stream code.
Regarding the font problem, that’s was what I did when I create the template. Please advise on this as it is very crucial to my application.
Hi
Aspose.Words preserves embedded fonts in the document. However, it seems there is no embedded font in your document. Because text inserted by Aspose.Words and text that already present in the template looks the same. Could you please attach this font here for testing?
If you see difference between text inserted by Aspose.Words and text in your template, please provide me screenshot or explain what the difference is.
Best regards,
I’m able to get the font working when I use the memory stream code and updating the fonts. But now the next problem I’m facing is how to not display the wordings found in the template in the generated word document? Please see attached files and code.
//Read file bytes
byte[] doc_bytes = File.ReadAllBytes("cisco_font_template.dot");
//Create memory stream
MemoryStream doc_stream = new MemoryStream(doc_bytes);
//Create document
Document doc = new Document(doc_stream);
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertHtml(
"<table border='0' cellpadding='0' cellspacing='0' width='100%'>" +
"<tr>" +
"<td><font style='font-family: Arial;'>Arial: The Quick Brown Fox Jumps Over The Lazy Dog!</font></td>" +
"</tr>" +
"<tr>" +
"<td><font style='font-family: Ciscoboldoblique;'>Cisco: The Quick Brown Fox Jumps Over The Lazy Dog!</font></td>" +
"</tr>" +
"<tr>" +
"<td> </td>" +
"</tr>" +
"<tr>" +
"<td><font style='font-family: Arial;'><u>Embedded font below</u></font></td>" +
"</tr>" +
"</table>");
doc.Save("test.doc", SaveFormat.Doc, SaveType.OpenInBrowser, Response);
It works. Thanks alot for your help. One last issue. I need to save the file as pdf and I tried replacing the save code with one of the following code
- doc.Save(“test.pdf”, SaveFormat.Pdf, SaveType.OpenInBrowser, Response);
- doc.Save(str_path + “test.pdf”, SaveFormat.Pdf);
- doc.SaveToPdf(str_path + “test.pdf”);
I get this error: System.IndexOutOfRangeException: Index was outside the bounds of the array
Here is the stack trace:
**Please note that I’m using the latest aspose.word 6.1.0 and I do not have aspose.pdf.
What I need is the code in bold "doc.Save(“test.pdf”, SaveFormat.Pdf, SaveType.OpenInBrowser, Response);" to work, please advise.
Hi
Thanks for your request. Could you please provide me code that will allow me to reproduce the problem or attach the document that causes the problem? I will try to reproduce the issue on my side and provide you more information.
Best regards.
Hi
Thank you for additional information. Unfortunately, I cannot reproduce the problem on my side. I used the same code as you provided and no errors occur. The output PDF id generated correctly. Maybe there is something else, I can do to reproduce the issue.
Best regards.
Is it possible for you to attach the generated pdf here, I need to take a look at it. Also, please provide me with the version of the Aspose.word version that you are using and the version for the .net framework. I need to get this to work as it is very urgent and crucial for my application. Thanks.
Hi
Thanks for you r inquiry. I use .NET 2.0 and Aspose.Words 6.2.0. https://releases.aspose.com/words/net
I also tried using Aspose.Words 6.1.0 and all works fine.
Best regards.
Hi
Thanks for your inquiry. Aspose.Words does not yet support embedded fonts upon converting document to PDF. This is the issue #7626 in our defect database.
Best regards.
Hi there, I got everything working even with the embedded font. For those who is having this problem, please use the latest Aspose.word 6.2.0 and .net framework 2.0. Thanks for the help.