pdf-customization-example.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 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">
  4. <p>DITA Open Toolkit</p>
  5. <hr>
  6. </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">
  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. <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"><code>&lt;?xml version='1.0' encoding='UTF-8'?&gt;
  28. &lt;plugin id="com.example.print-pdf"&gt;
  29. &lt;require plugin="org.dita.pdf2"/&gt;
  30. &lt;feature extension="dita.conductor.transtype.check" value="print-pdf"/&gt;
  31. &lt;feature extension="dita.transtype.print" value="print-pdf"/&gt;
  32. &lt;feature extension="dita.conductor.target.relative" file="integrator.xml"/&gt;
  33. &lt;/plugin&gt;</code></pre>
  34. </figure>
  35. </div>
  36. </li><li class="li step stepexpand">
  37. <span class="ph cmd">Add an Ant script (<span class="ph filepath">integrator.xml</span>) to define the transformation type.</span>
  38. <div class="itemgroup info">
  39. <figure class="fig fignone"><figcaption><span class="fig--title-label">Figure 2. </span><span class="ph filepath">integrator.xml</span> file</figcaption>
  40. <pre class="pre codeblock"><code>&lt;?xml version='1.0' encoding='UTF-8'?&gt;
  41. &lt;project name="com.example.print-pdf"&gt;
  42. &lt;target name="dita2print-pdf.init"&gt;
  43. &lt;property name="customization.dir" location="${dita.plugin.com.example.print-pdf.dir}/cfg"/&gt;
  44. &lt;/target&gt;
  45. &lt;target name="dita2print-pdf" depends="dita2print-pdf.init, dita2pdf2"/&gt;
  46. &lt;/project&gt;</code></pre>
  47. </figure></div>
  48. </li><li class="li step stepexpand">
  49. <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
  50. XSLT style sheets.</span>
  51. <div class="itemgroup stepxmp">
  52. <figure class="fig fignone"><figcaption><span class="fig--title-label">Figure 3. </span><span class="ph filepath">cfg/catalog.xml</span> file</figcaption>
  53. <pre class="pre codeblock"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  54. &lt;catalog prefer="system" xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog"&gt;
  55. &lt;uri name="cfg:fo/attrs/custom.xsl" uri="fo/attrs/custom.xsl"/&gt;
  56. &lt;uri name="cfg:fo/xsl/custom.xsl" uri="fo/xsl/custom.xsl"/&gt;
  57. &lt;/catalog&gt;</code></pre>
  58. </figure>
  59. </div>
  60. </li><li class="li step stepexpand">
  61. <span class="ph cmd">Create the <span class="ph filepath">cfg/fo/attrs/custom.xsl</span> file, and add attribute and variable overrides to
  62. it.</span>
  63. <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>
  64. <pre class="pre codeblock"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  65. &lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  66. version="2.0"&gt;
  67. <strong class="ph b"> &lt;!-- Change page size to A4 --&gt;
  68. &lt;xsl:variable name="page-width"&gt;210mm&lt;/xsl:variable&gt;
  69. &lt;xsl:variable name="page-height"&gt;297mm&lt;/xsl:variable&gt;</strong>
  70. &lt;/xsl:stylesheet&gt;</code></pre>
  71. </figure></div>
  72. </li><li class="li step stepexpand">
  73. <span class="ph cmd">Create the <span class="ph filepath">cfg/fo/xsl/custom.xsl</span> file, and add XSLT overrides to it.</span>
  74. <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>
  75. <pre class="pre codeblock"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  76. &lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  77. xmlns:xs="http://www.w3.org/2001/XMLSchema"
  78. xmlns:fo="http://www.w3.org/1999/XSL/Format"
  79. version="2.0"&gt;
  80. &lt;!-- Move figure title to top and description to bottom --&gt;
  81. &lt;xsl:template match="*[contains(@class,' topic/fig ')]"&gt;
  82. &lt;fo:block xsl:use-attribute-sets="fig"&gt;
  83. &lt;xsl:call-template name="commonattributes"/&gt;
  84. &lt;xsl:if test="not(@id)"&gt;
  85. &lt;xsl:attribute name="id"&gt;
  86. &lt;xsl:call-template name="get-id"/&gt;
  87. &lt;/xsl:attribute&gt;
  88. &lt;/xsl:if&gt;
  89. &lt;xsl:apply-templates select="*[contains(@class,' topic/title ')]"/&gt;
  90. &lt;xsl:apply-templates select="*[not(contains(@class,' topic/title ') or contains(@class,' topic/desc '))]"/&gt;
  91. &lt;xsl:apply-templates select="*[contains(@class,' topic/desc ')]"/&gt;
  92. &lt;/fo:block&gt;
  93. &lt;/xsl:template&gt;
  94. &lt;/xsl:stylesheet&gt;</code></pre>
  95. </figure></div>
  96. </li><li class="li step stepexpand">
  97. <span class="ph cmd">Create an English-language variable-definition file (<span class="ph filepath">cfg/common/vars/en.xml</span>) and make
  98. any necessary modifications to it.</span>
  99. <div class="itemgroup stepxmp">For example, the following code removes the period after the number for an ordered-list item; it also
  100. 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>
  101. <pre class="pre codeblock"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  102. &lt;vars xmlns="http://www.idiominc.com/opentopic/vars"&gt;
  103. &lt;!-- Remove dot from list number --&gt;
  104. &lt;variable id="Ordered List Number"&gt;&lt;param ref-name="number"/&gt;&lt;/variable&gt;
  105. &lt;!-- Change unordered list bullet to an em dash --&gt;
  106. &lt;variable id="Unordered List bullet"&gt;&amp;#x2014;&lt;/variable&gt;
  107. &lt;/vars&gt;</code></pre>
  108. </figure></div>
  109. </li></ol>
  110. <section class="section result"><div class="tasklabel"><h2 class="sectiontitle tasklabel">Results</h2></div>
  111. <p class="p">The new plug-in directory has the following layout and files:</p>
  112. <pre class="pre codeblock"><code>com.example.print-pdf/
  113. cfg/
  114. common/
  115. vars/
  116. en.xml
  117. fo/
  118. attrs/
  119. custom.xsl
  120. xsl/
  121. custom.xsl
  122. catalog.xml
  123. integrator.xml
  124. plugin.xml</code></pre>
  125. </section>
  126. <section class="section postreq"><div class="tasklabel"><h2 class="sectiontitle tasklabel">What to do next</h2></div>
  127. <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
  128. available.</p>
  129. </section>
  130. </div>
  131. <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>