# Dolibarr v.13 prints special characters in .odt files

**URL:** <https://www.dolibarr.org/forum/t/dolibarr-v-13-prints-special-characters-in-odt-files/20199>\
**Category:** Using my Dolibarr\
**Created:** [January 31, 2021, 2:25pm UTC](https://www.dolibarr.org/forum/t/dolibarr-v-13-prints-special-characters-in-odt-files/20199 "2021-01-31T14:25:14Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dido](https://www.dolibarr.org/forum/letter_avatar_proxy/v4/letter/d/87869e/32.png) [@Dido](https://www.dolibarr.org/forum/u/Dido)\
**Post date:** [January 31, 2021, 2:25pm UTC](https://www.dolibarr.org/forum/t/dolibarr-v-13-prints-special-characters-in-odt-files/20199/1 "2021-01-31T14:25:14Z")

</div>

Hi dears,  
after installing v.13 all generated .odt documents contains special characters from tags like

   
·&nbsp;&nbsp; and others. It was working fine in previous versions v.12 and oldest

Is there any setting for Other Setup?  
I have more than 500 products and have to change them manually.  
Awaiting your advise…

---

<div class="post-metadata">

**Author:** ![simmer](https://www.dolibarr.org/forum/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@simmer](https://www.dolibarr.org/forum/u/simmer)\
**Post date:** [February 1, 2021, 4:26pm UTC](https://www.dolibarr.org/forum/t/dolibarr-v-13-prints-special-characters-in-odt-files/20199/2 "2021-02-01T16:26:02Z")

</div>

I’ve also had issues with generating invoices with .odt templates. I downgraded to 12.0.4 and reported a bug at Github

---

<div class="post-metadata">

**Author:** ![Dido](https://www.dolibarr.org/forum/letter_avatar_proxy/v4/letter/d/87869e/32.png) [@Dido](https://www.dolibarr.org/forum/u/Dido)\
**Post date:** [February 1, 2021, 4:39pm UTC](https://www.dolibarr.org/forum/t/dolibarr-v-13-prints-special-characters-in-odt-files/20199/3 "2021-02-01T16:39:52Z")

</div>

Dear Simmer,  
is it working fine again after downgrading to v. 12.0.4?

---

<div class="post-metadata">

**Author:** ![simmer](https://www.dolibarr.org/forum/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@simmer](https://www.dolibarr.org/forum/u/simmer)\
**Post date:** [February 1, 2021, 4:51pm UTC](https://www.dolibarr.org/forum/t/dolibarr-v-13-prints-special-characters-in-odt-files/20199/4 "2021-02-01T16:51:53Z")

</div>

for me it works. I’m looking forward to the 13.0.1 where hopfully those bugs are fixed

---

<div class="post-metadata">

**Author:** ![Dido](https://www.dolibarr.org/forum/letter_avatar_proxy/v4/letter/d/87869e/32.png) [@Dido](https://www.dolibarr.org/forum/u/Dido)\
**Post date:** [February 23, 2021, 3:58pm UTC](https://www.dolibarr.org/forum/t/dolibarr-v-13-prints-special-characters-in-odt-files/20199/5 "2021-02-23T15:58:16Z")

</div>

Hello all,  
I try today v 13.0.1 with .odt, but it is not fixed yet.  
Continue printing special characters in simple text.  
like that

════════════════════════════════════  
  
Broadcast Video/Audio I/O :  
  
· Dual Port Gigabit Adapter  
  
════════════════════════════════════  
  
1RU Rackmount Server  
  
Redundant (1 + 1) PSU  
  
Single Intel® CPU;  
  
Two (2) Gigabit Ethernet ports;  
  
System HDDs with RAID 1;  
  
Video Storage: 4TB SATA with RAID5;  
  
OS: Microsoft Windows 10

· Fixes, Maintenance Patches, Software Updates and New Features included  
  
· Critical Cases Handled with Priority  
  
· Remote Access to the Systems by our Broadcast Engineers  
  
· 24/7 Global Customer Care Center

---

<div class="post-metadata">

**Author:** ![Dido](https://www.dolibarr.org/forum/letter_avatar_proxy/v4/letter/d/87869e/32.png) [@Dido](https://www.dolibarr.org/forum/u/Dido)\
**Post date:** [February 23, 2021, 4:01pm UTC](https://www.dolibarr.org/forum/t/dolibarr-v-13-prints-special-characters-in-odt-files/20199/6 "2021-02-23T16:01:49Z")

</div>

![image](https://www.dolibarr.org/forum/uploads/dolibarrorg/original/2X/9/92deafb991c56417a4961ba8c430ae9764df2ba9.jpeg)

---

<div class="post-metadata">

**Author:** ![Dido](https://www.dolibarr.org/forum/letter_avatar_proxy/v4/letter/d/87869e/32.png) [@Dido](https://www.dolibarr.org/forum/u/Dido)\
**Post date:** [March 18, 2021, 10:39am UTC](https://www.dolibarr.org/forum/t/dolibarr-v-13-prints-special-characters-in-odt-files/20199/7 "2021-03-18T10:39:31Z")

</div>

Hi all,  
today upgraded to 13.02  
but odt generation is still with html charecters instead of normal text.  
Try to downgrade to 12.05 but after downgrade too many error messages appears on some of menus.  
Please try to fix this in next release.

---

<div class="post-metadata">

**Author:** ![Dido](https://www.dolibarr.org/forum/letter_avatar_proxy/v4/letter/d/87869e/32.png) [@Dido](https://www.dolibarr.org/forum/u/Dido)\
**Post date:** [July 31, 2021, 1:50pm UTC](https://www.dolibarr.org/forum/t/dolibarr-v-13-prints-special-characters-in-odt-files/20199/8 "2021-07-31T13:50:14Z")

</div>

Hello developers team!  
Thanks for releasing Dolibarr v14.0  
I try it, but in .odt templates again prints HTML for special characters.  
I can’t use my odt templates for generating documents.  
Is there any workaround?

---

<div class="post-metadata">

**Author:** ![crisgua](https://www.dolibarr.org/forum/letter_avatar_proxy/v4/letter/c/e5b9ba/32.png) [@crisgua](https://www.dolibarr.org/forum/u/crisgua)\
**Post date:** [October 18, 2021, 9:18am UTC](https://www.dolibarr.org/forum/t/dolibarr-v-13-prints-special-characters-in-odt-files/20199/9 "2021-10-18T09:18:50Z")

</div>

Hello I’ve the same issue…I can’t use my odt templates for generating documents.  
Is there any workaround? Dolibarr vers. 14.0.2  
Thank You

---

<div class="post-metadata">

**Author:** ![playcock](https://www.dolibarr.org/forum/user_avatar/www.dolibarr.org/playcock/32/6009_2.png) [@playcock](https://www.dolibarr.org/forum/u/playcock)\
**Post date:** [March 7, 2022, 5:04pm UTC](https://www.dolibarr.org/forum/t/dolibarr-v-13-prints-special-characters-in-odt-files/20199/10 "2022-03-07T17:04:54Z")

</div>

Someone reported the issue on github.

[# Probleme with line ODT generation](https://github.com/Dolibarr/dolibarr/issues/16184)

There was a workaround reported in the thread that will strip the html tags and insert line breaks where intended, but stripping the html tags: you lose any design you wanted like bolded and underlined characters. To me, that is still a problem.

The issue is in open status, so hopefully someday someone will be able to address this.

---

<div class="post-metadata">

**Author:** ![playcock](https://www.dolibarr.org/forum/user_avatar/www.dolibarr.org/playcock/32/6009_2.png) [@playcock](https://www.dolibarr.org/forum/u/playcock)\
**Post date:** [March 7, 2022, 8:18pm UTC](https://www.dolibarr.org/forum/t/dolibarr-v-13-prints-special-characters-in-odt-files/20199/11 "2022-03-07T20:18:49Z")

</div>

I posted to the github open issue and am hoping that the issue is not so old that it gets missed. 🤞

I am trying to intercept the template values using the `odtgeneration` hook initialized by `doc_generic_proposal_odt.modules.php`. I can all of the following in my hook function called `public function ODTSubstitution`, but no matter what I do, I cannot manipulate the variable values so that they get passed back to the ODT template file with the correct ODT styles.

I have even added the following functions to my actions class in my custom module and I can step through them just fine, but after the hook is finished, nothing happens to the variables and the ODT file ends up printing out the `htmlspecialchars` anyways:

`setVars`  
`convertVarToOdf`  
`_hasHtmlTag`  
`_replaceHtmlWithOdtTag`  
`_getDataFromHtml`

I figured that if I could prevent the variables from being returned to the ODT file without `htmlspecialchars` that would at least allow me to print out variables that are bolded, underlined, and italicized. Upon that being a success, then maybe I can write in some more ODT styles to handles things like lists and text colors or whatever.

Is the reason why I cannot return the manipulated variables to ODT templates because $reshook is not being handled properly in `doc_generic_proposal_odt.modules.php` like the following?  
`if ($reshook < 0)`  
`if ($reshook == 1)`

I shared some more thoughts on GitHub:

> The public function convertVarToOdf($value, $encode = true, $charset = ‘ISO-8859’) odf.php has nothing wrong with it. It’s just that every time -\>setVars is called, it passes the enocde value as true. At least in doc\_generic\_odt\_modules.php
> 
> Example:  
> `->setVars($key, $val, true, 'UTF-8');`
> 
> There is nothing that you can do to pass encode as false when generating ODT documents. We have tried hooks quite extensively and still cannot get the Dolibarr system to bend so that the substitution variables get passwed with $encode = false.
> 
> We know it’s an issue in Dolibarr and we don’t want to modify the core.

> If the hook functionality would allow us to work with ODT generation and allow us to intervene to set $encode = false and to even add more html tags to covert to ODT, that would be ideal.

---

<div class="post-metadata">

**Author:** ![playcock](https://www.dolibarr.org/forum/user_avatar/www.dolibarr.org/playcock/32/6009_2.png) [@playcock](https://www.dolibarr.org/forum/u/playcock)\
**Post date:** [March 9, 2022, 3:45pm UTC](https://www.dolibarr.org/forum/t/dolibarr-v-13-prints-special-characters-in-odt-files/20199/12 "2022-03-09T15:45:41Z")

</div>

* * *

## **Updated Progress**

I implemented a workaround on my sandbox so that I can apply the styles to the text for strong/b, i/em, u, s, sub & sup instead of displaying the HTML tags.

I created a custom module and used the Dolibarr Module Builder to create the actions class, then I made it an extension of ModelePDFPropales.

Before the class declaration, I am requiring /core/modules/propale/modules\_propale.php

My custom module is called documenttemplates and this is the syntax I am using to do the aforementioned:

```auto
require_once DOL_DOCUMENT_ROOT.'/core/modules/propale/modules_propale.php';

/**

* Class ActionsDocumentTemplates

*/

class ActionsDocumentTemplates extends ModelePDFPropales

```

Inside the class I implemented the afterODTCreation hook function

```auto
/* Add here any other hooked methods... */

public function afterODTCreation($parameters, &$object, &$action, $hookmanager)

{

global $langs;
$outputlangs = $langs;
require_once DOL_DOCUMENT_ROOT.'/core/modules/propale/modules_propale.php';

$srctemplatepath = DOL_DATA_ROOT . '/doctemplates/proposals/key_mapping.odt';

ob_clean(); // required so that you don't receive PHP Warning: Cannot modify header information

$this->write_file($parameters['object'], $outputlangs, $srctemplatepath);
return 0;
}

```

Then I duplicated the following functions from htdocs/core/modules/propale/doc/doc\_generic\_proposal\_odt.modules.php

> write\_file
> 
> setVars
> 
> convertVarToOdf
> 
> \_hasHtmlTag
> 
> \_replaceHtmlWithOdtTag
> 
> \_getDataFromHtml

In the write\_file function, I made sure that $encode is false whenever setVars is called.

Example:  
`$odfHandler->setVars($key, $value, false, 'UTF-8');`

I also commented out the executeHooks in the write\_file function I duplicated so that I do not risk going into an endless hook loop when generating an ODT file.

What this hook functionality does is that it generates the ODT file as normal with the unwanted HTML tags displayed in the file. Then when the ODT file is finished generated, the hook regenerates the ODT file with the styled text in the ODT files instead of the unwanted HTML tags.

I do have one more issue I am trying to figure out and that is how to get the $srctemplatepath dynamically because right now it is hardcoded which limits the ODT file generation to one template. I want to be able to accommodate whatever ODT template the Dolibarr users selects from the dropdown.

---

<div class="post-metadata">

**Author:** ![farneyaurelio](https://www.dolibarr.org/forum/user_avatar/www.dolibarr.org/farneyaurelio/32/6313_2.png) [@farneyaurelio](https://www.dolibarr.org/forum/u/farneyaurelio)\
**Post date:** [July 26, 2022, 3:40pm UTC](https://www.dolibarr.org/forum/t/dolibarr-v-13-prints-special-characters-in-odt-files/20199/13 "2022-07-26T15:40:01Z")

</div>

hello playcock,

I have this problem on my Dolibarr (V15.0.2). Look at this post: [Problem with character special in odt](https://www.dolibarr.org/forum/t/problem-with-character-special-in-odt/22180)

I understand you managed to develop a workaround. However, your level of programming knowledge is much higher than mine. Would it be possible to make this module available for download and installation in a simple way and without programming?

My fear is to mess up Dolibarr’s programming and lose my CRM.
