Dolibarr v.13 prints special characters in .odt files

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


·   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…

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

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

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

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

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.

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?

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

Someone reported the issue on github.

# Probleme with line ODT generation

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.

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

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.


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:

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

/* 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.

hello playcock,

I have this problem on my Dolibarr (V15.0.2). Look at this post: Problem with character special in odt

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.