pdf-customization-example.dita 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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</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. <prolog>
  12. <metadata>
  13. <keywords>
  14. <indexterm><xmlelement>figure</xmlelement></indexterm>
  15. <indexterm>PDF
  16. <indexterm>plug-in</indexterm></indexterm>
  17. <indexterm>integrator.xml</indexterm>
  18. <indexterm>catalog
  19. <indexterm>example</indexterm></indexterm>
  20. </keywords>
  21. </metadata>
  22. </prolog>
  23. <taskbody>
  24. <context>
  25. <p>The <option>print-pdf</option> transformation has the following characteristics:</p>
  26. <ul>
  27. <li>Uses A4 paper </li>
  28. <li>Renders figures with a title at the top and a description at the bottom</li>
  29. <li>Use em dashes as the symbols for unordered lists</li>
  30. </ul>
  31. </context>
  32. <steps>
  33. <step>
  34. <cmd>In the <filepath>plugins</filepath> directory, create a directory named
  35. <filepath>com.example.print-pdf</filepath>.</cmd>
  36. </step>
  37. <step>
  38. <cmd>In the new <filepath>com.example.print-pdf</filepath> directory, create a plug-in configuration file
  39. (<filepath>plugin.xml</filepath>) that declares the new <option>print-pdf</option> transformation and its
  40. dependencies.</cmd>
  41. <info>
  42. <fig>
  43. <title><filepath>plugin.xml</filepath> file</title>
  44. <codeblock outputclass="language-xml normalize-space show-line-numbers show-whitespace"><coderef href="../samples/plugins/com.example.print-pdf/plugin.xml"/></codeblock>
  45. </fig>
  46. </info>
  47. </step>
  48. <step>
  49. <cmd>Add an Ant script (<filepath>integrator.xml</filepath>) to define the transformation type.</cmd>
  50. <info>
  51. <fig>
  52. <title><filepath>integrator.xml</filepath> file</title>
  53. <codeblock outputclass="language-xml normalize-space show-line-numbers show-whitespace"><coderef href="../samples/plugins/com.example.print-pdf/integrator.xml"/></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 outputclass="language-xml normalize-space show-line-numbers show-whitespace"><coderef href="../samples/plugins/com.example.print-pdf/cfg/catalog.xml"/></codeblock>
  63. </fig>
  64. </stepxmp>
  65. </step>
  66. <step>
  67. <cmd>Create the <filepath>cfg/fo/attrs/custom.xsl</filepath> file, and add attribute and variable overrides to
  68. it.</cmd>
  69. <stepxmp>For example, add the following variables to change the page size to A4.<fig>
  70. <title><filepath>cfg/fo/attrs/custom.xsl</filepath> file</title>
  71. <codeblock outputclass="language-xml normalize-space show-line-numbers show-whitespace"><coderef href="../samples/plugins/com.example.print-pdf/cfg/fo/attrs/custom.xsl"/></codeblock>
  72. </fig></stepxmp>
  73. </step>
  74. <step>
  75. <cmd>Create the <filepath>cfg/fo/xsl/custom.xsl</filepath> file, and add XSLT overrides to it.</cmd>
  76. <stepxmp>For example, the following code changes the rendering of <xmlelement>figure</xmlelement> elements.<fig>
  77. <title><filepath>cfg/fo/xsl/custom.xsl</filepath> file</title>
  78. <codeblock outputclass="language-xml normalize-space show-line-numbers show-whitespace"><coderef href="../samples/plugins/com.example.print-pdf/cfg/fo/xsl/custom.xsl"/></codeblock>
  79. </fig></stepxmp>
  80. </step>
  81. <step>
  82. <cmd>Create an English-language variable-definition file (<filepath>cfg/common/vars/en.xml</filepath>) and make
  83. any necessary modifications to it.</cmd>
  84. <stepxmp>For example, the following code removes the period after the number for an ordered-list item; it also
  85. specifies that the bullet for an unordered list item should be an em dash.<fig>
  86. <title><filepath>cfg/common/vars/en.xml</filepath> file</title>
  87. <codeblock outputclass="language-xml normalize-space show-line-numbers show-whitespace"><coderef href="../samples/plugins/com.example.print-pdf/cfg/common/vars/en.xml"/></codeblock>
  88. </fig></stepxmp>
  89. </step>
  90. </steps>
  91. <result>
  92. <note type="tip">The files for this sample plug-in are included in the DITA-OT installation directory under
  93. <filepath>docsrc/samples/plugins/com.example.print-pdf/</filepath> and on
  94. <xref href="https://github.com/dita-ot/docs/tree/develop/samples/plugins/com.example.print-pdf" format="html"
  95. scope="external">GitHub</xref>.</note>
  96. <p>The plug-in directory has the following layout and files:</p>
  97. <codeblock>com.example.print-pdf
  98. ├── cfg
  99. │   ├── catalog.xml
  100. │   ├── common
  101. │   │   └── vars
  102. │   │   └── en.xml
  103. │   └── fo
  104. │   ├── attrs
  105. │   │   └── custom.xsl
  106. │   └── xsl
  107. │   └── custom.xsl
  108. ├── integrator.xml
  109. └── plugin.xml</codeblock>
  110. </result>
  111. <postreq>
  112. <ol>
  113. <li>Run <filepath conkeyref="conref-task/dita-cmd"/>
  114. <parmname>--install</parmname> to install the plug-in and make the <option>print-pdf</option> transformation
  115. available.</li>
  116. <li>Build output with the new transformation type to verify that the plug-in works as intended.
  117. <codeblock><filepath conkeyref="conref-task/dita-cmd"/> <parmname>--input</parmname>=<varname>my.ditamap</varname> <parmname>--format</parmname>=<option>print-pdf</option></codeblock>
  118. </li>
  119. </ol>
  120. </postreq>
  121. </taskbody>
  122. </task>