Categories > OpenTBS general >

Using OpenTBS can i remove the image form a template when picture file does not exist?

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Meri van Buuren
Date: 2015-06-09
Time: 15:45

Using OpenTBS can i remove the image form a template when picture file does not exist?

Hello,

I have a odt template with an default image, i need to merge this with an image from my filesystem.

The template is loaded like this:
$TBS_document = new clsTinyButStrong;
$TBS_document->NoErr = TRUE;
$TBS_document->Plugin(TBS_INSTALL, OPENTBS_PLUGIN);
$TBS_document->LoadTemplate($template_file, OPENTBS_ALREADY_UTF8);   -> $template_file holds the template file

The default image in my template has in de discription field a tag: [block.signature]
I do the merge with $TBS_document->PlugIn(OPENTBS_CHANGE_PICTURE, '[block.signature], '/tmp/signature.png' ,array('unique' => true));

After merging:
$TBS_document->Show(OPENTBS_FILE, $filename); -> $filename hold de merged file name

If that image from my filesystem does not exist I need to remove the default image from my template.
How do i do that?

By: Skrol29
Date: 2015-06-10
Time: 10:19

Re: Using OpenTBS can i remove the image form a template when picture file does not exist?

Hi,

The field "[block.signature]" has probably been merged before when you have performed the MergeBlock() for "block".

Use another keyword instead.
For example, use "here_is_my_signature"
and do
$TBS_document->PlugIn(OPENTBS_CHANGE_PICTURE, 'here_is_my_signature', '/tmp/signature.png' ,array('unique' => true));
By: Meri van Buuren
Date: 2015-06-12
Time: 09:15

Re: Using OpenTBS can i remove the image form a template when picture file does not exist?

I first merge the picture, after that i do a MergeField: so the correct sequence i do is:

$TBS_document = new clsTinyButStrong;
$TBS_document->NoErr = TRUE;
$TBS_document->Plugin(TBS_INSTALL, OPENTBS_PLUGIN);
$TBS_document->LoadTemplate($template_file, OPENTBS_ALREADY_UTF8);   -> $template_file holds the template file

$TBS_document->PlugIn(OPENTBS_CHANGE_PICTURE, '[block.signature], '/tmp/signature.png' ,array('unique' => true))

$TBS_document->MergeField( 'block', $module_data );  -> $module_data hold an array with data
$TBS_document->Show(OPENTBS_FILE, $filename); -> $filename hold de merged file name


so changing the keyword is not solving my problem. Any other idea's?
By: Skrol29
Date: 2015-06-12
Time: 16:12

Re: Using OpenTBS can i remove the image form a template when picture file does not exist?

OK, I misunderstood the problem.

In ODT, images are placed using an <draw:frame> element.
Si you have to check if the file exists, then merge the picture if it exists, and then delete the <draw:frame> element if it doesn't.

Exemple, at the PHP side:
$img_file = '/tmp/signature.png';
if (file_exists($img_file)) {
  $TBS_document->PlugIn(OPENTBS_CHANGE_PICTURE, '[block.signature], $img_file ,array('unique' => true))
} else {
  $TBS_document->MergeBlock('del_img', 'clear');
}

In the description of the picture:
[block.signature] [del_img;block=draw:frame]

Note; deleting the XML entity can also be done using a TBS field that have parameter "magnet".
By: Meri van Buuren
Date: 2015-06-12
Time: 16:23

Re: Using OpenTBS can i remove the image form a template when picture file does not exist?

Ok, thx, i will try this.

Does it work the same with docx files?