You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@forrest.apache.org by Eric BURGHARD <eb...@free.fr> on 2003/09/16 12:11:38 UTC

table of contents in pdf

Hi,

Don't know if this is interresting for someone down here, anyway it is 
valuable for me. this address two issues (from my point of view) of the 
document2fo.xsl stylesheet:
- generate table of contents
- correct font size computation for section/subsection/subsubsection

1- table of contents
Add this somewhere in your skin xslt/fo/document2fo.xsl after the
<xsl:import href="../../../common/xslt/fo/document2fo.xsl"/>
---
    <xsl:template match="body">
        <xsl:if test="count(//section) != 0">
            <fo:block font-family="serif" font-size="14pt" font-weight="bold" 
space-after="5pt" space-before="5pt" text-align="justify" width="7.5in"> 
<!-- insert i18n stuff here -->
Table of contents
 </fo:block>
            <fo:block font-family="sans" font-size="12pt" space-after="5pt" 
space-before="0pt" text-align="justify" width="7.5in">
                <xsl:apply-templates mode="toc"/>
            </fo:block>
        </xsl:if>
        <xsl:apply-templates/>
    </xsl:template>
    <!-- -->
    <xsl:template match="section" mode="toc">
        <fo:block space-before="5pt" text-align-last="justify">
            <fo:inline>
                <xsl:number count="section" format="1.1.1.1.1.1.1" 
level="multiple"/>
                <xsl:text>. </xsl:text>
                <xsl:value-of select="title"/>
                <fo:leader leader-pattern="dots"/>
                <fo:page-number-citation ref-id="{generate-id(  )}"/>
            </fo:inline>
            <xsl:apply-templates mode="toc2" select="section"/>
        </fo:block>
    </xsl:template>
    <!-- -->
    <xsl:template match="section" mode="toc2">
        <fo:block start-indent=".5em" text-align-last="justify" 
text-indent=".5em">
            <fo:inline padding-start="1em">
                <xsl:number count="section" format="1.1.1.1.1.1.1" 
level="multiple"/>
                <xsl:text>. </xsl:text>
                <xsl:value-of select="title"/>
                <fo:leader leader-pattern="dots"/>
                <fo:page-number-citation ref-id="{generate-id(  )}"/>
            </fo:inline>
        </fo:block>
    </xsl:template>
----

2- font size for section/subsection/subsubsection
in the <xsl:template match="section">, replace the <xsl:variable name="size"> 
block by this one:
----
    <xsl:variable name="size">
        <xsl:value-of select="14-number($level)"/>
    </xsl:variable>
----

A+


Re: table of contents in pdf

Posted by Juan Jose Pablos <ch...@che-che.com>.
Eric, Antonio,

I will have a look later, but usually improves a lot when if has been 
forward using diff -u

Cheers,
Cheche

Antonio Gallardo wrote:
> Hi Eric,
> 
> this is a very nice idea. I hope you can see it implemented soon in
> Forrest :)
> 
> Best Regards,
> 
> Antonio Gallardo
> 
> Eric BURGHARD dijo:
> 
>>Hi,
>>
>>Don't know if this is interresting for someone down here, anyway it is
>>valuable for me. this address two issues (from my point of view) of the
>>document2fo.xsl stylesheet:
>>- generate table of contents
>>- correct font size computation for section/subsection/subsubsection
>>
>>1- table of contents
>>Add this somewhere in your skin xslt/fo/document2fo.xsl after the
>><xsl:import href="../../../common/xslt/fo/document2fo.xsl"/>
>>---
>>    <xsl:template match="body">
>>        <xsl:if test="count(//section) != 0">
>>            <fo:block font-family="serif" font-size="14pt"
>>font-weight="bold"
>>space-after="5pt" space-before="5pt" text-align="justify" width="7.5in">
>> <!-- insert i18n stuff here -->
>>Table of contents
>> </fo:block>
>>            <fo:block font-family="sans" font-size="12pt"
>>space-after="5pt"
>>space-before="0pt" text-align="justify" width="7.5in">
>>                <xsl:apply-templates mode="toc"/>
>>            </fo:block>
>>        </xsl:if>
>>        <xsl:apply-templates/>
>>    </xsl:template>
>>    <!-- -->
>>    <xsl:template match="section" mode="toc">
>>        <fo:block space-before="5pt" text-align-last="justify">
>>            <fo:inline>
>>                <xsl:number count="section" format="1.1.1.1.1.1.1"
>>level="multiple"/>
>>                <xsl:text>. </xsl:text>
>>                <xsl:value-of select="title"/>
>>                <fo:leader leader-pattern="dots"/>
>>                <fo:page-number-citation ref-id="{generate-id(  )}"/>
>>            </fo:inline>
>>            <xsl:apply-templates mode="toc2" select="section"/>
>>        </fo:block>
>>    </xsl:template>
>>    <!-- -->
>>    <xsl:template match="section" mode="toc2">
>>        <fo:block start-indent=".5em" text-align-last="justify"
>>text-indent=".5em">
>>            <fo:inline padding-start="1em">
>>                <xsl:number count="section" format="1.1.1.1.1.1.1"
>>level="multiple"/>
>>                <xsl:text>. </xsl:text>
>>                <xsl:value-of select="title"/>
>>                <fo:leader leader-pattern="dots"/>
>>                <fo:page-number-citation ref-id="{generate-id(  )}"/>
>>            </fo:inline>
>>        </fo:block>
>>    </xsl:template>
>>----
>>
>>2- font size for section/subsection/subsubsection
>>in the <xsl:template match="section">, replace the <xsl:variable
>>name="size">  block by this one:
>>----
>>    <xsl:variable name="size">
>>        <xsl:value-of select="14-number($level)"/>
>>    </xsl:variable>
>>----
>>
>>A+
> 
> 
> 



Re: table of contents in pdf

Posted by Antonio Gallardo <ag...@agsoftware.dnsalias.com>.
Hi Eric,

this is a very nice idea. I hope you can see it implemented soon in
Forrest :)

Best Regards,

Antonio Gallardo

Eric BURGHARD dijo:
> Hi,
>
> Don't know if this is interresting for someone down here, anyway it is
> valuable for me. this address two issues (from my point of view) of the
> document2fo.xsl stylesheet:
> - generate table of contents
> - correct font size computation for section/subsection/subsubsection
>
> 1- table of contents
> Add this somewhere in your skin xslt/fo/document2fo.xsl after the
> <xsl:import href="../../../common/xslt/fo/document2fo.xsl"/>
> ---
>     <xsl:template match="body">
>         <xsl:if test="count(//section) != 0">
>             <fo:block font-family="serif" font-size="14pt"
> font-weight="bold"
> space-after="5pt" space-before="5pt" text-align="justify" width="7.5in">
>  <!-- insert i18n stuff here -->
> Table of contents
>  </fo:block>
>             <fo:block font-family="sans" font-size="12pt"
> space-after="5pt"
> space-before="0pt" text-align="justify" width="7.5in">
>                 <xsl:apply-templates mode="toc"/>
>             </fo:block>
>         </xsl:if>
>         <xsl:apply-templates/>
>     </xsl:template>
>     <!-- -->
>     <xsl:template match="section" mode="toc">
>         <fo:block space-before="5pt" text-align-last="justify">
>             <fo:inline>
>                 <xsl:number count="section" format="1.1.1.1.1.1.1"
> level="multiple"/>
>                 <xsl:text>. </xsl:text>
>                 <xsl:value-of select="title"/>
>                 <fo:leader leader-pattern="dots"/>
>                 <fo:page-number-citation ref-id="{generate-id(  )}"/>
>             </fo:inline>
>             <xsl:apply-templates mode="toc2" select="section"/>
>         </fo:block>
>     </xsl:template>
>     <!-- -->
>     <xsl:template match="section" mode="toc2">
>         <fo:block start-indent=".5em" text-align-last="justify"
> text-indent=".5em">
>             <fo:inline padding-start="1em">
>                 <xsl:number count="section" format="1.1.1.1.1.1.1"
> level="multiple"/>
>                 <xsl:text>. </xsl:text>
>                 <xsl:value-of select="title"/>
>                 <fo:leader leader-pattern="dots"/>
>                 <fo:page-number-citation ref-id="{generate-id(  )}"/>
>             </fo:inline>
>         </fo:block>
>     </xsl:template>
> ----
>
> 2- font size for section/subsection/subsubsection
> in the <xsl:template match="section">, replace the <xsl:variable
> name="size">  block by this one:
> ----
>     <xsl:variable name="size">
>         <xsl:value-of select="14-number($level)"/>
>     </xsl:variable>
> ----
>
> A+




Re: table of contents in pdf

Posted by Juan Jose Pablos <ch...@che-che.com>.
David Crossley wrote:
> Eric BURGHARD wrote:
>>That's what i like in open source dev. just give the stuff and it will go its 
>>way (even a little thing like this patch).
> 
> 
> Yes, it is organic. The beauty is that other people will
> build upon your contribution. Everyone wins.

LOL!! open source code is organic and fat free.

Cheers,
cheche


Re: table of contents in pdf

Posted by David Crossley <cr...@indexgeo.com.au>.
Eric BURGHARD wrote:
<snip/>

Thanks for your work with this, Eric.

> That's what i like in open source dev. just give the stuff and it will go its 
> way (even a little thing like this patch).

Yes, it is organic. The beauty is that other people will
build upon your contribution. Everyone wins.

> If i had some time, i will try to add pdf links with the toc (i think this can 
> done with a saxon docbook extension).

That would be good. However, we cannot put any processor-specific
extensions into the distribution. Perhaps if it can detect that Saxon
is being used, then this capability could be added.

--David



Re: table of contents in pdf

Posted by Eric BURGHARD <eb...@free.fr>.
Le Jeudi 18 Septembre 2003 16:49, Juan Jose Pablos a écrit :
> Eric BURGHARD wrote:
> > no it's my fault because the solution was not here and the implementation
> > is in fact pretty mmmm... basic: just add an fo:basic-link tag like this
>
> Thanks, I added to CVS. But I have not been able to see this basic link.
> Maybe it is a problem with my kghostview. Would you mind test it?
>

yes it is. right clic and open with xpdf.

> > I don't really know how to contribute to forrest efficiently via patchs
> > submissions. I think it's simple with eclipse and cvs, but give the time
> > to find how (anyway any infos would be appreciated ;-)
> >
> > A+
>
> well, if you have got CVS setup ( as I assume)  when you modify a file
> "cvs diff -u file" is enough for me.
>

ok. thanks

> if you have not got cvs then diff -u file.old file.new will do.
>
>
> Cheers,
> Cheche


Re: table of contents in pdf

Posted by Juan Jose Pablos <ch...@che-che.com>.
Eric BURGHARD wrote:
> 
> no it's my fault because the solution was not here and the implementation is 
> in fact pretty mmmm... basic: just add an fo:basic-link tag like this
> 

Thanks, I added to CVS. But I have not been able to see this basic link. 
Maybe it is a problem with my kghostview. Would you mind test it?

> 
> I don't really know how to contribute to forrest efficiently via patchs 
> submissions. I think it's simple with eclipse and cvs, but give the time to 
> find how (anyway any infos would be appreciated ;-)
> 
> A+

well, if you have got CVS setup ( as I assume)  when you modify a file 
"cvs diff -u file" is enough for me.

if you have not got cvs then diff -u file.old file.new will do.


Cheers,
Cheche


Re: table of contents in pdf

Posted by Eric BURGHARD <eb...@free.fr>.
Le Jeudi 18 Septembre 2003 14:07, Juan Jose Pablos a écrit :
> Victor,
>
> I went back to the page, check the examples and I could not find
> <fox:bookmarks>. But I am pretty sure that I was that tag before
>
> I am sorry about giving misleading information.
>

no it's my fault because the solution was not here and the implementation is 
in fact pretty mmmm... basic: just add an fo:basic-link tag like this

    <xsl:template match="section" mode="toc">
        <fo:block space-before="5pt" text-align-last="justify">
            <fo:inline>
                <fo:basic-link internal-destination="{generate-id( )}">
                    <xsl:number count="section" format="1.1.1.1.1.1.1" 
level="multiple"/>
                    <xsl:text>. </xsl:text>
                    <xsl:value-of select="title"/>
                    <fo:leader leader-pattern="dots"/>
                    <fo:page-number-citation ref-id="{generate-id(  )}"/>
                </fo:basic-link>
            </fo:inline>
            <xsl:apply-templates mode="toc2" select="section"/>
        </fo:block>
    </xsl:template>
    <!-- -->
    <xsl:template match="section" mode="toc2">
        <fo:block start-indent=".5em" text-align-last="justify" 
text-indent=".5em">
            <fo:inline padding-start="1em">
                <fo:basic-link internal-destination="{generate-id( )}">
                    <xsl:number count="section" format="1.1.1.1.1.1.1" 
level="multiple"/>
                    <xsl:text>. </xsl:text>
                    <xsl:value-of select="title"/>
                    <fo:leader leader-pattern="dots"/>
                    <fo:page-number-citation ref-id="{generate-id(  )}"/>
                </fo:basic-link>
            </fo:inline>
        </fo:block>
    </xsl:template>

I don't really know how to contribute to forrest efficiently via patchs 
submissions. I think it's simple with eclipse and cvs, but give the time to 
find how (anyway any infos would be appreciated ;-)

A+


RE: table of contents in pdf

Posted by Victor Mote <vi...@outfitr.com>.
Juan Jose Pablos wrote:

> I went back to the page, check the examples and I could not find
> <fox:bookmarks>. But I am pretty sure that I was that tag before

In my mind the terms are confusing. Acrobat uses the term "bookmark", but
pdf uses the term "outline". The URL you gave is correct, and its title is
"PDF Bookmarks", but the element name to use is <fox:outline>.

> I am sorry about giving misleading information.

The confusion is our (FOP's) fault. We are trying to support two versions of
code from one web site, and it is understandable that this causes confusion.
I just wanted to clarify it for the Forrest developers.

Victor Mote


Re: table of contents in pdf

Posted by Juan Jose Pablos <ch...@che-che.com>.
Victor,

I went back to the page, check the examples and I could not find 
<fox:bookmarks>. But I am pretty sure that I was that tag before

I am sorry about giving misleading information.


Eric,

This this the tag i was talking about :

    <fox:bookmarks>
       <xsl:apply-templates select="body/section" mode="outline"/>
   </fox:bookmarks>

Cheers,
Cheche

Victor Mote wrote:
> Juan Jose Pablos wrote:
> 
> 
>>Fop provides some kind of extensions:
>>http://xml.apache.org/fop/extensions.html#bookmarks
>>
>>
>>But you need to check Java API, some of these extension does not work as
>>we are using maintenance brach.
>>
>>http://nagoya.apache.org/gump/javadoc/xml-fop-maintenance/build/ja
> 
> vadocs/index.html
> 
> All of the extensions documented on the FOP website work with currently
> released code (i.e. the maintenance branch), and, in general, the
> documentation under the "Home" tab applies to users of the current
> maintenance branch releases.
> 
> Victor Mote



RE: table of contents in pdf

Posted by Victor Mote <vi...@outfitr.com>.
Juan Jose Pablos wrote:

> Fop provides some kind of extensions:
> http://xml.apache.org/fop/extensions.html#bookmarks
>
>
> But you need to check Java API, some of these extension does not work as
> we are using maintenance brach.
>
> http://nagoya.apache.org/gump/javadoc/xml-fop-maintenance/build/ja
vadocs/index.html

All of the extensions documented on the FOP website work with currently
released code (i.e. the maintenance branch), and, in general, the
documentation under the "Home" tab applies to users of the current
maintenance branch releases.

Victor Mote


Re: table of contents in pdf

Posted by Juan Jose Pablos <ch...@che-che.com>.
Eric BURGHARD wrote:
> 
> If i had some time, i will try to add pdf links with the toc (i think this can 
> done with a saxon docbook extension).
> 

Fop provides some kind of extensions: 
http://xml.apache.org/fop/extensions.html#bookmarks


But you need to check Java API, some of these extension does not work as 
we are using maintenance brach.

http://nagoya.apache.org/gump/javadoc/xml-fop-maintenance/build/javadocs/index.html


Cheers,
Cheche


Re: table of contents in pdf

Posted by Eric BURGHARD <eb...@free.fr>.
Le Mercredi 17 Septembre 2003 01:12, Juan Jose Pablos a écrit :
> Eric BURGHARD wrote:
> > Don't know if this is interresting for someone down here, anyway it is
> > valuable for me. this address two issues (from my point of view) of the
> > document2fo.xsl stylesheet:
> > - generate table of contents
> > - correct font size computation for section/subsection/subsubsection
>
> I just added to CVS, PDF looks nicer thanks to you!
>

no thanks you ;-p

> > Add this somewhere in your skin xslt/fo/document2fo.xsl after the
> > <xsl:import href="../../../common/xslt/fo/document2fo.xsl"/>
>
> Most skins just imported from commons, so I added there.
>
> >     <xsl:template match="body">
> >         <xsl:if test="count(//section) != 0">
>
> I added this instead:
>
>   <xsl:template match="body[count(//section) != 0]">
>
> >         <xsl:value-of select="14-number($level)"/>
> > A+
>
> Yes A+, Clever.
>
>
>
> I added a toc-max-depth variable and a couple of ifs to display same toc
> for html and pdf.
>

That's what i like in open source dev. just give the stuff and it will go its 
way (even a little thing like this patch).

If i had some time, i will try to add pdf links with the toc (i think this can 
done with a saxon docbook extension).

> Cheers,
> cheche

ciao.


Re: table of contents in pdf

Posted by Juan Jose Pablos <ch...@che-che.com>.
Eric BURGHARD wrote:
> Don't know if this is interresting for someone down here, anyway it is 
> valuable for me. this address two issues (from my point of view) of the 
> document2fo.xsl stylesheet:
> - generate table of contents
> - correct font size computation for section/subsection/subsubsection
> 

I just added to CVS, PDF looks nicer thanks to you!


> Add this somewhere in your skin xslt/fo/document2fo.xsl after the
> <xsl:import href="../../../common/xslt/fo/document2fo.xsl"/>

Most skins just imported from commons, so I added there.


>     <xsl:template match="body">
>         <xsl:if test="count(//section) != 0">

I added this instead:

  <xsl:template match="body[count(//section) != 0]">


>         <xsl:value-of select="14-number($level)"/>
> A+

Yes A+, Clever.



I added a toc-max-depth variable and a couple of ifs to display same toc 
for html and pdf.

Cheers,
cheche