0

Is there a way to access docx properties once an OpenTBS template is loaded?

$TBS->LoadTemplate($template, OPENTBS_ALREADY_UTF8);

I know that I could open the docx as a zip, access core.xml in docProps and parse the content to find for instance the document title. There are also helper libraries that do this but it would be cleaner to do it using TBS.

Many thanks in advance.

Toto
  • 89,455
  • 62
  • 89
  • 125
Marco
  • 1

3 Answers3

0

Command OPENTBS_EDIT_ENTITY is done for that purpose.

See the doc

Skrol29
  • 5,402
  • 1
  • 20
  • 25
  • I saw the doc before asking but it seems that the command cannot read the current value . I need to retrieve the value first and set a different value based on the template value. – Marco Sep 15 '21 at 12:12
  • Do you know how to target a specific "content" in the docx, not related to his position ? in other words, can we name "blocks" in the docx and read them based on this name ? i only see path in the function – Micbol12 Nov 26 '21 at 15:12
  • @Micbol12 do you mean "TBS blocks" ? – Skrol29 Nov 27 '21 at 21:54
0

I have been able to retrieve the title property as follows. Is there a better way?

$TBS->LoadTemplate($template . "#docProps/core.xml", OPENTBS_ALREADY_UTF8);
$xml = new SimpleXMLElement($TBS->Source);
$xml = dom_import_simplexml($xml);
$nodelist= $xml->getElementsByTagName('title');
$node = $nodelist[0];
$title = $node->nodeValue;
Ryan M
  • 18,333
  • 31
  • 67
  • 74
Marco
  • 1
0

Since OpenTBS version 1.10.3 (which has just been released) there is a new command OPENTBS_READ_ENTITY.

Thank you for suggesting this feature. The internal functions were already there.

Skrol29
  • 5,402
  • 1
  • 20
  • 25