PDF: Whitespace in headings being replaced by spaces

This forum is for all Flare issues related to PDF, eBook, Microsoft Word, Adobe FrameMaker, XPS, and XHTML book targets.
Post Reply
FrankyT
Propeller Head
Posts: 56
Joined: Wed Apr 04, 2012 3:45 am
Location: United Kingdom

PDF: Whitespace in headings being replaced by spaces

Post by FrankyT »

I have a Flare document that was converted from another format via XSLT. The XSLT left carriage returns and tabs at the start of some text nodes. E.g.:

Code: Select all

        <h2>
			Sample GET response </h2>
For Web output this is not an issue, since browsers ignore initial whitespace characters. However, when I output to PDF, the carriage returns and tabs are converted to a space:
indented heading.PNG
I can't see what the point of this is; is it a bug? I'd rather not have to go through the whole document deleting carriage returns, as I have several other documents that were produced using the same script that also would need editing.

Just wondering if anyone else has come across this issue and, if so, were you able to fix it?

Thanks.
You do not have the required permissions to view the files attached to this post.
nickatwork
Sr. Propeller Head
Posts: 457
Joined: Thu Sep 16, 2010 6:31 am
Location: London

Re: PDF: Whitespace in headings being replaced by spaces

Post by nickatwork »

Hi,
That looks a bit annoying. Is it only with H2 levels, or just heading levels in particular? You could use a find/replace to remove the returns if that is the case.

It looks like there is a return and a single white space character in there as well. Turn on Show/Hide Spaces to see if there's one before the heading.

It can be removed with a regular expression, but if you confirm the above it will be eaier to target the right piece of code.

Nick
FrankyT
Propeller Head
Posts: 56
Joined: Wed Apr 04, 2012 3:45 am
Location: United Kingdom

Re: PDF: Whitespace in headings being replaced by spaces

Post by FrankyT »

Haven't revisited this thread till now, but the problem was not just with H2: it occurred with other elements as well.

In the end I edited the XSLT so that it stripped out the spaces at the source. This was easier than running the XSL stylesheet and then post-processing to get rid of the spaces.

This is the the XSLT template for anyone who's interested:

Code: Select all

    <xsl:template match="text()">
        <xsl:choose>
            <!-- Strip initial carriage return from all text nodes except those in code listings. This is because
                Flare replaces carriage returns with spaces: so if a paragraph (or heading, or whatever) 
                starts with a carriage return, Flare will display it with a spurious initial space. Even though its format is
                HTML, Flare doesn't behave like a browser and normalise spaces. If you output from Flare to HTML everything
                looks OK, but if you output to PDF the initial spaces remain. Hence this. (Code listings (<example-{x}>) are exempted because
                we want them to be displayed preformatted.) -->
            <xsl:when test="(starts-with(., '
')) and not (starts-with(name(parent::*), 'example'))">
                <xsl:value-of select="substring(., 2)"/>
            </xsl:when>
            <!-- Normalise spaces in anchors (for some reason there are otherwise spurious spaces at the beginnings of some links). -->
            <xsl:when test="parent::A|a">
                <xsl:value-of select="normalize-space(.)"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="."/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
The reference to "example" is specific to my document - there were <example-x> elements that I wanted this template to ignore.
Post Reply