1
votes

I have a word document (.doc) that I have converted to an XSL-FO so that I can add a user's input, but the conversion wasn't the greatest so I am modifying the FO to match the original word document. The word document has line numbers going down the left side of each page. See screenshot of original .doc file. I found this article to be somewhat useful thanks to Dimitre Novatchev's answer, but I get a Stack Overflow exception with his solution. Mr. AH had a great solution, but I don't like the idea of manually adding the line number to every line on each page. Each page has 28 lines.

Is there something I can do that is similar to a header or footer?

Or would it make sense to create the line numbers with an image and insert the image on each page?

I'm using Apache's FOP 1.0 library with Java driving in the background. (upgrading to 2.0 is not an option)

My .fo file:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:fo="http://www.w3.org/1999/XSL/Format"       xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xml:space="preserve">
<xsl:strip-space elements="fo:inline"/>
<fo:root xmlns:myHelper="com.my.path.XslHelper"
     xmlns:svg="http://www\.w3\.org/2000/svg"
     xmlns:exsl="http://xmlns.opentechnology.org/xslt-extensions/common" 
     xmlns:fo="http://www.w3.org/1999/XSL/Format" 
     xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml"
     xmlns:st1="urn:schemas-microsoft-com:office:smarttags" >
<fo:layout-master-set xmlns:rx="http://www.renderx.com/XSL/Extensions" 
                    xmlns:o="urn:schemas-microsoft-com:office:office" 
                    xmlns:v="urn:schemas-microsoft-com:vml" 
                    xmlns:wx="http://schemas.microsoft.com/office/word/2003/auxHint" 
                    xmlns:aml="http://schemas.microsoft.com/aml/2001/core" 
                    xmlns:w10="urn:schemas-microsoft-com:office:word" 
                    xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882">
<fo:simple-page-master master-name="simple" page-width="8.5in" page-height="11in" margin-top=".5in" margin-bottom=".3in" margin-left=".75in" margin-right=".7in">
  <fo:region-body region-name="xsl-region-body" margin-top=".50in" margin-bottom=".5in"/>
  <fo:region-before region-name="xsl-region-before" extent="5in"/>
  <fo:region-after region-name="xsl-region-after" extent=".5in"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence xmlns:rx="http://www.renderx.com/XSL/Extensions"
                xmlns:o="urn:schemas-microsoft-com:office:office"
                xmlns:v="urn:schemas-microsoft-com:vml"
                xmlns:wx="http://schemas.microsoft.com/office/word/2003/auxHint"
                xmlns:aml="http://schemas.microsoft.com/aml/2001/core"
                xmlns:w10="urn:schemas-microsoft-com:office:word"
                xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"
                master-reference="simple"
                id="IDDEWVO12VGWFHFXTK2ROJBGP3HLXLWHRYZMPQZ5NGVSECKDMKHTTH"
                format="1">
<fo:static-content flow-name="xsl-region-before">
    <fo:block></fo:block>
</fo:static-content>
<fo:static-content flow-name="xsl-region-after"> 
    <fo:block text-align="center"><fo:page-number/></fo:block>
</fo:static-content>
<fo:flow flow-name="xsl-region-body" font-family="TimesNewRoman" font-size="12pt" line-height="1.7205" language="EN-US">
  <fo:block widows="2" orphans="2" white-space-collapse="false" break-after="page">
      <xsl:variable name="confidentialChecked"><xsl:choose><xsl:when test="$livingTogether = 'Yes'">[x]</xsl:when><xsl:otherwise>[ ]</xsl:otherwise></xsl:choose></xsl:variable>
      <fo:inline>2.<xsl:value-of select="$spacer"/>My address is: <xsl:value-of select="$confidentialChecked"/> </fo:inline><fo:inline font-weight="bold" text-decoration="underline">CONFIDENTIAL</fo:inline><fo:inline> (If confidential, do not write address here)</fo:inline>
    </fo:block>
    <fo:block start-indent="36pt">
      <fo:inline>Address: <xsl:value-of select="concat($pl1_addressLine1, ' ', $pl1_addressLine2)"/></fo:inline>
    </fo:block>
    <fo:block start-indent="36pt">
      <fo:inline>City: <xsl:value-of select="$pl1_city"/> State: <xsl:value-of select="$pl1_state"/> Zip: <xsl:value-of select="$pl1_postalCode"/></fo:inline>
    </fo:block>
    <fo:block start-indent="36pt">
      <xsl:variable name="ownRent"><xsl:choose><xsl:when test="$pl1_ownOrRent = 'Own'">[x] own [ ] rent</xsl:when><xsl:when test="$pl1_ownOrRent = 'Rent'">[ ] own [x] rent</xsl:when><xsl:otherwise>[ ] own [ ] rent</xsl:otherwise></xsl:choose></xsl:variable>
      <fo:inline>I <xsl:value-of select="$ownRent"/> this residence. Lease/title is held in all the following name(s):</fo:inline>
    </fo:block>
    <fo:block text-indent="36pt">
      <fo:inline><xsl:value-of select="$pl1_residenceLeaseNames"/></fo:inline>
    </fo:block>
    <fo:block start-indent="36pt">
      <fo:inline>How long have you been living in this residence? <xsl:value-of select="$pl1_timeAtResidence"/></fo:inline>
    </fo:block>
  </fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
</xsl:stylesheet>

I'm new to all of this FO stuff, so please let me know what other info you need to help me with this. Thanks in advance!

2
What you actually have in the screen shot is a ruler, not true line numbers. I would put that structure into a region in an absolute positioned container on the page. - Kevin Brown

2 Answers

1
votes

What your image shows is a ruler, not actual physical line numbers. Line numbers would align with the text, your image shows just an equally spaced set of content with numbers.

You could create something like that easily in several ways, here's some FO for your inspiration to adapt. You could adjust spacing, sizes or even use math to calculate what you need for these things.

<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:rx="http://www.renderx.com/XSL/Extensions">
<fo:layout-master-set>
    <fo:simple-page-master page-width="8.5in" page-height="11in" master-name="master">
        <fo:region-body margin-top="0.5in" margin-bottom="0.5in" margin-left="0.5in" margin-right="0.5in"/>
        <fo:region-before extent="11in"/>
    </fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="master">
    <fo:static-content flow-name="xsl-region-before">
        <fo:block-container margin-left="0.15in" margin-top="0.5in" line-height="26pt" width="12pt" text-align="right">
            <fo:block>1</fo:block>
            <fo:block>2</fo:block>
            <fo:block>3</fo:block>
            <fo:block>4</fo:block>
            <fo:block>5</fo:block>
            <fo:block>6</fo:block>
            <fo:block>7</fo:block>
            <fo:block>8</fo:block>
            <fo:block>9</fo:block>
            <fo:block>10</fo:block>
            <fo:block>11</fo:block>
            <fo:block>12</fo:block>
            <fo:block>13</fo:block>
            <fo:block>14</fo:block>
            <fo:block>15</fo:block>
            <fo:block>16</fo:block>
            <fo:block>17</fo:block>
            <fo:block>18</fo:block>
            <fo:block>19</fo:block>
            <fo:block>20</fo:block>
            <fo:block>21</fo:block>
            <fo:block>22</fo:block>
            <fo:block>23</fo:block>
            <fo:block>24</fo:block>
            <fo:block>25</fo:block>
            <fo:block>26</fo:block>
            <fo:block>27</fo:block>
            <fo:block>28</fo:block>
        </fo:block-container>
    </fo:static-content>
    <fo:flow flow-name="xsl-region-body">
        <fo:block>Test</fo:block>
        <fo:block space-before="12pt">Eos sed aliquam diam sanctus duis facilisis clita. Euismod accusam eu blandit autem dolores ullamcorper illum amet molestie et sadipscing sea et ut dolore stet dolor. Ullamcorper invidunt stet hendrerit lorem ex clita ipsum luptatum elitr aliquyam accusam vero. Voluptua sadipscing nonumy ea sit consequat et et diam amet vulputate. Nulla ea odio duo consetetur elitr stet eos. Stet amet aliquyam duis.</fo:block>
        <fo:block space-before="12pt">Eos sed aliquam diam sanctus duis facilisis clita. Euismod accusam eu blandit autem dolores ullamcorper illum amet molestie et sadipscing sea et ut dolore stet dolor. Ullamcorper invidunt stet hendrerit lorem ex clita ipsum luptatum elitr aliquyam accusam vero. Voluptua sadipscing nonumy ea sit consequat et et diam amet vulputate. Nulla ea odio duo consetetur elitr stet eos. Stet amet aliquyam duis.</fo:block>
        <fo:block space-before="12pt">Eos sed aliquam diam sanctus duis facilisis clita. Euismod accusam eu blandit autem dolores ullamcorper illum amet molestie et sadipscing sea et ut dolore stet dolor. Ullamcorper invidunt stet hendrerit lorem ex clita ipsum luptatum elitr aliquyam accusam vero. Voluptua sadipscing nonumy ea sit consequat et et diam amet vulputate. Nulla ea odio duo consetetur elitr stet eos. Stet amet aliquyam duis.</fo:block>
    </fo:flow>
</fo:page-sequence>
</fo:root>

This yields this output in FOP:

enter image description here

0
votes

A normal, single-pass XSL-FO process cannot produce line numbering. There is no command that supports this. And as Kevin shows in his example, it's really difficult to line up fixed line numbers with a text that has variable height.

There are formatters that use extensions to support line numbering: Antennahouse Formatter has the axf:line-number extension, for instance.