| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- <!DOCTYPE html
- SYSTEM "about:legacy-compat">
- <html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta charset="UTF-8"><meta name="copyright" content="(C) Copyright 2016"><meta name="DC.rights.owner" content="(C) Copyright 2016"><meta name="DC.Type" content="task"><meta name="description" content="This scenario walks through the process of creating a very simple plug-in (com.example.print-pdf) that creates a new transformation type: print-pdf."><meta name="DC.Relation" scheme="URI" content="../dev_ref/pdf-customization.html"><meta name="DC.Relation" scheme="URI" content="../dev_ref/plugins-installing.html"><meta name="DC.Format" content="XHTML"><meta name="DC.Identifier" content="dita2pdf-customization"><meta name="DC.Language" content="en"><link rel="stylesheet" type="text/css" href="../css/commonltr.css"><link rel="stylesheet" type="text/css" href="../css/dita-ot-doc.css"><title>Example: Creating a simple PDF plug-in</title></head><body id="dita2pdf-customization"><header role="banner"><div class="header">
- <p>DITA Open Toolkit</p>
- <hr>
- </div></header><nav role="toc"><ul><li><a href="../index.html">DITA Open Toolkit 2.3</a></li><li><a href="../release-notes/index.html">Release Notes</a></li><li><a href="../getting-started/index.html">Getting Started</a></li><li><a href="../user-guide/index.html">User Guide</a></li><li><a href="../parameters/index.html">Parameter Reference</a></li><li><a href="../dev_ref/index.html">Developer Reference</a><ul><li><a href="../dev_ref/DITA-OTArchitecture.html">DITA-OT Architecture</a></li><li><a href="../dev_ref/extending-the-ot.html">Extending the DITA-OT</a></li><li><a href="../dev_ref/plugin-creating.html">Creating plug-ins</a></li><li><a href="../dev_ref/plugin-extension-points.html">Extension points</a></li><li><a href="../dev_ref/pdf-customization.html">Customizing PDF output</a><ul><li><a href="../dev_ref/pdf-transformation-history.html">History of the PDF transformation</a></li><li><a href="../dev_ref/pdf-customization-approaches.html">PDF customization approaches</a></li><li><a href="../dev_ref/pdf-customization-plugin-types.html">Types of custom PDF plug-ins</a></li><li><a href="../dev_ref/pdf-plugin-structure.html">PDF plug-in structure</a></li><li class="active"><a href="../dev_ref/pdf-customization-example.html">Simple PDF plug-in example</a></li><li><a href="../dev_ref/pdf-customization-best-practices.html">Customization best practices</a></li><li><a href="../dev_ref/pdf-customization-resources.html">Custom PDF plug-in resources</a></li></ul></li><li><a href="../dev_ref/migration.html">Migrating customizations</a></li></ul></li><li><a href="../user-guide/dita-and-dita-ot-resources.html">DITA Resources</a></li></ul></nav><main role="main"><article role="article" aria-labelledby="ariaid-title1">
- <h1 class="title topictitle1" id="ariaid-title1">Example: Creating a simple PDF plug-in</h1>
-
- <div class="body taskbody"><p class="shortdesc">This scenario walks through the process of creating a very simple plug-in
- (<code class="ph codeph">com.example.print-pdf</code>) that creates a new transformation type: <span class="keyword option">print-pdf</span>. </p>
- <section class="section context"><div class="tasklabel"><h2 class="sectiontitle tasklabel">About this task</h2></div>
- <p class="p">The <span class="keyword option">print-pdf</span> transformation has the following characteristics:</p>
- <ul class="ul">
- <li class="li">Uses A4 paper </li>
- <li class="li">Renders figures with a title at the top and a description at the bottom</li>
- <li class="li">Use em dashes as the symbols for unordered lists</li>
- </ul>
- </section>
- <div class="tasklabel"><h2 class="sectiontitle tasklabel">Procedure</h2></div><ol class="ol steps"><li class="li step stepexpand">
- <span class="ph cmd">In the <span class="ph filepath">plugins</span> directory, create a directory named
- <span class="ph filepath">com.example.print-pdf</span>.</span>
- </li><li class="li step stepexpand">
- <span class="ph cmd">In the new <span class="ph filepath">com.example.print-pdf</span> directory, create a plug-in configuration file
- (<span class="ph filepath">plugin.xml</span>) that declares the new <span class="keyword option">print-pdf</span> transformation and its
- dependencies.</span>
- <div class="itemgroup info">
- <figure class="fig fignone"><figcaption><span class="fig--title-label">Figure 1. </span><span class="ph filepath">plugin.xml</span> file</figcaption>
-
- <pre class="pre codeblock"><code><?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></code></pre>
- </figure>
- </div>
- </li><li class="li step stepexpand">
- <span class="ph cmd">Add an Ant script (<span class="ph filepath">integrator.xml</span>) to define the transformation type.</span>
- <div class="itemgroup info">
- <figure class="fig fignone"><figcaption><span class="fig--title-label">Figure 2. </span><span class="ph filepath">integrator.xml</span> file</figcaption>
-
- <pre class="pre codeblock"><code><?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></code></pre>
- </figure></div>
- </li><li class="li step stepexpand">
- <span class="ph cmd">In the new plug-in directory, add a <span class="ph filepath">cfg/catalog.xml</span> file that specifies the custom
- XSLT style sheets.</span>
- <div class="itemgroup stepxmp">
- <figure class="fig fignone"><figcaption><span class="fig--title-label">Figure 3. </span><span class="ph filepath">cfg/catalog.xml</span> file</figcaption>
-
- <pre class="pre codeblock"><code><?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></code></pre>
- </figure>
- </div>
- </li><li class="li step stepexpand">
- <span class="ph cmd">Create the <span class="ph filepath">cfg/fo/attrs/custom.xsl</span> file, and add attribute and variable overrides to
- it.</span>
- <div class="itemgroup stepxmp">For example, add the content highlighted with bold to change the page size to A4.<figure class="fig fignone"><figcaption><span class="fig--title-label">Figure 4. </span><span class="ph filepath">cfg/fo/attrs/custom.xsl</span> file</figcaption>
-
- <pre class="pre codeblock"><code><?xml version="1.0" encoding="UTF-8"?>
- <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- version="2.0">
- <strong class="ph b"> <!-- Change page size to A4 -->
- <xsl:variable name="page-width">210mm</xsl:variable>
- <xsl:variable name="page-height">297mm</xsl:variable></strong>
- </xsl:stylesheet></code></pre>
- </figure></div>
- </li><li class="li step stepexpand">
- <span class="ph cmd">Create the <span class="ph filepath">cfg/fo/xsl/custom.xsl</span> file, and add XSLT overrides to it.</span>
- <div class="itemgroup stepxmp">For example, the following code changes the rendering of <code class="keyword markupname xmlelement"><figure></code> elements.<figure class="fig fignone"><figcaption><span class="fig--title-label">Figure 5. </span><span class="ph filepath">cfg/fo/xsl/custom.xsl</span> file</figcaption>
-
- <pre class="pre codeblock"><code><?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></code></pre>
- </figure></div>
- </li><li class="li step stepexpand">
- <span class="ph cmd">Create an English-language variable-definition file (<span class="ph filepath">cfg/common/vars/en.xml</span>) and make
- any necessary modifications to it.</span>
- <div class="itemgroup 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.<figure class="fig fignone"><figcaption><span class="fig--title-label">Figure 6. </span><span class="ph filepath">cfg/common/vars/en.xml</span> file</figcaption>
-
- <pre class="pre codeblock"><code><?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></code></pre>
- </figure></div>
- </li></ol>
- <section class="section result"><div class="tasklabel"><h2 class="sectiontitle tasklabel">Results</h2></div>
- <p class="p">The new plug-in directory has the following layout and files:</p>
- <pre class="pre codeblock"><code>com.example.print-pdf/
- cfg/
- common/
- vars/
- en.xml
- fo/
- attrs/
- custom.xsl
- xsl/
- custom.xsl
- catalog.xml
- integrator.xml
- plugin.xml</code></pre>
- </section>
- <section class="section postreq"><div class="tasklabel"><h2 class="sectiontitle tasklabel">What to do next</h2></div>
- <p class="p">Run <span class="ph filepath"><var class="keyword varname">dita-ot-dir</var>/bin/<span class="keyword cmdname">dita</span></span> <span class="keyword option">-install</span> to install the plug-in and make the <span class="keyword option">print-pdf</span> transformation
- available.</p>
- </section>
- </div>
- <nav role="navigation" class="related-links"><div class="familylinks"><div class="parentlink"><strong>Parent topic:</strong> <a class="link" href="../dev_ref/pdf-customization.html" title="You can create custom DITA-OT plug-ins that build on the default DITA to PDF transformation. Plug-ins can customize covers and page layouts, modify formatting, override logic of the default PDF plug-in, and much more.">Customizing PDF output</a></div></div><div class="linklist linklist relinfo reltasks"><strong>Related tasks</strong><br><div><a class="link" href="../dev_ref/plugins-installing.html" title="Use the dita command to install a plug-in.">Installing plug-ins</a></div></div></nav></article></main></body></html>
|