TinyButStrong with OpenTBS and custom file

Morning All.I am currently trying to get TinybutStrong working with OpenTBS and a template in .docxI have created a custom file to get started to work the code in. the template is a basic docx file with only 2 words in it. So far I can create a “corrupt” downloadable file even if I don’t merge any data.

here is the code from:

<?php
//TBS activate;
	$TBS = new \clsTinyButStrong();
	$ok = class_exists('clsOpenTBS', true);
	$TBS->Plugin(TBS_INSTALL, OPENTBS_PLUGIN);
// Page object
	$cur = '1';
// Tempalte
	$template = 'company.docx';  
//debug;
	$TBS->LoadTemplate($template, OPENTBS_ALREADY_UTF8); // Also merge some [onload] automatic fields (depends of the type of document).
// Merge object
	$TBS->MergeField('a1',$cur);
// Debug comments
	//$TBS->Plugin(OPENTBS_DEBUG_XML_CURRENT, true); $TBS->Plugin(OPENTBS_DEBUG_INFO, true); $TBS->Plugin(OPENTBS_DEBUG_XML_SHOW); 
// Download object
	$TBS->Show(OPENTBS_DOWNLOAD, 'test.docx');
?>

When I debug the output I get the following:

* 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.10.7
  • TinyButStrong version: 3.14.0
  • PHP version: 8.2.0YES
  • Opened document: company.docx
  • Activated features for document type: openxml/docx
  • Deleted files in the archive: none
  • Added files in the archive: none
  • Modified files in the archive:word/document.xml

File merged with OpenTBS (XML reformated for debuging only): word/document.xml

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<w:document xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:cx="http://schemas.microsoft.com/office/drawing/2014/chartex" xmlns:cx1="http://schemas.microsoft.com/office/drawing/2015/9/8/chartex" xmlns:cx2="http://schemas.microsoft.com/office/drawing/2015/10/21/chartex" xmlns:cx3="http://schemas.microsoft.com/office/drawing/2016/5/9/chartex" xmlns:cx4="http://schemas.microsoft.com/office/drawing/2016/5/10/chartex" xmlns:cx5="http://schemas.microsoft.com/office/drawing/2016/5/11/chartex" xmlns:cx6="http://schemas.microsoft.com/office/drawing/2016/5/12/chartex" xmlns:cx7="http://schemas.microsoft.com/office/drawing/2016/5/13/chartex" xmlns:cx8="http://schemas.microsoft.com/office/drawing/2016/5/14/chartex" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:aink="http://schemas.microsoft.com/office/drawing/2016/ink" xmlns:am3d="http://schemas.microsoft.com/office/drawing/2017/model3d" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:oel="http://schemas.microsoft.com/office/2019/extlst" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:w16cex="http://schemas.microsoft.com/office/word/2018/wordml/cex" xmlns:w16cid="http://schemas.microsoft.com/office/word/2016/wordml/cid" xmlns:w16="http://schemas.microsoft.com/office/word/2018/wordml" xmlns:w16sdtdh="http://schemas.microsoft.com/office/word/2020/wordml/sdtdatahash" xmlns:w16se="http://schemas.microsoft.com/office/word/2015/wordml/symex" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" mc:Ignorable="w14 w15 w16se w16cid w16 w16cex w16sdtdh wp14" xml:space="preserve">
 <w:body>
  <w:p w14:paraId="6A442145" w14:textId="77777777" w:rsidRDefault="007A45E1" w:rsidP="007A45E1">
   <w:r>
    <w:t>
     Hello 1,
    </w:t>
   </w:r>
  </w:p>
  <w:p w14:paraId="3D6C9D11" w14:textId="77777777" w:rsidRDefault="00192B52"/>
  <w:sectPr>
   <w:pgSz w:w="12240" w:h="15840"/>
   <w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440" w:header="720" w:footer="720" w:gutter="0"/>
   <w:cols w:space="720"/>
   <w:docGrid w:linePitch="360"/>
  </w:sectPr>
 </w:body>
</w:document>

I have had to have the line in of
$ok = class_exists(‘clsOpenTBS’, true);
else I get an error about the plugin for OpenTBS "Undefined constant “PHPMaker2023\medeea\OPENTBS_PLUGIN”"any ideas are welcome.

CraigNel wrote:

I have had to have the line in of
$ok = class_exists(‘clsOpenTBS’, true);
else I get an error about the plugin for OpenTBS “Undefined constant “PHPMaker2023\medeea\OPENTBS_PLUGIN””


  1. You should add tinybutstrong/opentbs by Tools → Composer Packages.
  2. You should not use Custom Files to output file. If you must, you’d better use the Page_Load or Page_Render server event to output and then exit the page there (so no HTML output). If you put the code in the “View” (you use Include common files and put your code in the Content), the output contains some default HTML output from the “View” of the page. The preferred approach is to use custom API action, see Create Your Own API Action, simply move your code inside the handler of your action.