pdf-customization-example.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <!DOCTYPE html
  2. SYSTEM "about:legacy-compat">
  3. <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 2019"><meta name="DC.rights.owner" content="(C) Copyright 2019"><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.subject" content=", figure, PDF, plug-in, integrator.xml, catalog, example"><meta name="keywords" content=", figure, PDF, plug-in, integrator.xml, catalog, example"><meta name="DC.relation" scheme="URI" content="../topics/pdf-customization.html"><meta name="DC.relation" scheme="URI" content="../topics/plugins-installing.html"><meta name="DC.format" content="HTML5"><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">
  4. <p>DITA Open Toolkit</p>
  5. <hr>
  6. </div></header><nav role="toc"><ul><li><a href="../index.html">DITA Open Toolkit 3.3</a></li><li><a href="../release-notes/index.html">Release Notes</a></li><li><a href="../topics/installing-client.html">Installing DITA-OT</a></li><li><a href="../topics/alternative-input-formats.html">Authoring formats</a></li><li><a href="../topics/building-output.html">Building output</a></li><li><a href="../parameters/index.html">Setting parameters</a></li><li><a href="../topics/customizing.html">Customizing DITA-OT</a><ul><li><a href="../topics/html-customization.html">Customizing HTML</a></li><li><a href="../topics/pdf-customization.html">Customizing PDF</a><ul><li><a href="../topics/pdf-customization-approaches.html">PDF customization approaches</a></li><li><a href="../topics/pdf-customization-plugin-types.html">Types of custom PDF plug-ins</a></li><li><a href="../topics/pdf-plugin-structure.html">PDF plug-in structure</a></li><li class="active"><a href="../topics/pdf-customization-example.html">Simple PDF plug-in example</a></li><li><a href="../topics/pdf-customization-resources.html">Custom PDF plug-in resources</a></li><li><a href="../topics/pdf2-creating-change-bars.html">Generating revision bars</a></li></ul></li><li><a href="../topics/custom-plugins.html">Working with plug-ins</a></li><li><a href="../extension-points/plugin-extension-points.html">Extension points</a></li><li><a href="../topics/migration.html">Migrating customizations</a></li><li><a href="../topics/globalization.html">Globalizing DITA content</a></li><li><a href="../topics/rebuilding-docs.html">Rebuilding documentation</a></li></ul></li><li><a href="../topics/troubleshooting-overview.html">Troubleshooting</a></li><li><a href="../reference/index.html">Reference</a></li><li><a href="../topics/dita-and-dita-ot-resources.html">Resources</a></li></ul></nav><main role="main"><article role="article" aria-labelledby="ariaid-title1">
  7. <h1 class="title topictitle1" id="ariaid-title1">Example: Creating a simple PDF plug-in</h1>
  8. <div class="body taskbody"><p class="shortdesc">This scenario walks through the process of creating a very simple plug-in
  9. (<code class="ph codeph">com.example.print-pdf</code>) that creates a new transformation type: <span class="keyword option">print-pdf</span>. </p>
  10. <section class="section context"><div class="tasklabel"><h2 class="sectiontitle tasklabel">About this task</h2></div>
  11. <p class="p">The <span class="keyword option">print-pdf</span> transformation has the following characteristics:</p>
  12. <ul class="ul">
  13. <li class="li">Uses A4 paper </li>
  14. <li class="li">Renders figures with a title at the top and a description at the bottom</li>
  15. <li class="li">Use em dashes as the symbols for unordered lists</li>
  16. </ul>
  17. </section>
  18. <section><div class="tasklabel"><h2 class="sectiontitle tasklabel">Procedure</h2></div><ol class="ol steps"><li class="li step stepexpand">
  19. <span class="ph cmd">In the <span class="ph filepath">plugins</span> directory, create a directory named
  20. <span class="ph filepath">com.example.print-pdf</span>.</span>
  21. </li><li class="li step stepexpand">
  22. <span class="ph cmd">In the new <span class="ph filepath">com.example.print-pdf</span> directory, create a plug-in configuration file
  23. (<span class="ph filepath">plugin.xml</span>) that declares the new <span class="keyword option">print-pdf</span> transformation and its
  24. dependencies.</span>
  25. <div class="itemgroup info">
  26. <figure class="fig fignone"><figcaption><span class="fig--title-label">Figure 1. </span><span class="ph filepath">plugin.xml</span> file</figcaption>
  27. <pre class="pre codeblock language-xml normalize-space show-line-numbers show-whitespace"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  28. &lt;?xml-model href="dita-ot/plugin.rnc" type="application/relax-ng-compact-syntax"?&gt;
  29. &lt;plugin id="com.example.print-pdf"&gt;
  30. &lt;require plugin="org.dita.pdf2"/&gt;
  31. &lt;transtype name="print-pdf" extends="pdf" desc="PDF on A4 paper"/&gt;
  32. &lt;feature extension="dita.transtype.print" value="print-pdf"/&gt;
  33. &lt;feature extension="ant.import" file="integrator.xml"/&gt;
  34. &lt;/plugin&gt;</code></pre>
  35. </figure>
  36. </div>
  37. </li><li class="li step stepexpand">
  38. <span class="ph cmd">Add an Ant script (<span class="ph filepath">integrator.xml</span>) to define the transformation type.</span>
  39. <div class="itemgroup info">
  40. <figure class="fig fignone"><figcaption><span class="fig--title-label">Figure 2. </span><span class="ph filepath">integrator.xml</span> file</figcaption>
  41. <pre class="pre codeblock language-xml normalize-space show-line-numbers show-whitespace"><code>&lt;?xml version='1.0' encoding='UTF-8'?&gt;
  42. &lt;project&gt;
  43. &lt;target name="dita2print-pdf"
  44. depends="dita2print-pdf.init,
  45. dita2pdf2"/&gt;
  46. &lt;target name="dita2print-pdf.init"&gt;
  47. &lt;property name="customization.dir"
  48. location="${dita.plugin.com.example.print-pdf.dir}/cfg"/&gt;
  49. &lt;/target&gt;
  50. &lt;/project&gt;</code></pre>
  51. </figure></div>
  52. </li><li class="li step stepexpand">
  53. <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
  54. XSLT style sheets.</span>
  55. <div class="itemgroup stepxmp">
  56. <figure class="fig fignone"><figcaption><span class="fig--title-label">Figure 3. </span><span class="ph filepath">cfg/catalog.xml</span> file</figcaption>
  57. <pre class="pre codeblock language-xml normalize-space show-line-numbers show-whitespace"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  58. &lt;catalog prefer="system"
  59. xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog"&gt;
  60. &lt;uri name="cfg:fo/attrs/custom.xsl" uri="fo/attrs/custom.xsl"/&gt;
  61. &lt;uri name="cfg:fo/xsl/custom.xsl" uri="fo/xsl/custom.xsl"/&gt;
  62. &lt;/catalog&gt;</code></pre>
  63. </figure>
  64. </div>
  65. </li><li class="li step stepexpand">
  66. <span class="ph cmd">Create the <span class="ph filepath">cfg/fo/attrs/custom.xsl</span> file, and add attribute and variable overrides to
  67. it.</span>
  68. <div class="itemgroup stepxmp">For example, add the following variables 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>
  69. <pre class="pre codeblock language-xml normalize-space show-line-numbers show-whitespace"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  70. &lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  71. version="2.0"&gt;
  72. &lt;!-- Change page size to A4 --&gt;
  73. &lt;xsl:variable name="page-width"&gt;210mm&lt;/xsl:variable&gt;
  74. &lt;xsl:variable name="page-height"&gt;297mm&lt;/xsl:variable&gt;
  75. &lt;/xsl:stylesheet&gt;</code></pre>
  76. </figure></div>
  77. </li><li class="li step stepexpand">
  78. <span class="ph cmd">Create the <span class="ph filepath">cfg/fo/xsl/custom.xsl</span> file, and add XSLT overrides to it.</span>
  79. <div class="itemgroup stepxmp">For example, the following code changes the rendering of <code class="keyword markupname xmlelement">&lt;figure&gt;</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>
  80. <pre class="pre codeblock language-xml normalize-space show-line-numbers show-whitespace"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  81. &lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  82. xmlns:xs="http://www.w3.org/2001/XMLSchema"
  83. xmlns:fo="http://www.w3.org/1999/XSL/Format"
  84. version="2.0"&gt;
  85. &lt;!-- Move figure title to top and description to bottom --&gt;
  86. &lt;xsl:template match="*[contains(@class,' topic/fig ')]"&gt;
  87. &lt;fo:block xsl:use-attribute-sets="fig"&gt;
  88. &lt;xsl:call-template name="commonattributes"/&gt;
  89. &lt;xsl:if test="not(@id)"&gt;
  90. &lt;xsl:attribute name="id"&gt;
  91. &lt;xsl:call-template name="get-id"/&gt;
  92. &lt;/xsl:attribute&gt;
  93. &lt;/xsl:if&gt;
  94. &lt;xsl:apply-templates select="*[contains(@class,' topic/title ')]"/&gt;
  95. &lt;xsl:apply-templates select="*[not(contains(@class,' topic/title ') or contains(@class,' topic/desc '))]"/&gt;
  96. &lt;xsl:apply-templates select="*[contains(@class,' topic/desc ')]"/&gt;
  97. &lt;/fo:block&gt;
  98. &lt;/xsl:template&gt;
  99. &lt;/xsl:stylesheet&gt;</code></pre>
  100. </figure></div>
  101. </li><li class="li step stepexpand">
  102. <span class="ph cmd">Create an English-language variable-definition file (<span class="ph filepath">cfg/common/vars/en.xml</span>) and make
  103. any necessary modifications to it.</span>
  104. <div class="itemgroup stepxmp">For example, the following code removes the period after the number for an ordered-list item; it also
  105. 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>
  106. <pre class="pre codeblock language-xml normalize-space show-line-numbers show-whitespace"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  107. &lt;vars xmlns="http://www.idiominc.com/opentopic/vars"&gt;
  108. &lt;!-- Remove dot from list number --&gt;
  109. &lt;variable id="Ordered List Number"&gt;
  110. &lt;param ref-name="number"/&gt;
  111. &lt;/variable&gt;
  112. &lt;!-- Change unordered list bullet to an em dash --&gt;
  113. &lt;variable id="Unordered List bullet"&gt;&amp;#x2014;&lt;/variable&gt;
  114. &lt;/vars&gt;</code></pre>
  115. </figure></div>
  116. </li></ol></section>
  117. <section class="section result"><div class="tasklabel"><h2 class="sectiontitle tasklabel">Results</h2></div>
  118. <div class="note tip note_tip"><span class="note__title">Tip:</span> The files for this sample plug-in are included in the DITA-OT installation directory under
  119. <span class="ph filepath">docsrc/samples/plugins/com.example.print-pdf/</span> and on
  120. <a class="xref" href="https://github.com/dita-ot/docs/tree/develop/samples/plugins/com.example.print-pdf" target="_blank">GitHub</a>.</div>
  121. <p class="p">The plug-in directory has the following layout and files:</p>
  122. <pre class="pre codeblock"><code>com.example.print-pdf
  123. ├── cfg
  124. │&nbsp;&nbsp; ├── catalog.xml
  125. │&nbsp;&nbsp; ├── common
  126. │&nbsp;&nbsp; │&nbsp;&nbsp; └── vars
  127. │&nbsp;&nbsp; │&nbsp;&nbsp; └── en.xml
  128. │&nbsp;&nbsp; └── fo
  129. │&nbsp;&nbsp; ├── attrs
  130. │&nbsp;&nbsp; │&nbsp;&nbsp; └── custom.xsl
  131. │&nbsp;&nbsp; └── xsl
  132. │&nbsp;&nbsp; └── custom.xsl
  133. ├── integrator.xml
  134. └── plugin.xml</code></pre>
  135. </section>
  136. <section class="section postreq"><div class="tasklabel"><h2 class="sectiontitle tasklabel">What to do next</h2></div>
  137. <ol class="ol">
  138. <li class="li">Run <span class="ph filepath"><var class="keyword varname">dita-ot-dir</var>/bin/<span class="keyword cmdname">dita</span></span>
  139. <span class="keyword parmname">--install</span> to install the plug-in and make the <span class="keyword option">print-pdf</span> transformation
  140. available.</li>
  141. <li class="li">Build output with the new transformation type to verify that the plug-in works as intended.
  142. <pre class="pre codeblock"><code><span class="ph filepath"><var class="keyword varname">dita-ot-dir</var>/bin/<span class="keyword cmdname">dita</span></span> <span class="keyword parmname">--input</span>=<var class="keyword varname">my.ditamap</var> <span class="keyword parmname">--format</span>=<span class="keyword option">print-pdf</span></code></pre>
  143. </li>
  144. </ol>
  145. </section>
  146. </div>
  147. <nav role="navigation" class="related-links"><div class="familylinks"><div class="parentlink"><strong>Parent topic:</strong> <a class="link" href="../topics/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 relinfo reltasks"><strong>Related tasks</strong><br><ul class="linklist"><li class="linklist"><a class="link" href="../topics/plugins-installing.html" title="Use the dita command to install a plug-in.">Installing plug-ins</a></li></ul></div></nav></article></main></body></html>