TinyButStrong - the PHP Template Engine
Categories > OpenTBS with DOCX >

Error Replacing picture on a template that had other picture replaced already.

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs

By: PACh
Date: 2017-04-01
Time: 11:48

Error Replacing picture on a template that had other picture replaced already.

Good morning,
I have a PHP function that replaces a white jpg picture with a codebar jpg picture, it works good but now I want to replace a second picture on the same docx file so I added a second empty picture a transparent png.
The process goes like this:
The docx template have the 2 pictures since the beginning (1 blank jpg and 1 transparent png) in one function it replace the blank picture with a codebar picture, then the user add some content to it and at the end it request a signature so other function replaces the transparent png picture with a signature picture.
The problem is that in the second function, the 2nd picture ist replaced with the codebar picture instead of the signature picture and I get a corrupted docx that can be opened after repairing it...
when I open the file with 7-zip I see the 2 pictures on the folder word/media so the signature picture is loaded correctly and each have a different name I don't understand why it replaces the 2nd picture with the codebar picture instead of the signature picture, even one is a jpg and the other is a png...
something funny.... if after replacing the first picture I edit the document and add again a description to the codebar picture (it gets deleted when the white picture is replaced) it works fine......

code of the first function (replacing the white jpg with a codebar jpg:

                     App::import('Vendor', 'tbs/tbs_class');
                     App::import('Vendor', 'tbs/tbs_plugin_opentbs');
                     $TBS = new clsTinyButStrong;
                     $TBS->Plugin(TBS_INSTALL, OPENTBS_PLUGIN);
                     $TBS->LoadTemplate('D:'.$plantilla);
                     $prms = array('as' => 'firma.jpg', 'unique' => true);
                     $TBS->Plugin(OPENTBS_CHANGE_PICTURE, 'bar_code', 'D:/RegistroDocumentos/salientes/barcode/code_'.$this->Session->read('L_Usuario.id').'.jpg', $prms);
                     $TBS->Show(OPENTBS_FILE, $newdoc_path);
                     $TBS->LoadTemplate(false);

code of the second function replacing the transparent png with the signature transparent:

                         App::import('Vendor', 'tbs/tbs_class');
                         App::import('Vendor', 'tbs/tbs_plugin_opentbs');
                         $TBS = new clsTinyButStrong;
                         $TBS->Plugin(TBS_INSTALL, OPENTBS_PLUGIN);
                         $TBS->LoadTemplate('D:'.$plantilla);
                         $prms = array('as' => 'firmado.png', 'unique' => true);
                         $TBS->Plugin(OPENTBS_CHANGE_PICTURE, '#firma_empty#', $tipo_firma, $prms);
                         //$TBS->PlugIn(OPENTBS_DEBUG_XML_SHOW);
                         $TBS->Show(OPENTBS_FILE, $newdoc_path);
                         $TBS->LoadTemplate(false);

Thank you in advance for any help

Best regards
By: PACh
Date: 2017-04-01
Time: 15:17

Re: Error Replacing picture on a template that had other picture replaced already.

I found the problem, open_tbs creates consecutive numbers on the Relationship Id="opentbs1" based on the amount of pictures on that particular process, if you make other process later, it will start from 1 again creating a duplicate Relationship Id. I modified the code on tbs_plugin_opentbs.php on line nr. 2663:    $NewRid = 'opentbs'. mt_rand(1, 99).mt_rand(1, 99); so it generates a randon number eachtime. maybe is not a perfect solution but it works, maybe developers can make something more elegant.
By: Skrol29
Date: 2017-04-03
Time: 16:02

Re: Error Replacing picture on a template that had other picture replaced already.

Hello,

This is intersting. Do you mean you are merging a DOCX template which is the result of a first merging ? ?
By: PACh
Date: 2017-04-03
Time: 16:12

Re: Error Replacing picture on a template that had other picture replaced already.

yes, I do 2 merges. On the first merge I replace the blank .jpg with a codebar jpg then later I do a second merge to replace the transparent .png with a signature .png