Categories > OpenTBS with ODT >

Newbie problems

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Amok
Date: 2014-12-22
Time: 15:59

Newbie problems

Hi there!

I'm trying to use OpenTBS in order to populate a Libre Office .odt file from an html form. Oddly enough, I cannot make it work properly. I  took a look of the demo .php and template, but it just doesn't seem to work for me. The problem is, the generated .odt contains nothing but funny characters  that I assume to be the representation of a binary file. Funny enough, if I echoed some of the variables retrieved with $_POST from the form, the generated .odt show them perfectly. My experience programming is quite limited, so please be patient. That's how my code looks like:

      include_once('../../librerias/tbs_us/tbs_class.php');
      include_once('../../librerias/open_tbs/tbs_plugin_opentbs.php');

      $TBS = new clsTinyButStrong;
      $TBS->Plugin(TBS_INSTALL, OPENTBS_PLUGIN);

      $template= 'plantillas/denuncia/2Apertura.odt';  
      $TBS->LoadTemplate($template,OPENTBS_ALREADY_UTF8);

      $filename = 'a_apertura.odt';  
      $TBS->Show(OPENTBS_DOWNLOAD,$filename);

Note that i don't even tried to merge any data (save for the accidental echo issue).
By: Skrol29
Date: 2014-12-23
Time: 01:41

Re: Newbie problems

Hi Amok,

This may happen if your PHP script send some content before the end of the merging.
It can be one of your echo() command, or maybe a PHP notice.

I suggest that use use the OpenTBS debug mode.
See http://www.tinybutstrong.com/opentbs.php?doc#debugmode
By: Amok
Date: 2014-12-23
Time: 09:45

Re: Newbie problems

Ok, thnaks a lot. I will try that.
But I have another silly doubt: is it required to have Open Office or Libre Office installed on server side?
By: Skrol29
Date: 2014-12-23
Time: 10:39

Re: Newbie problems

> is it required to have Open Office or Libre Office installed on server side?

Not at all.
OpenTBS works only by extracting XML from the documents, modify them, and put them back in the document.
By: Amok
Date: 2014-12-23
Time: 13:27

Re: Newbie problems

The Debug output looks like this:

* OPENTBS DEBUG MODE: if the star, (*) on the left before the word OPENTBS, is not the very first character of this page,
then your merged Document will be corrupted when you use the OPENTBS_DOWNLOAD option. If there is a PHP error message,
then you have to fix it. If they are blank spaces, line beaks, or other unexpected characters, then you have to check your code
in order to avoid them. ------------------------------ INFORMATION ------------------------------ * Debug command:
OPENTBS_DEBUG_XML_CURRENT * OpenTBS version: 1.9.2 * TinyButStrong version:3.9.0 * PHP version: 5.2.0-8+etch16YES
* Opened document: plantillas/denuncia/2Apertura_.odt * Activated features for document type: odf/odt * Deleted files in the
archive: none * Added files in the archive: none * Modified files in the archive: - styles.xml - content.xml
------------------------------ File merged with OpenTBS (XML reformated for debuging only): styles.xml ------------------------------
Policía Local Udaltzaingoa Atestado nº: Folio n°:____ Policía Local ------------------------------ File merged with
OpenTBS (XML reformated for debuging only): content.xml ------------------------------ APERTURA DE ATESTADO POR
DENUNCIA DE LESIONES ____________________________________________________________________ Los Agentes con números
de carnet profesional 033 y 066 , pertenecientes a la Policía Local, como componentes del Equipo Instructor de las presentes
diligencias hacen CONSTAR : Que a las 22:00 horas del día 10/1/2015 , se personó en las Dependencias de esta Policía Local
D/Dña. Pedro Pablos , con D.N.I. N° 555555555 , quien formula denuncia por la presunta comisión de un delito de
Lesiones A partir de ese instante se procede a realizar la correspondiente investigación y práctica de las diligencias oportunas,
para el esclarecimiento de los hechos y la identificación del autor/es del mismo. Y para que conste, se extiende la presente
diligencia que es firmada por el Equipo Instructor. Fdo. El Equipo Instructor

All seems to be ok, despite the typical php encoding issue, and the fact that there are no line breaks (I formatted the output myself a bit in order to post it here). The [onload] fields are correctly merged. Anyway, the 'save as' dialog doesn't appears (surprisingly, in my personal laptop that dialog DO appears, so maybe it is related to some PHP config file), and the TBS->Show just prints the same bucket of random characters.
By: Skrol29
Date: 2014-12-24
Time: 01:32

Re: Newbie problems

Ok.

You have also to check if your PHP script is a UTF-8 encoded, not ANSI.
Also check that your script is actually ending after the $TBS->Show() command. You can add an exit() in order to ensure the script is ending.

If the problem is not gone, then you have to open the result ODT file with a text editor or hexa editor and whatch the star and the ending to see if there is some XML or HTML contents.

If the problem is not gone, you can send you ODT result to me.
By: Amok
Date: 2015-02-17
Time: 09:41

Re: Newbie problems

I've solved the encoding issue (it was a silly mistake by me, as I was not using the php header() function in the very first line of the .php files to enforce UTF-8). Anyway, OpenTBS still doesn't work. I'll send you my .odt file as soon as I can.

Thank you very much.
By: Amok
Date: 2015-03-06
Time: 09:51

Re: Newbie problems

Problems solved, thanks to Skrol29.
Be careful of keeping the brackets and the text inside [onload.whatever] in the same format (font, etc). That was my mistake.
Also, on TBS->Show() calling, you cannot use a string to pass the show mode parameter. See:

$showmode="OPENTBS_DOWNLOAD";
$filename="myfile.odt";
openTBS->Show($showmode,$filename);

This code above won't work at all. You need to pass the $showmode parameter not as an string, and directly the function call:

$filename="myfile.odt";
openTBS->Show(OPENTBS_DOWNLOAD,$filename);

Now it works. That was a major flaw in my code...
By: Skrol29
Date: 2015-03-06
Time: 16:39

Re: Newbie problems

OK, thanks for this feed back.