White space in FO causes PDF TOC problem

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

White space in FO causes PDF TOC problem

Mark Giffin
I'm using FOP 2.3 with the DITA Open Toolkit. The <title> tags in DITA
topics are used in the table of contents in a PDF. Each table of
contents line is justified like this in the PDF:

(left margin)Intro to
XYZ........................................................14(right margin)
(left margin)Setting Up
XYZ...................................................18(right margin)

Most lines line up neatly on the right margin, but a few do not go to
the margin. The cause of a line that does not go all the way to the
right margin is a <title> tag with white space in it like this:

<title>
   Do This First
</title>

This white space gets copied over to the XSL-FO produced by the DITA OT:

height="150%"><fo:inline end-indent="14pt">
         Do This First
     </fo:inline><fo:inline color="black"
keep-together.within-line="always" start-indent="-14pt"><fo:leader
color="black" leader-pattern="dots"/><fo:page-number-citation...

And FOP renders this in the PDF like this, where the line does not go
all the way to the right margin:

(left margin)Do This
First....................................................10 (right margin)
(left margin)Intro to
XYZ........................................................14(right margin)
(left margin)Setting Up
XYZ...................................................18(right margin)

When I remove the whitespace in the XSL-FO, the line renders correctly,
all the way to the right margin. Both Antenna House and XEP render the
line correctly, ignoring the extraneous whitespace. This seems like a
FOP bug, is there a fix for this? Other than removing the whitespace?

Thanks,
Mark


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: White space in FO causes PDF TOC problem

Matthias Reischenbacher
Hi,

yes, this is an unresolved FOP bug, see also:

https://issues.apache.org/jira/browse/FOP-1952

https://issues.apache.org/jira/browse/FOP-1839

Best regards,

Matthias


On 26.11.2018 01:21, Mark Giffin wrote:

> I'm using FOP 2.3 with the DITA Open Toolkit. The <title> tags in DITA
> topics are used in the table of contents in a PDF. Each table of
> contents line is justified like this in the PDF:
>
> (left margin)Intro to
> XYZ........................................................14(right
> margin)
> (left margin)Setting Up
> XYZ...................................................18(right margin)
>
> Most lines line up neatly on the right margin, but a few do not go to
> the margin. The cause of a line that does not go all the way to the
> right margin is a <title> tag with white space in it like this:
>
> <title>
>   Do This First
> </title>
>
> This white space gets copied over to the XSL-FO produced by the DITA OT:
>
> height="150%"><fo:inline end-indent="14pt">
>         Do This First
>     </fo:inline><fo:inline color="black"
> keep-together.within-line="always" start-indent="-14pt"><fo:leader
> color="black" leader-pattern="dots"/><fo:page-number-citation...
>
> And FOP renders this in the PDF like this, where the line does not go
> all the way to the right margin:
>
> (left margin)Do This
> First....................................................10 (right
> margin)
> (left margin)Intro to
> XYZ........................................................14(right
> margin)
> (left margin)Setting Up
> XYZ...................................................18(right margin)
>
> When I remove the whitespace in the XSL-FO, the line renders
> correctly, all the way to the right margin. Both Antenna House and XEP
> render the line correctly, ignoring the extraneous whitespace. This
> seems like a FOP bug, is there a fix for this? Other than removing the
> whitespace?
>
> Thanks,
> Mark
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: White space in FO causes PDF TOC problem

kibukj
In reply to this post by Mark Giffin
If you can modify the XSLT stylesheets a little, you could use
normalize-space() to automatically remove the whitespace.

Something like this:

<xsl:template match="title" mode="toc">
  <fo:inline>
    <xsl:value-of select="normalize-space()"/>
  </fo:inline>
</xsl:template>

This won't work if you need to handle other kinds of elements in <title>
tags besides text nodes though, like <title><b>Bold</b> text</title>.

Another solution could be to run the XML input through a pretty-printer
(or rather, the opposite of one) that removes this "insignificant"
whitespace before applying the XSLT.

I had a similar problem (but not specifically related to
XSL-FO/FOP) where I wanted to remove extra whitespace from
certain elements. I ended up writing this small utility:
https://github.com/kibook/xml-utils/tree/master/xml-trimspace

This is basically the reverse-pretty-printer described above, but it
targets only specified elements, so that ones where "extra" whitespace
might actually be significant are ignored.

Example usage:

[input.xml]
<section>
  <title>
    Do <b>This</b> First
  </title>
</section>

$ xml-trimspace title < input.xml > output.xml

[output.xml]
<section>
  <title>Do <b>This</b> First</title>
</section>

Mark Giffin <[hidden email]> wrote:

> I'm using FOP 2.3 with the DITA Open Toolkit. The <title> tags in DITA
> topics are used in the table of contents in a PDF. Each table of
> contents line is justified like this in the PDF:
>
> (left margin)Intro to
> XYZ........................................................14(right margin)
> (left margin)Setting Up
> XYZ...................................................18(right margin)
>
> Most lines line up neatly on the right margin, but a few do not go to
> the margin. The cause of a line that does not go all the way to the
> right margin is a <title> tag with white space in it like this:
>
> <title>
>    Do This First
> </title>
>
> This white space gets copied over to the XSL-FO produced by the DITA OT:
>
> height="150%"><fo:inline end-indent="14pt">
>          Do This First
>      </fo:inline><fo:inline color="black"
> keep-together.within-line="always" start-indent="-14pt"><fo:leader
> color="black" leader-pattern="dots"/><fo:page-number-citation...
>
> And FOP renders this in the PDF like this, where the line does not go
> all the way to the right margin:
>
> (left margin)Do This
> First....................................................10 (right margin)
> (left margin)Intro to
> XYZ........................................................14(right margin)
> (left margin)Setting Up
> XYZ...................................................18(right margin)
>
> When I remove the whitespace in the XSL-FO, the line renders correctly,
> all the way to the right margin. Both Antenna House and XEP render the
> line correctly, ignoring the extraneous whitespace. This seems like a
> FOP bug, is there a fix for this? Other than removing the whitespace?
>
> Thanks,
> Mark

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]