Categories > OpenTBS with DOCX >

East Asian Characters and MS Word using MergeBlock not working

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Dee Dee
Date: 2013-06-26
Time: 19:58

East Asian Characters and MS Word using MergeBlock not working

I have a program in which I am trying to place East Asian characters onto a MS Word document using the MergeBlock method.  The text is in an XML file that looks like this:

...
<titleInfo>
   <title>詩風初集</title>
</titleInfo>
...

1. I've verified the following are all encoded in UTF-8:
-XML file
-MS Word template
-PHP (using the iconv_set_encoding methods)
2. I verified that PHP is extracting the title with the proper characters.  I did this by doing a simple echo of the title.

Inside my MS Word template, I have a table with a block that looks like this:
[a.title;block=tbs:row]


Here is the code I used to try to populate the template:
...
$xml = simplexml_load_string($xmlString);

$TBS = new clsTinyButStrong(); // new instance of TBS
$TBS->setOption("charset", "UTF-8");
$TBS->Plugin(TBS_INSTALL, OPENTBS_PLUGIN);
$TBS->LoadTemplate($templatePath, "UTF-8");

echo $xml->titleInfo->title; //This echos the characters correctly

$TBS->MergeBlock('a', array(array("title" => $xml->titleInfo->title)));
$TBS->Show(OPENTBS_FILE, $filesName);

If I use any characters aside from the East Asian characters, the blocks populate correctly. Using East Asian Characters, the characters are displayed as squares, question marks, and other symbols (something like this: 詩風初集).

I also tried changing the font of the template to Arial Unicode MS but this resulted in the same output as mentioned above.

Any ideas what I'm doing wrong?
Thanks.
By: Skrol29
Date: 2013-06-26
Time: 23:53

Re: East Asian Characters and MS Word using MergeBlock not working

Hi Dee Dee,

With OpenTBS, do not use the argument "UTF-8" but OPENTBS_ALREADY_UTF8 instead.
$TBS->LoadTemplate($templatePath, OPENTBS_ALREADY_UTF8);
By: Dee Dee
Date: 2013-06-27
Time: 03:17

Re: East Asian Characters and MS Word using MergeBlock not working

Thanks, I should have mentioned that I tried the OPENTBS_ALREADY_UTF8 as well and had the same results.
By: Skrol29
Date: 2013-06-28
Time: 00:05

Re: East Asian Characters and MS Word using MergeBlock not working

I need few days to reply. I'll be back after the weekend.
By: Skrol29
Date: 2013-07-01
Time: 23:08

Re: East Asian Characters and MS Word using MergeBlock not working

Hi Dee Dee,

I must say I cannot reproduce your problem.

I have a small code that does the same as yours except that it does
  $txt = file_get_contents('test.txt');
instead of
  $xml = simplexml_load_string($xmlString);

And all is running as expected.
So I guess the problem can comes from you $xml object that may not work as you can expect.
By: Dee Dee
Date: 2013-07-02
Time: 03:53

Re: East Asian Characters and MS Word using MergeBlock not working

Thanks for troubleshooting that for me.  I am glad to know that OpenTBS will work with this once I figure out the xml translation problem.