Add a watermark to PDFs based on a user parameter

You can configure IXIASOFT CCMS Output Generator so that an output type includes a watermark based on the value of a user parameter.

The watermark is only included in the PDF output if a user enables it using a user parameter in the Generate Output dialog.

For more information about creating watermark images, refer to Creating watermark images.

  1. Copy the watermark image to %OutputGenDir%/data/resources/client.

    The watermark image can have any name (the examples below use draft-watermark.png), and it can be any image format except SVG.

  2. Add the following lines to your preprocessors.xml file in %OutputGenDir%/conf/client:
    <user>
    	<parameter label="Add watermark?" name="include.watermark" mandatory="false" type="choice">
    		<value name="no" _default="true">No</value>
    		<value name="yes">Yes</value>
    	</parameter>
    </user>

    You can name the parameter anything you like and use any label text you like. If there is already a <user> section in the preprocessor, add the parameter to the existing section.

    Here are those lines in context:

    <preprocessor name="dita2pdf" class="com.ixiasoft.outputgenerator.preprocessor.AntProcessor" >
    	<parameters>
    		<system>
    			...
    		</system>
    		<user>
    			<parameter label="Add watermark?" name="include.watermark" mandatory="false" type="choice">
    				<value name="no" _default="true">No</value>
    				<value name="yes">Yes</value>
    			</parameter>
    		</user>
    	</parameters>
    </preprocessor>

  3. Save your changes to the preprocessor file.
  4. Add the following lines to the appropriate PDF targets in your conductor file:
    <if>
    	<equals arg1="${outgen.job.userparam.include.watermark}" arg2="yes"/>
    	<then>
    		<move file="${outgen.job.output.dir}/${outgen.job.source.name.noext}.pdf" todir="${outgen.job.dir}"/>
    		<watermark execute="true" 
    				   inputfile="${outgen.job.dir}/${outgen.job.source.name.noext}.pdf"
    				   tempfile="${outgen.job.output.dir}/${outgen.job.source.name.noext}.pdf"
    				   imagefile="${outgen.resources.dir.client}/draft-watermark.png"/>
    	</then>
    </if>
    Important: If you are using a different user parameter name (other than "include.watermark") be sure to use the same name in the target.

    Here are those lines in context:

    <target name="BigCorp_PDF" depends="default_dependencies, flatten, resolve_container_keyref, extract_HiRes_images">
    	<echostart>BigCorp_PDF</echostart>
    
    	<!-- These are the required target calls to do -->
    	<ot_build_add_ditaval_ifpresent/>
    	<ot_build_clean_ot_temp/>
    
    		...
    
    	<!-- Set the property job.keep.temp to preserve the completed temp folder of the task -->
    	<!--<property name="job.keep.temp" value="yes"/>-->
    
    	<if>
    		<equals arg1="${outgen.job.userparam.include.watermark}" arg2="yes"/>
    		<then>
    			<move file="${outgen.job.output.dir}/${outgen.job.source.name.noext}.pdf" todir="${outgen.job.dir}"/>
    			<watermark execute="true" 
    				   inputfile="${outgen.job.dir}/${outgen.job.source.name.noext}.pdf"
    				   tempfile="${outgen.job.output.dir}/${outgen.job.source.name.noext}.pdf"
    				   imagefile="${outgen.resources.dir.client}/draft-watermark.png"/>
    		</then>
    	</if>
    
    	<echoend>BigCorp_PDF</echoend>
    </target>
  5. Save your changes to the conductor file.
  6. Restart the Ixiasoft Output Generator service.

The watermark will be present in all PDFs created when the user selects the value that enables it on the Generate Output dialog.