Categories > OpenTBS with DOCX >

Change pictures in header of a docx

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: RudiRocket
Date: 2013-12-11
Time: 10:24

Change pictures in header of a docx

Hi there!
I am very new to openTBS. I altered successfully the demo page with my settings.
Just one thing troubles me. It is possible to change pictures in the document, but
it seems I cannot do it neither in the header nor the footer. Is there a workaround.
My code: [b.number;ope=changepic;from=pic_[val].png;tagpos=inside;adjust]

Hope somebody can help me!
By: Skrol29
Date: 2013-12-11
Time: 22:27

Re: Change pictures in header of a docx

In a DOCX, headers can be saved in sub files
- "/word/header1.xml" for common pages
- "/word/header2.xml" for odd numbered pages
- "/word/header3.xml" for the first page if different
They are also
- "word/footer1.xml" for common pages
- "word/footer2.xml" for odd numbered pages
- "word/footer3.xml" for the first page if different

So you have to load this sub-file and operate your mering on it.
Example:
$TBS->LoadTemplate('#word/header1.xml');
$TBS->MergeFields('b', $data);


By: Arnold
Date: 2013-12-12
Time: 10:23

Re: Change pictures in header of a docx

i'm using different templates, some have headers some have footers and some have none.
but when i'm using these LoadTemplate's i'm getting the error:
TinyButStrong Error OpenTBS Plugin: Cannot load "word/header1.xml". The file is not found in the archive "/tmp/phpZFdELA". The process is ending, unless you set NoErr property to true.
how to avoid this without setting the NoErr?

EDIT:
on the same note,
$TBS->LoadTemplate($template->tempfile);
$TBS->LoadTemplate('#word/header1.xml');
$TBS->LoadTemplate('#word/footer1.xml');
$TBS->MergeBlock('data',$data);
doesn't work, MergeBlock only apply's on the last LoadTemplate not on all.
By: Skrol29
Date: 2013-12-13
Time: 02:58

Re: Change pictures in header of a docx

Try this:
$files= array('header1.xml', 'header2.xml', 'header3.xml', 'footer1.xml', 'footer2.xml', 'footer3.xml');
foreach ($files as $f) {
  $fpath = 'word/' . $f;
  if ($TBS->Plugin(OPENTBS_FILEEXISTS, $fpath)) {
     $TBS->LoadTemplate('#' . $fpath);
     $TBS->MergeBlock('data',$data);
  }
}
By: Arnold
Date: 2013-12-31
Time: 10:51

Re: Change pictures in header of a docx

Hi Skrol,

worked like a charm.
but for those using open-/libreoffice add to the files array 'styles.xml'
else the headers and footers wont be merged.