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

Free Support Forum - aspose.com

Template with embedded font not showing!

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(

"

" +

"

" +

"

" +

"

" +

"

" +

"

" +

"

" +

"

" +

"

" +

"

" +

"

Times: The Quick Brown Fox Jumps Over The Lazy Dog!
Arial: The Quick Brown Fox Jumps Over The Lazy Dog!
Cisco: The Quick Brown Fox Jumps Over The Lazy Dog!
");

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<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

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")<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Dim docStream As IO.MemoryStream = New IO.MemoryStream(fileBytes)

Dim document As Document = New Document(docStream)

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional information. Here is code that shows how to open document from stream:

//Read file bytest

byte[] docBytes = File.ReadAllBytes(@"Test179\cisco_font_template.dot");

//Create memory stream

MemoryStream docStream = new MemoryStream(docBytes);

//Create document

Document doc = 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:

http://www.idautomation.com/kb/ttf_embedding.html

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<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

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(

"

" +

"

" +

"

" +

"

" +

"

" +

"

" +

"

" +

"

" +

"

" +

"

" +

"

" +

"

" +

"

" +

"

Arial: The Quick Brown Fox Jumps Over The Lazy Dog!
Cisco: The Quick Brown Fox Jumps Over The Lazy Dog!
 
Embedded font below
");

doc.Save("test.doc", SaveFormat.Doc, SaveType.OpenInBrowser, Response);

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. Maybe you can try to remove all content from the document after loading. See the following 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);

//Remove content from first section

doc.FirstSection.Body.RemoveAllChildren();

doc.FirstSection.Body.EnsureMinimum();

//Insert HTML... etc

Hope this helps.

Best regards.

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:

[IndexOutOfRangeException: Index was outside the bounds of the array.]
㷩.㽳.㽹(㽭 㽺) +421
㷩.㻭.㼎() +329
㷩.㻭.ޭ(Stream ԑ) +111
㷩.㻭.ޭ(String ԏ) +73
㷩.㻭.㼄(String ⯧) +469
㷩.㻭.㸡(String ⯧, FontStyle উ, Boolean 㼁) +153
㷩.㻭.ਾ(String ⯧, FontStyle উ, Boolean 㼁) +18
㵔.㷗..ctor(㶈 context, String familyName, FontStyle requestedStyle) +43
㵔.㸬..ctor(㶈 context, String familyName, FontStyle requestedStyle) +79
㵔.㷗.㷤(㶈 ೫, String ⯧, FontStyle 㷥, Boolean 㷦) +43
㵔.㸚.ਾ(String ⯧, FontStyle উ, Boolean 㷦) +111
㵔.䁝.䁦(଴ ஢) +176
㵔.䁆.㬥(଴ ஢) +30
㵔.䃔.VisitGlyphs(଴ glyphs) +13
૜.଴.Accept(૥ visitor) +9
૜.૟.Accept(૥ visitor) +108
૜.૦.Accept(૥ visitor) +26
૜.૟.Accept(૥ visitor) +108
૜.૦.Accept(૥ visitor) +26
૜.૟.Accept(૥ visitor) +108
૜.૦.Accept(૥ visitor) +26
૜.૟.Accept(૥ visitor) +108
૜.૦.Accept(૥ visitor) +26
૜.૟.Accept(૥ visitor) +108
૜.૦.Accept(૥ visitor) +26
૜.૟.Accept(૥ visitor) +108
૜.૦.Accept(૥ visitor) +26
૜.૟.Accept(૥ visitor) +108
૜.૦.Accept(૥ visitor) +26
૜.૟.Accept(૥ visitor) +108
૜.૛.Accept(૥ visitor) +27
Aspose.Words.Document.SaveToPdf(Int32 pageIndex, Int32 pageCount, Stream stream, PdfOptions options) +474
Aspose.Words.Document.ԗ(Stream ԑ, String ԏ, SaveFormat Ԙ) +48
Aspose.Words.Document.Save(String fileName, SaveFormat fileFormat) +97
test_font.btn_word_preview_click(Object sender, EventArgs e) in c:\CBRE\test_font.aspx.cs:60
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565

**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<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

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, here's the code.

string str_path = System.Web.HttpContext.Current.Server.MapPath("") + "/";

//Read file bytes

byte[] doc_bytes = File.ReadAllBytes(str_path + "cisco_font_template.dot");

//Create memory stream

MemoryStream doc_stream = new MemoryStream(doc_bytes);

//Create document

Document doc = new Document(doc_stream);

//Remove content from first section

doc.FirstSection.Body.RemoveAllChildren();

doc.FirstSection.Body.EnsureMinimum();

DocumentBuilder builder = new DocumentBuilder(doc);

builder.InsertHtml(

"

" +

"

" +

"

" +

"

" +

"

" +

"

" +

"

" +

"

" +

"

" +

"

" +

"

Arial: The Quick Brown Fox Jumps Over The Lazy Dog!
Ciscoregular: The Quick Brown Fox Jumps Over The Lazy Dog!
Ciscolight: The Quick Brown Fox Jumps Over The Lazy Dog!
");

//doc.Save("test.doc", SaveFormat.Doc, SaveType.OpenInBrowser, Response);

//doc.Save(str_path + "test.pdf", SaveFormat.Pdf);

//doc.SaveToPdf(str_path + "test.pdf");

doc.Save("test.pdf", SaveFormat.Pdf, SaveType.OpenInBrowser, Response);

It will be good if you provide me with code to resolve this. Thanks.

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

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<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for you r inquiry. I use .NET 2.0 and Aspose.Words 6.2.0.

http://www.aspose.com/community/files/51/file-format-components/aspose.words-for-.net-and-java/entry166389.aspx

I also tried using Aspose.Words 6.1.0 and all works fine.

Best regards.

Why is the embedded font in the word document not showing in your out.pdf? How do you make it appear? Please advise.

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

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.

A fix for the issue(s) you've reported (filed as 7626) 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.
(3)

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


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