watermarkDocx

watermarkDocx

ADVANCED / PREMIUM TRIAL

Inserts a watermark into a Word document.

Description
public watermarkDocx (string $source, string $target, [string $type, array $options])

This method allows you to insert a watermark image or text in a Word document.

Parameters

source

Path to the Word document.

target

Path to the resulting watermarked document.

type

Watermark type: 'text' or 'image'.

options

The possible keys and values are:

Key Type Description
remove_previous_watermarks bool If true (default) removes previous watermarks.
scope string Header (default) or footer.
section int All if not set. Allows adding a watermark per section.

If type is 'image':

Key Type Description
image string Path to the watermark image.
height int Watermark image height in pixels (optional).
width int Watermark image width in pixels (optional).
decolorate bool If true (default) decolorates the image.
gain string Optional value to customize decoloration: hexadecimal value.
blacklevel string Optional value to customize decoloration: hexadecimal value.

If type is 'text':

Key Type Description
text string The string of text used for watermarking.
"\n" adds a line break.
text_orientation string Orientation: diagonal (default) or horizontal.
height int Watermark text height in pixels (optional).
width int Watermark text width in pixels (optional).
font string The font-family. If not set defaults to Calibri.
bold bool Bold style.
italic bool Italic style.
color string Hexadecimal value or color name (defaults to silver).
opacity float Decimal number between 0 and 1. If not set defaults to 0.5
add_vshapetype_tag bool If true (default as false) adds a v:shapetype tag to force LibreOffice to display the text watermark.
Exceptions

Error while trying to open the (base) template as a zip file.

Unknown watermark type.

Image doesn't exist.

Image format not supported.

Code samples

Example #1

The resulting Word document looks like:

Example #2

The resulting Word document looks like:

Release notes
  • phpdocx 14.0:
    • return DOCXStructure.
  • phpdocx 12.5:
    • multiline texts.
    • bold and italic styles.
  • phpdocx 12.0:
    • DOCXStructure.
    • htmlspecialchars applied in text value.
    • replaced exit methods by exceptions.
  • phpdocx 10.0:
    • footer scope.
  • phpdocx 9.5:
    • watermarks per section.
  • phpdocx 9.0:
    • add_vshapetype_tag option.