jason-fox / fox.jason.watermark

DITA-OT Plug-in to add a watermark to generated PDF files
https://jason-fox.github.io/dita-ot-plugins/watermark
Apache License 2.0
1 stars 0 forks source link
dita-ot-plugin pdf-document watermark

Watermark Plugin for DITA-OT

license DITA-OT 4.2 Documentation Status

This is a DITA-OT Plug-in to add a watermark to generated PDF files. The plugin extends standard PDF processing. It offers an extension-point for further processing.

Table of Contents - [Install](#install) - [Installing DITA-OT](#installing-dita-ot) - [Installing the Plug-in](#installing-the-plug-in) - [Usage](#usage) - [Parameter Reference](#parameter-reference) - [Extension points](#extension-points) - [License](#license)

Install

The DITA-OT Watermark plug-in has been tested against DITA-OT 3.x. It is recommended that you upgrade to the latest version.

Installing DITA-OT

The DITA-OT Watermark plug-in is a plug-in for the DITA Open Toolkit.

curl -LO https://github.com/dita-ot/dita-ot/releases/download/4.2/dita-ot-4.2.zip
unzip -q dita-ot-4.2.zip
rm dita-ot-4.2.zip

Installing the Plug-in

dita install https://github.com/jason-fox/fox.jason.watermark/archive/master.zip

The dita command line tool requires no additional configuration.


Usage

The plugin extends standard PDF processing:

PATH_TO_DITA_OT/bin/dita -f pdf -o out -i document.ditamap --pdf.watermark=draft|review|final

By default the output PDF will be watermarked as a DRAFT

Parameter Reference

Extension points

This plug-in is designed to be extended and offers an extension point:

Example

The following plugin.xml will enable the watermarking of PDF files to depend on an authorization server.

plugin.xml Configuration
<plugin id="com.example.watermark.dita">
  <require plugin="fox.jason.watermark"/>
  <feature extension="watermark.pre" value="watermark.auth"/>
  <feature extension="depend.preprocess.pre" value="watermark.check"/>
</plugin>
ANT build file
<project name="com.example.passthrough.dita">

  <macrodef name="authorize-user">
    <attribute name="token"/>
    <attribute name="action"/>
    <sequential>
      <!-- do-something to authorize the action -->
      <property if:true="${authorized}" name="pdf.watermark" value="@{value}"/>
    </sequential>
  </macrodef>

  <target name="watermark.check">
    <!-- Ensure watermark isn't preset on the command line -->
    <dita-ot-fail if:set="pdf.watermark"/>
    <condition property="auth.watermark.review">
      <equals arg1="${auth.level}" arg2="review"/>
    </condition>
    <condition property="auth.watermark.final">
        <equals arg1="${auth.level}" arg2="final"/>
    </condition>
    <condition property="auth.watermark.none">
        <equals arg1="${auth.level}" arg2="none"/>
    </condition>
  </target>

  <target name="watermark.auth">
    <!-- Now set watermark if authorized to do so -->
    <authorize-action if:true="${auth.watermark.review}" token="${auth.token}"  action="review" />
    <authorize-action if:true="${auth.watermark.final}" token="${auth.token}"  action="final"/>
    <authorize-action if:true="${auth.watermark.none}" token="${auth.token}"  action="none"/>
  </target>
</project>

A working example can be found in the DITA-OT Watermark Auth plug-in repository.

License

Apache 2.0 © 2021 - 2024 Jason Fox