pdf-customization-example.dita 6.2 KB

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