Page 1 of 1
How to limit the bookmark level is PDF
Posted: Mon May 02, 2022 5:48 pm
by girishkanmas
Hi,
In the "<custom-plugin>\cfg\fo\attrs\custom.xsl" file, I have used the following line to control the TOC entry levels:
Code: Select all
<xsl:variable name="tocMaximumLevel">3</xsl:variable>
However, the PDF bookmarks lists all the level.
How to do I control bookmark levels as per the custom TOC levels.
Re: How to limit the bookmark level is PDF
Posted: Tue May 03, 2022 11:15 am
by julien_lacour
Hello,
The tocMaximumLevel XSLT parameter is not used by the bookmarks templates, however you can add it in the template generating the fo:bookmark elements like in the example below:
Code: Select all
<xsl:template match="*[contains(@class, ' topic/topic ')]" mode="bookmark">
<xsl:variable name="mapTopicref" select="key('map-id', @id)[1]" as="element()?"/>
<xsl:variable name="topicTitle">
<xsl:call-template name="getNavTitle"/>
</xsl:variable>
<xsl:variable name="topicLevel" as="xs:integer">
<xsl:apply-templates select="." mode="get-topic-level"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="$topicLevel < $tocMaximumLevel and
$mapTopicref[@toc = 'yes' or not(@toc)] or
not($mapTopicref)">
<fo:bookmark>
<xsl:attribute name="internal-destination">
<xsl:call-template name="generate-toc-id"/>
</xsl:attribute>
<xsl:if test="$bookmarkStyle!='EXPANDED'">
<xsl:attribute name="starting-state">hide</xsl:attribute>
</xsl:if>
<fo:bookmark-title>
<xsl:value-of select="normalize-space($topicTitle)"/>
</fo:bookmark-title>
<xsl:apply-templates mode="bookmark"/>
</fo:bookmark>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates mode="bookmark"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
This template will override the default template and you will obtain the result you want. And if you change the parameter value, it will apply on both toc and bookmarks.
Regards,
Julien
Re: How to limit the bookmark level is PDF
Posted: Wed May 04, 2022 6:50 pm
by girishkanmas
Hi Julien,
It worked like a charm!
Thank you so much.
Regards,
Girish
Re: How to limit the bookmark level is PDF
Posted: Tue Mar 07, 2023 2:00 pm
by sbhatt
Hi Julien,
I've tried the example that you shared and it works just fine. I did observe that the bookmarks, in this case, take the same number of levels as the TOC. Is there any way to keep the bookmarks level independent of the TOC level?
Thanks,
Somi
Re: How to limit the bookmark level is PDF
Posted: Tue Mar 07, 2023 6:12 pm
by julien_lacour
Hello,
If you want to keep the bookmark level independent of the toc level, you can create a custom parameter:
Code: Select all
<xsl:param name="bookmarksMaximumLevel" select="1"/>
Something similar to what's in org.dita.pdf2\cfg\fo\attrs\basic-settings.xsl.
And then use this parameter in your custom bookmarks processing template:
Code: Select all
<xsl:template match="*[contains(@class, ' topic/topic ')]" mode="bookmark">
<xsl:variable name="mapTopicref" select="key('map-id', @id)[1]" as="element()?"/>
<xsl:variable name="topicTitle">
<xsl:call-template name="getNavTitle"/>
</xsl:variable>
<xsl:variable name="topicLevel" as="xs:integer">
<xsl:apply-templates select="." mode="get-topic-level"/>
</xsl:variable>
<xsl:if test="$topicLevel <= $bookmarksMaximumLevel">
<xsl:choose>
<xsl:when test="$mapTopicref[@toc = 'yes' or not(@toc)] or
not($mapTopicref)">
<fo:bookmark>
<xsl:attribute name="internal-destination">
<xsl:call-template name="generate-toc-id"/>
</xsl:attribute>
<xsl:if test="$bookmarkStyle!='EXPANDED'">
<xsl:attribute name="starting-state">hide</xsl:attribute>
</xsl:if>
<fo:bookmark-title>
<xsl:value-of select="normalize-space($topicTitle)"/>
</fo:bookmark-title>
<xsl:apply-templates mode="bookmark"/>
</fo:bookmark>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates mode="bookmark"/>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:template>
Don't customize directly the org.dita.pdf2 plugin you may lose your customization after an update.
Use the
Customization directory or create your own
custom PDF plugin.
Regards,
Julien
Re: How to limit the bookmark level is PDF
Posted: Tue Mar 07, 2023 6:15 pm
by julien_lacour
The previous post works only for the DITA Map PDF - based on XSL-FO scenario, if you are using the DITA Map PDF - based on HTML5 & CSS scenario you can directly follow
the instructions from the user-guide.
Regards,
Julien
Re: How to limit the bookmark level is PDF
Posted: Fri Mar 17, 2023 4:58 pm
by sbhatt
Thanks Julien.