Forum


Replies: 3   Views: 3854
Different background (header) images
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by bgcc  · 06-02-2014 - 16:25

Hello,



I'm trying to set a different background image for the first page, different from the other pages. The background image is set as header image. The result is, that the first page has the same background image like the others. I'm using PHPDocX 3.7 Pro+



My code for the backgrounds is:




/* BACKGROUND IMAGE */
if ($tmp_background_file_1) {
$options = array(
'border' => 0,
'borderDiscontinuous' => 0,
'float' => 'center', // (left, right, center) floating image. It only applies if textWrap is not inline (default value)
'horizontalOffset' => 0, // given in emus (1cm = 360000 emus). Only applies if there is the image is not floating
'jc' => 'center', // (center, left, right, inside, outside)
'name' => $tmp_background_file_1,
'scaling' => 100,
'dpi' => 96,
'spacingTop' => -165,
'spacingBottom' => 0,
'spacingLeft' => 0,
'spacingRight' => 0,
'textWrap' => 3, // 0 (inline), 1 (square), 2 (front), 3 (back), 4 (up and bottom)
'target' => 'firstHeader', // document (default value), defaultHeader, firstHeader, evenHeader, defaultFooter, firstFooter, evenFooter, footnote, endnote, comment
'verticalOffset' => 0,
'rawWordML' => 'true',
);

$header_wordml_pieces[] = $docx->addImage($options);
}

if ($tmp_background_file_2) {
$options = array(
'border' => 0,
'borderDiscontinuous' => 0,
'float' => 'center', // (left, right, center) floating image. It only applies if textWrap is not inline (default value)
'horizontalOffset' => 0, // given in emus (1cm = 360000 emus). Only applies if there is the image is not floating
'jc' => 'center', // (center, left, right, inside, outside)
'name' => $tmp_background_file_2,
'scaling' => 100,
'dpi' => 96,
'spacingTop' => -165,
'spacingBottom' => 0,
'spacingLeft' => 0,
'spacingRight' => 0,
'textWrap' => 3, // 0 (inline), 1 (square), 2 (front), 3 (back), 4 (up and bottom)
'target' => 'defaultHeader', // document (default value), defaultHeader, firstHeader, evenHeader, defaultFooter, firstFooter, evenFooter, footnote, endnote, comment
'verticalOffset' => 0,
'rawWordML' => 'true',
);

$header_wordml_pieces[] = $docx->addImage($options);
}

$header_wordml_fragment = $docx->createWordMLFragment($header_wordml_pieces);
$docx->addHeader(array('default' => $header_wordml_fragment));


Hopefully someone can help.