xml – 如何为xsl-fo中的每个页面添加页眉和页脚以生成pdf

前端之家收集整理的这篇文章主要介绍了xml – 如何为xsl-fo中的每个页面添加页眉和页脚以生成pdf前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
请找到以下xsl-fo,尝试为pdf中的每个页面设置页眉和页脚,但在第一页和第页的页脚只有页眉.但这里我需要每一页.如何执行这个
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
  3. <xsl:template match='/'>
  4. <fo:root>
  5. <fo:layout-master-set>
  6. <fo:simple-page-master master-name="my-page"
  7. page-height="29.7cm"
  8. page-width="21cm"
  9. margin-top="1cm"
  10. margin-bottom="0.1cm"
  11. margin-left="0.8cm"
  12. margin-right="1.0cm" >
  13. <fo:region-body margin-top="2.5cm" margin-bottom="2.5cm"/>
  14. <fo:region-before extent="2.0cm"/>
  15. <fo:region-after extent="2.0cm"/>
  16. </fo:simple-page-master>
  17. </fo:layout-master-set>
  18. <fo:page-sequence master-reference="my-page">
  19. <fo:flow flow-name="xsl-region-before">
  20. <fo:block>
  21. Message Body
  22. </fo:block>
  23. </fo:flow>
  24. <fo:flow flow-name="xsl-region-body">
  25. Message Content
  26. </fo:flow>
  27.  
  28. <fo:flow flow-name="xsl-region-after">
  29. <h2>
  30. Page Footer
  31. </h2>
  32. </fo:flow>
  33. </fo:page-sequence>
  34. </fo:root>
  35. </xsl:template>
  36. <xsl:template name="replace-returns">
  37. <xsl:param name="text"/>
  38. <xsl:choose>
  39. <xsl:when test="contains($text,'&#xa;')">
  40. <xsl:value-of select="substring-before($text,'&#xa;')"/>
  41. <xsl:value-of select="'&lt;br /&gt;'" disable-output-escaping="yes"/>
  42. <xsl:call-template name="replace-returns">
  43. <xsl:with-param name="text" select="substring-after($text,'&#xa;')"/>
  44. </xsl:call-template>
  45. </xsl:when>
  46. <xsl:otherwise>
  47. <xsl:value-of select="$text"/>
  48. </xsl:otherwise>
  49. </xsl:choose>
  50. </xsl:template>
以下是关于如何在每个页面获取页眉和页脚的简单示例.希望这可以帮助
  1. <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
  2. <fo:layout-master-set>
  3. <fo:simple-page-master master-name="simple" page-height="11in" page-width="8.5in" margin-top=".5in" margin-bottom=".5in" margin-left=".5in" margin-right=".5in">
  4. <fo:region-body region-name="xsl-region-body" margin-bottom=".5in" margin-top=".50in"/>
  5. <fo:region-before region-name="xsl-region-before" extent="5in"/>
  6. <fo:region-after region-name="xsl-region-after" extent=".5in"/>
  7. </fo:simple-page-master>
  8. </fo:layout-master-set>
  9. <fo:page-sequence master-reference="simple">
  10. <fo:static-content flow-name="xsl-region-before">
  11. <fo:block>header</fo:block>
  12. </fo:static-content>
  13. <fo:static-content flow-name="xsl-region-after">
  14. <fo:block>footer</fo:block>
  15. </fo:static-content>
  16. <fo:flow flow-name="xsl-region-body">
  17. <fo:block break-after="page">
  18. Body
  19. </fo:block>
  20. <fo:block>
  21. Body
  22. </fo:block>
  23. </fo:flow>
  24. </fo:page-sequence>
  25. </fo:root>

猜你在找的XML相关文章