pdf-customization-example.dita 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE task PUBLIC "-//OASIS//DTD DITA Task//EN" "task.dtd">
  3. <!-- This file is part of the DITA Open Toolkit project. See the accompanying LICENSE file for applicable license. -->
  4. <task id="dita2pdf-customization" xml:lang="en">
  5. <title>Example: Creating a simple PDF plug-in</title>
  6. <titlealts>
  7. <navtitle>Simple PDF plug-in example</navtitle>
  8. </titlealts>
  9. <shortdesc>This scenario walks through the process of creating a very simple plug-in
  10. (<codeph>com.example.print-pdf</codeph>) that creates a new transformation type: <option>print-pdf</option>. </shortdesc>
  11. <taskbody>
  12. <context>
  13. <p>The <option>print-pdf</option> transformation has the following characteristics:</p>
  14. <ul>
  15. <li>Uses A4 paper </li>
  16. <li>Renders figures with a title at the top and a description at the bottom</li>
  17. <li>Use em dashes as the symbols for unordered lists</li>
  18. </ul>
  19. </context>
  20. <steps>
  21. <step>
  22. <cmd>In the <filepath>plugins</filepath> directory, create a directory named
  23. <filepath>com.example.print-pdf</filepath>.</cmd>
  24. </step>
  25. <step>
  26. <cmd>In the new <filepath>com.example.print-pdf</filepath> directory, create a plug-in configuration file
  27. (<filepath>plugin.xml</filepath>) that declares the new <option>print-pdf</option> transformation and its
  28. dependencies.</cmd>
  29. <info>
  30. <fig>
  31. <title><filepath>plugin.xml</filepath> file</title>
  32. <codeblock>&lt;?xml version='1.0' encoding='UTF-8'?>
  33. &lt;plugin id="com.example.print-pdf">
  34. &lt;require plugin="org.dita.pdf2"/>
  35. &lt;feature extension="dita.conductor.transtype.check" value="print-pdf"/>
  36. &lt;feature extension="dita.transtype.print" value="print-pdf"/>
  37. &lt;feature extension="dita.conductor.target.relative" file="integrator.xml"/>
  38. &lt;/plugin></codeblock>
  39. </fig>
  40. </info>
  41. </step>
  42. <step>
  43. <cmd>Add an Ant script (<filepath>integrator.xml</filepath>) to define the transformation type.</cmd>
  44. <info>
  45. <fig>
  46. <title><filepath>integrator.xml</filepath> file</title>
  47. <codeblock>&lt;?xml version='1.0' encoding='UTF-8'?>
  48. &lt;project name="com.example.print-pdf">
  49. &lt;target name="dita2print-pdf.init">
  50. &lt;property name="customization.dir" location="${dita.plugin.com.example.print-pdf.dir}/cfg"/>
  51. &lt;/target>
  52. &lt;target name="dita2print-pdf" depends="dita2print-pdf.init, dita2pdf2"/>
  53. &lt;/project></codeblock>
  54. </fig></info>
  55. </step>
  56. <step>
  57. <cmd>In the new plug-in directory, add a <filepath>cfg/catalog.xml</filepath> file that specifies the custom
  58. XSLT style sheets.</cmd>
  59. <stepxmp>
  60. <fig>
  61. <title><filepath>cfg/catalog.xml</filepath> file</title>
  62. <codeblock>&lt;?xml version="1.0" encoding="UTF-8"?>
  63. &lt;catalog prefer="system" xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
  64. &lt;uri name="cfg:fo/attrs/custom.xsl" uri="fo/attrs/custom.xsl"/>
  65. &lt;uri name="cfg:fo/xsl/custom.xsl" uri="fo/xsl/custom.xsl"/>
  66. &lt;/catalog></codeblock>
  67. </fig>
  68. </stepxmp>
  69. </step>
  70. <step>
  71. <cmd>Create the <filepath>cfg/fo/attrs/custom.xsl</filepath> file, and add attribute and variable overrides to
  72. it.</cmd>
  73. <stepxmp>For example, add the content highlighted with bold to change the page size to A4.<fig>
  74. <title><filepath>cfg/fo/attrs/custom.xsl</filepath> file</title>
  75. <codeblock>&lt;?xml version="1.0" encoding="UTF-8"?>
  76. &lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  77. version="2.0">
  78. <b> &lt;!-- Change page size to A4 -->
  79. &lt;xsl:variable name="page-width">210mm&lt;/xsl:variable>
  80. &lt;xsl:variable name="page-height">297mm&lt;/xsl:variable></b>
  81. &lt;/xsl:stylesheet></codeblock>
  82. </fig></stepxmp>
  83. </step>
  84. <step>
  85. <cmd>Create the <filepath>cfg/fo/xsl/custom.xsl</filepath> file, and add XSLT overrides to it.</cmd>
  86. <stepxmp>For example, the following code changes the rendering of <xmlelement>figure</xmlelement> elements.<fig>
  87. <title><filepath>cfg/fo/xsl/custom.xsl</filepath> file</title>
  88. <codeblock>&lt;?xml version="1.0" encoding="UTF-8"?>
  89. &lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  90. xmlns:xs="http://www.w3.org/2001/XMLSchema"
  91. xmlns:fo="http://www.w3.org/1999/XSL/Format"
  92. version="2.0">
  93. &lt;!-- Move figure title to top and description to bottom -->
  94. &lt;xsl:template match="*[contains(@class,' topic/fig ')]">
  95. &lt;fo:block xsl:use-attribute-sets="fig">
  96. &lt;xsl:call-template name="commonattributes"/>
  97. &lt;xsl:if test="not(@id)">
  98. &lt;xsl:attribute name="id">
  99. &lt;xsl:call-template name="get-id"/>
  100. &lt;/xsl:attribute>
  101. &lt;/xsl:if>
  102. &lt;xsl:apply-templates select="*[contains(@class,' topic/title ')]"/>
  103. &lt;xsl:apply-templates select="*[not(contains(@class,' topic/title ') or contains(@class,' topic/desc '))]"/>
  104. &lt;xsl:apply-templates select="*[contains(@class,' topic/desc ')]"/>
  105. &lt;/fo:block>
  106. &lt;/xsl:template>
  107. &lt;/xsl:stylesheet></codeblock>
  108. </fig></stepxmp>
  109. </step>
  110. <step>
  111. <cmd>Create an English-language variable-definition file (<filepath>cfg/common/vars/en.xml</filepath>) and make
  112. any necessary modifications to it.</cmd>
  113. <stepxmp>For example, the following code removes the period after the number for an ordered-list item; it also
  114. specifies that the bullet for an unordered list item should be an em dash.<fig>
  115. <title><filepath>cfg/common/vars/en.xml</filepath> file</title>
  116. <codeblock>&lt;?xml version="1.0" encoding="UTF-8"?>
  117. &lt;vars xmlns="http://www.idiominc.com/opentopic/vars">
  118. &lt;!-- Remove dot from list number -->
  119. &lt;variable id="Ordered List Number">&lt;param ref-name="number"/>&lt;/variable>
  120. &lt;!-- Change unordered list bullet to an em dash -->
  121. &lt;variable id="Unordered List bullet">&amp;#x2014;&lt;/variable>
  122. &lt;/vars></codeblock>
  123. </fig></stepxmp>
  124. </step>
  125. </steps>
  126. <result>
  127. <p>The new plug-in directory has the following layout and files:</p>
  128. <codeblock>com.example.print-pdf/
  129. cfg/
  130. common/
  131. vars/
  132. en.xml
  133. fo/
  134. attrs/
  135. custom.xsl
  136. xsl/
  137. custom.xsl
  138. catalog.xml
  139. integrator.xml
  140. plugin.xml</codeblock>
  141. </result>
  142. <postreq>
  143. <p>Run <filepath conref="../resources/conref-task.dita#ID/dita-cmd"/>
  144. <parmname>--install</parmname> to install the plug-in and make the <option>print-pdf</option> transformation
  145. available.</p>
  146. </postreq>
  147. </taskbody>
  148. </task>