Forum


Replies: 10   Views: 4107
Utf8 support
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by nachtschicht  · 13-03-2012 - 09:00

Hi,

this Problem is probably related to the "escape problem": http://www.phpdocx.com/forum?vasthtmlaction=viewtopic&t=148.00

Environment:
Eclipse - UTF8 set as default, and is confirmed to be inherited for the relevant files.
Server - Debian Linux with all locales set to UTF8
-> Other UTF8 content is displayed without any problems e. g. using PHPexcel

Setup:
[php]
$docx = new CreateDocx();
$docx->setEncodeUTF8();

// TEST
$docx->addText("öööööäääääßßßßß", $this->docx_params_Text_h1);
[/php]

The special (german-) chars are not displayed as they should be:

öööööäääääßßßßß

Can you please check the setEncodeUTF8() function and provide a patch if needed.

Posted by admin  · 11-04-2013 - 12:13

Hello,

Could you try removing setEncodeUTF8 method?. If your file is already on UTF8, you don't need to use setEncodeUTF8.

Regards.

Posted by nachtschicht  · 11-04-2013 - 12:13

OK, you should really document that... After not using that setting the german special chars are working well. I'll do some testing with other special chars in the next week and let you know.

Posted by admin  · 11-04-2013 - 12:13

Hello,

It's a problem related to utf8_encode function of PHP. We'll check if we can improve it using iconv or other function.

Regards.

Posted by js  · 11-04-2013 - 12:13

Hi,

I am facing a problem which seem to be related to the original one in that post. System environment is fully UTF8 compliant and other parts of the system are woring with UTF8 as expected (e. g. PHPexcel). I am using PHPdocx v2.6 pro.

When I create a docx file using a template like that:
[code]
$docx = new CreateDocx();
// Set Encoding
// $docx->setEncodeUTF8();
// Add Template
$docx->addTemplate('template_files/001.docx');

$docx->addTemplateVariable('MYVAR01', $params['MYVAR01']);

...
[/code]
German Umlauts like äüö are displayed as they should. However when I add some japanese chars like "おはようございます! " they look like that: "おはようございます!" in the docx file.
If I enable the setEncodeUTF8() function the German Umlauts are no longer displayed in the right way and the above chars look like that: "おはようございます!"

Any suggestions / howto's on that topic which explain how to use UTF8 chars within phpdocx would be helpfull.

Posted by admin  · 11-04-2013 - 12:13

Hello,

Please contact us, we'd like to test your template.

Regards.

Posted by js  · 11-04-2013 - 12:13

Hi,

I can also reproduce it using a plain vanilla template which has just one var in it: [url]http://www.security-blog.eu/wp-content/uploads/2012/11/test.docx[/url]

The chars are displayed in the right way if I create the file using phpdocx (without a template). It must therefore be related to the way phpdocx handels the templates.

Posted by admin  · 11-04-2013 - 12:13

Hello,

We've checked your issue and it's due to your font. MS Office and OpenOffice in Windows and Linux open that document fine, showing japanese chars, but if you use a version or OS that don't support that chartset then they won't be displayed right.
The best solution is to use a font that has full charset support when you create your template.

Regards.

Posted by js  · 11-04-2013 - 12:13

Hi,

sorry didn't had the time to test that until now. I was not able to get that working. Which font would you recommend to use? The default font for my test document was Arial or Calibri using Office 2010 on a win 7 (x64) PC.

Furthermore, I am now also facing charset issues in another function. The template is a plain vanilla word document which just contains the var $ITEMS$ ([url]http://www.security-blog.eu/wp-content/uploads/2013/01/LOR_TEST.docx[/url]). This document is called from the following function:
[code]
public function GenerateLoR_mytest() {
$style_base = "font-family:Arial; word-break: break-all; border-width:1px; border-color:black; border-style:solid; border-collapse:collapse; ";

$docx = new CreateDocx();
$docx->addTemplate('template_files/LOR_TEST.docx');
$items = "<table width=\"100%\" style=\"".$style_base."\">";
$items .= "<tr>";
$items .= "<td style=\"".$style_base."width:44pt; background-color: #CCCCCC; font-size:9pt;\">ÄÖÜäöü</td>";
$items .= "</tr>";
$items .= "</table>";
$docx->replaceTemplateVariableByHTML('ITEMS', 'block', $items, array('isFile' => false, 'parseDivsAsPs' => true, 'downloadImages' => false));

$path = $this->NewPath();
$docx_name = $GLOBALS['t']->t("DOCX_LOR_PATH_PREFIX").date('Ymd')." ".$GLOBALS['t']->t("DOCX_LOR_PATH_SUFIX");
$paramsDocument = array(
'orient' => 'landscape'
);
$docx->createDocx($path['full_path'].$docx_name, $paramsDocument);

return $path['download_path'].$docx_name.".docx";

}
[/code]

The german umlauts (ÄÖÜäöü) are again not displayed as they should. See resulting document: [url]http://www.security-blog.eu/wp-content/uploads/2013/01/LOR_TEST.docx[/url] PHPDOCX v3.0 Pro is already installed.

Posted by js  · 11-04-2013 - 12:13

Any idea how to fix that?