| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE task PUBLIC "-//OASIS//DTD DITA Task//EN" "task.dtd">
- <!-- This file is part of the DITA Open Toolkit project. See the accompanying LICENSE file for applicable license. -->
- <task id="dita2pdf-customization" xml:lang="en">
- <title>Example: Creating a simple PDF plug-in</title>
- <titlealts>
- <navtitle>Simple PDF plug-in example</navtitle>
- </titlealts>
- <shortdesc>This scenario walks through the process of creating a very simple plug-in
- (<codeph>com.example.print-pdf</codeph>) that creates a new transformation type: <option>print-pdf</option>. </shortdesc>
- <taskbody>
- <context>
- <p>The <option>print-pdf</option> transformation has the following characteristics:</p>
- <ul>
- <li>Uses A4 paper </li>
- <li>Renders figures with a title at the top and a description at the bottom</li>
- <li>Use em dashes as the symbols for unordered lists</li>
- </ul>
- </context>
- <steps>
- <step>
- <cmd>In the <filepath>plugins</filepath> directory, create a directory named
- <filepath>com.example.print-pdf</filepath>.</cmd>
- </step>
- <step>
- <cmd>In the new <filepath>com.example.print-pdf</filepath> directory, create a plug-in configuration file
- (<filepath>plugin.xml</filepath>) that declares the new <option>print-pdf</option> transformation and its
- dependencies.</cmd>
- <info>
- <fig>
- <title><filepath>plugin.xml</filepath> file</title>
- <codeblock><?xml version='1.0' encoding='UTF-8'?>
- <plugin id="com.example.print-pdf">
- <require plugin="org.dita.pdf2"/>
- <feature extension="dita.conductor.transtype.check" value="print-pdf"/>
- <feature extension="dita.transtype.print" value="print-pdf"/>
- <feature extension="dita.conductor.target.relative" file="integrator.xml"/>
- </plugin></codeblock>
- </fig>
- </info>
- </step>
- <step>
- <cmd>Add an Ant script (<filepath>integrator.xml</filepath>) to define the transformation type.</cmd>
- <info>
- <fig>
- <title><filepath>integrator.xml</filepath> file</title>
- <codeblock><?xml version='1.0' encoding='UTF-8'?>
- <project name="com.example.print-pdf">
- <target name="dita2print-pdf.init">
- <property name="customization.dir" location="${dita.plugin.com.example.print-pdf.dir}/cfg"/>
- </target>
- <target name="dita2print-pdf" depends="dita2print-pdf.init, dita2pdf2"/>
- </project></codeblock>
- </fig></info>
- </step>
- <step>
- <cmd>In the new plug-in directory, add a <filepath>cfg/catalog.xml</filepath> file that specifies the custom
- XSLT style sheets.</cmd>
- <stepxmp>
- <fig>
- <title><filepath>cfg/catalog.xml</filepath> file</title>
- <codeblock><?xml version="1.0" encoding="UTF-8"?>
- <catalog prefer="system" xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
- <uri name="cfg:fo/attrs/custom.xsl" uri="fo/attrs/custom.xsl"/>
- <uri name="cfg:fo/xsl/custom.xsl" uri="fo/xsl/custom.xsl"/>
- </catalog></codeblock>
- </fig>
- </stepxmp>
- </step>
- <step>
- <cmd>Create the <filepath>cfg/fo/attrs/custom.xsl</filepath> file, and add attribute and variable overrides to
- it.</cmd>
- <stepxmp>For example, add the content highlighted with bold to change the page size to A4.<fig>
- <title><filepath>cfg/fo/attrs/custom.xsl</filepath> file</title>
- <codeblock><?xml version="1.0" encoding="UTF-8"?>
- <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- version="2.0">
- <b> <!-- Change page size to A4 -->
- <xsl:variable name="page-width">210mm</xsl:variable>
- <xsl:variable name="page-height">297mm</xsl:variable></b>
- </xsl:stylesheet></codeblock>
- </fig></stepxmp>
- </step>
- <step>
- <cmd>Create the <filepath>cfg/fo/xsl/custom.xsl</filepath> file, and add XSLT overrides to it.</cmd>
- <stepxmp>For example, the following code changes the rendering of <xmlelement>figure</xmlelement> elements.<fig>
- <title><filepath>cfg/fo/xsl/custom.xsl</filepath> file</title>
- <codeblock><?xml version="1.0" encoding="UTF-8"?>
- <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- xmlns:xs="http://www.w3.org/2001/XMLSchema"
- xmlns:fo="http://www.w3.org/1999/XSL/Format"
- version="2.0">
- <!-- Move figure title to top and description to bottom -->
- <xsl:template match="*[contains(@class,' topic/fig ')]">
- <fo:block xsl:use-attribute-sets="fig">
- <xsl:call-template name="commonattributes"/>
- <xsl:if test="not(@id)">
- <xsl:attribute name="id">
- <xsl:call-template name="get-id"/>
- </xsl:attribute>
- </xsl:if>
- <xsl:apply-templates select="*[contains(@class,' topic/title ')]"/>
- <xsl:apply-templates select="*[not(contains(@class,' topic/title ') or contains(@class,' topic/desc '))]"/>
- <xsl:apply-templates select="*[contains(@class,' topic/desc ')]"/>
- </fo:block>
- </xsl:template>
- </xsl:stylesheet></codeblock>
- </fig></stepxmp>
- </step>
- <step>
- <cmd>Create an English-language variable-definition file (<filepath>cfg/common/vars/en.xml</filepath>) and make
- any necessary modifications to it.</cmd>
- <stepxmp>For example, the following code removes the period after the number for an ordered-list item; it also
- specifies that the bullet for an unordered list item should be an em dash.<fig>
- <title><filepath>cfg/common/vars/en.xml</filepath> file</title>
- <codeblock><?xml version="1.0" encoding="UTF-8"?>
- <vars xmlns="http://www.idiominc.com/opentopic/vars">
- <!-- Remove dot from list number -->
- <variable id="Ordered List Number"><param ref-name="number"/></variable>
- <!-- Change unordered list bullet to an em dash -->
- <variable id="Unordered List bullet">&#x2014;</variable>
- </vars></codeblock>
- </fig></stepxmp>
- </step>
- </steps>
- <result>
- <p>The new plug-in directory has the following layout and files:</p>
- <codeblock>com.example.print-pdf/
- cfg/
- common/
- vars/
- en.xml
- fo/
- attrs/
- custom.xsl
- xsl/
- custom.xsl
- catalog.xml
- integrator.xml
- plugin.xml</codeblock>
- </result>
- <postreq>
- <p>Run <filepath conref="../resources/conref-task.dita#ID/dita-cmd"/>
- <parmname>--install</parmname> to install the plug-in and make the <option>print-pdf</option> transformation
- available.</p>
- </postreq>
- </taskbody>
- </task>
|