Skrol29 / opentbs

With OpenTBS you can merge OpenOffice - LibreOffice and Ms Office documents with PHP using the TinyButStrong template engine. Simple use OpenOffice - LibreOffice or Ms Office to edit your templates : DOCX, XLSX, PPTX, ODT, OSD, ODP and other formats. That is the Natural Template philosophy.
http://www.tinybutstrong.com/opentbs.php
70 stars 17 forks source link

Exchange images using MergeBlock() #29

Closed Eskapone36 closed 1 year ago

Eskapone36 commented 1 year ago

Hi, I am having trouble exchanging images using the MergeBlock() function. Maybe I am not using it correct or I'm missing something, not exactly sure, please see my example below.

include_once('tinybutstrong/tinybutstrong/tbs_class.php');
include_once('tinybutstrong/opentbs/tbs_plugin_opentbs.php');

$tinyButStrong = new clsTinyButStrong();
$tinyButStrong->PlugIn(TBS_INSTALL, OPENTBS_PLUGIN);
$tinyButStrong->LoadTemplate("test.docx", OPENTBS_ALREADY_UTF8);
echo time() . "</br>Before:</br><textarea rows='35' cols='200'>" . $tinyButStrong->Source . "</textarea>";
$pics = [["pics" => "test.png"]];
$blockSrc = $tinyButStrong->GetBlockSource("block1");
$tinyButStrong->MergeBlock(
    "block1",
    $pics
);

echo "</br>After:</br><textarea rows='35' cols='200'>" . $tinyButStrong->Source . "</textarea>";
$tinyButStrong->Show(OPENTBS_FILE, "test.docx");

template.docx: template.docx test.png: test

Used versions: php: 8.1.8 opentbs: 1.10.7

When comparing the BlockSource before and after the MergeBlock() call, you can see that tbs does not replace correct and corrupts the file contents.

Any help or conclusion is well appreciated, thanks in advance.

(works just fine with php 7.2 & opentbs 1.9.4)

Skrol29 commented 1 year ago

You are inserting HTML contents in DOCX which is XML under the OpenXML format. This is not supposed to work.

Eskapone36 commented 1 year ago

Hi, thanks for your answer but inserting HTML is not what I'm doing there. The HTML data you see in my snippet are merely debug prints to see the file contents before and after the replacement takes place. What I am trying to replace is the content of 'block1.pics' with 'test.png'.

Skrol29 commented 1 year ago

Hi, You're right, I can reproduce the bug. I'm working on it...

Skrol29 commented 1 year ago

The bug is fixed in the new release OpenTBS version 1.11.2. It was a complicated bug, thank you for your patience.