watermarkPdf
- addBibliography
- addBookmark
- addBreak
- addChart
- addCitation
- addComment
- addCrossReference
- addDateAndHour
- addEndnote
- addExternalFile
- addFootnote
- addFormElement
- addHeading
- addImage
- addLink
- addList
- addMathEquation
- addMergeField
- addOLE
- addOnlineVideo
- addPageNumber
- addShape
- addSimpleField
- addSource
- addStructuredDocumentTag
- addSVG
- addTab
- addTable
- addTableContents
- addTableFigures
- addText
- addTextBox
- addWordFragment
- addWordML
- embedHTML
- addBackgroundImage
- addFooter
- addFooterSection
- addHeader
- addHeaderSection
- addLineNumbering
- addMacroFromDoc
- addPageBorders
- addProperties
- addSection
- createDocx
- createDocxAndDownload
- createCharacterStyle
- createListStyle
- createParagraphStyle
- createTableStyle
- docxSettings
- embedFont
- importChartStyle
- importHeadersAndFooters
- importListStyle
- importStyles
- importStylesWordDefault
- modifyPageLayout
- parseStyles
- removeFooters
- removeHeaders
- setBackgroundColor
- setDecimalSymbol
- setDefaultFont
- setDocumentDefaultStyles
- setEncodeUTF8
- setLanguage
- setMarkAsFinal
- setRTL
- clearBlocks
- cloneBlock
- deleteBlock
- getTemplateVariables
- getTemplateVariablesType
- modifyInputFields
- modifyMergeFields
- processTemplate
- removeTemplateVariable
- removeTemplateVariableImage
- replaceBlock
- replaceListVariable
- replacePlaceholderImage
- replaceTableVariable
- replaceVariableByExternalFile
- replaceVariableByHtml
- replaceVariableByText
- replaceVariableByWordFragment
- replaceVariableByWordML
- setTemplateSymbol
- setTemplateBlockSymbol
- tickCheckboxes
watermarkPdf
ADVANCED / PREMIUM
TRIAL
Inserts a watermark into a PDF document.
Description
public watermarkPdf (string $source, string $target, [string $type, array $options])
This method allows you to insert a watermark image or text in a PDF document.
Parameters
source
Path to the PDF document.
target
Path to the resulting watermarked document.
type
Watermark type: 'text' or 'image'.
options
The possible keys and values are (required options are shown with yellow background):
key | Type | Description |
---|---|---|
annotations | bool | Import annotations (links, comments and others). Default as false. |
pages | array | All if not set. Allows adding a watermark per page. |
useFixedAnnotationPositions | bool | Force annotation page link IDs. Useful when using PDF readers that don't detect all PDF contents automatically. Default as false. |
If type is 'image':
Key | Type | Description |
---|---|---|
image | string | Path to the watermark image. |
positionX | int | X-asis position (page center as default). |
positionY | int | Y-asis position (page center as default). |
opacity | float | Decimal number between 0 and 1(optional), if not set defaults to 0.5. |
height | int | Height value (proportional). |
width | int | Width value (proportional). |
If type is 'text':
Key | Type | Description |
---|---|---|
text | string | The string of text used for watermarking. |
positionX | int | X-asis position (page center as default). |
positionY | int | Y-asis position (page center as default). |
opacity | float | Decimal number between 0 and 1(optional), if not set defaults to 0.5. |
font | string | The font-family. It must be installed in the OS. |
size | int | Font size. |
color | string | RGB: array(r, g, b) (array(255, 255, 255)). |
Exceptions
File doesn't exist.
Not supported type.
Image doesn't exist.
Missing text value.
Code samples
Example #1
Example #2
Release notes
- phpdocx 15.5:
- cast to int object stream content indexes.
- improved annotations support.
- phpdocx 15.0:
- pages option.
- phpdocx 14.0:
- useFixedAnnotationPositions option.
- phpdocx 13.0:
- improved working with indirect objects.
- phpdocx 12.5:
- improved auto centering watermarks.
- improved using multiple sizes and orientations in the same PDF.
- width and height values adding an image as watermark.
- phpdocx 12.0:
- improved annotations support.
- phpdocx 10.0:
- annotations option.
- phpdocx 8.5:
- stream mode.
- phpdocx 7.0:
- supported PDF 1.5, 1.6 and 1.7 versions.