3

We have a function that writes out content from Sitecore into a Word document. It basically uses a user control (this was some legacy services we brought into the project to make it easier than rewriting) to write out a whole page in HTML, then uses this code to save this via a StringWriter to a Word document:

using (StringWriter stringWriter = new StringWriter()) {
  Context.Server.Execute(page, stringWriter, true);
  content = stringWriter.ToString();

  if (!string.IsNullOrEmpty(fileName)) {
    HttpContext.Current.Response.AddHeader("content-disposition", string.Format("attachment;filename={0}.doc", fileName));
    HttpContext.Current.Response.ContentEncoding = Encoding.UTF8;
    HttpContext.Current.Response.ContentType = "application/html";
    Context.Response.Write(content);
  } else {
    throw new Exception(string.Format("Could not get document from item in wordgenerator.asmx.cs item id {0}", item.ID));
  }
}

When the document is generated in Chinese, I'm not specifying any font specific to that language. I'm using Georgia in the headers and Arial in the body, but the intermix is happening in between content. When I export the document to HTML and look at the generated markup, it's mixing spans between different bits of text, where some are MS Gothic and some are SimSum. I checked the original source from Sitecore and it's just marked with "p" tags, so there's no font setting there. But it also seems like the MS Gothic's only effect is to bold the content...if I manually switch MS Gothic to SimSum, the Chinese characters don't change appearance except for losing bolding.

These are files that were sent by my client, but when I generated the files myself using my Mac, I got MS Mincho where MS Gothic appeared in the provided Word copy. Could it just be a matter of what system is generating the file, based on their version of Word, that they're getting different fonts? That doesn't make a lot of sense since it's server-generated, but I don't know if the browser/OS has any influence, maybe because it's a ContentType of applicatiopn/html.

0

1 Answer 1

1

The answer to this ended up being a stylesheet solution. Adding the language code to the body tag as a class, we were able to control the text fonts that way.

So in the body tag, add the language code, like <body class="zh-cn">. Then in your stylesheet, use style definitions that include the class, such as:

body.zh-cn h1, body.zh-cn h2, body.zh-cn h3, body.zh-cn p, body.zh-cn li, body.zh-cn .vcard-name, body.zh-cn .vcard-role, body.zh-cn .office a{
    font-family: "Microsoft YaHei UI Light", sans-serif !important;
}
body.zh-cn, body.lawyer-page.zh-cn .body-copy.body p {
    line-height: 1.7 !important;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.