Add topic file path to footer in PDF > CSS

Post here questions and problems related to editing and publishing DITA content.
amyers3
Posts: 28
Joined: Sat Feb 16, 2019 8:43 pm

Add topic file path to footer in PDF > CSS

Post by amyers3 »

Hi,
Is there an easy way to add the file path of a topic as a footer in the PDF > HTML/CSS transformation? When we are reviewing a PDF, it would be great to see which file is the source of a topic in the PDF. For example:

My Troubleshooting Topic
Some content
Footer: troubleshooting\my_troubleshooting_topic.dita
Adam Myers
Technical Publications Manager
MATRIXX Software
Dan
Posts: 501
Joined: Mon Feb 03, 2003 10:56 am

Re: Add topic file path to footer in PDF > CSS

Post by Dan »

Not quite easy, but possible:

1. If you do not have yet a publishing template in place, you can start by creating a publishing template stub, that you will use in your transformation scenario. For this, go to the https://styles.oxygenxml.com and press the 'Download' buton. Save the 'styles.zip' archive in your project, then extract it in the 'styles' foolder. You can read more about the publishing templates here: https://www.oxygenxml.com/doc/ug-pdf-cs ... plate.html
2. Add a XSLT extension point that will copy location information in the XML intermediate formats (there is a publishing pipeline, we need to push this information through it). For this create a new folder 'styles/xsl'. Create a file named 'merged2mergedExtension.xsl' with the following content:

Code: Select all

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:dita2html="http://dita-ot.sourceforge.net/ns/200801/dita2html"
    exclude-result-prefixes="xs dita2html" version="2.0">
    
    <xsl:template match="@xtrf" priority="100">
        <xsl:attribute name="topic-uri" select="."/>
    </xsl:template>
            
</xsl:stylesheet>
3. Create a new CSS file that uses the 'topic-uri' attribute and place it into the bottom left of the pages. Name this file 'custom.css' and place it next to the 'styles/styles.opt' file.

Code: Select all

*[class~='topic/body'] {
    string-set: topic-uri-string attr(topic-uri);    
}

@page chapter {  
    @bottom-left {  
        content: "Location: " string(topic-uri-string);
    }
}
4. Refer these two files from the styles.opt publishing template descriptor.

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<publishing-template>
    <name>Custom Template</name>
    <webhelp>
        <preview-image file="preview/generated-preview.png"/>
        <resources>
            <css file="styles.css"/>
            <fileset>
                <include name="resources/**/*"/>
                <include name="*.css"/>
                <include name="css/**/*"/>
            </fileset>
        </resources>
        <parameters>
            <parameter name="webhelp.show.main.page.tiles" value="yes"/>
            <parameter name="webhelp.show.main.page.toc" value="no"/>
        </parameters>
    </webhelp>
    <pdf>
        <preview-image file="preview/generated-preview.png"/>
        <resources>
            <css file="styles.css"/>
            <!-- reference -->
            <css file="custom.css"/>
        </resources>
        <!-- reference -->
        <xslt>
            <extension
                id="com.oxygenxml.pdf.css.xsl.merged2merged"
                file="xslt/merged2mergedExtension.xsl"/>
        </xslt>
    </pdf>
</publishing-template>
5. Next, configure your transformation scenario to use this publishing template. See: https://www.oxygenxml.com/doc/ug-pdf-cs ... plate.html

You can use this example as a starting point to change your publishing template.
Let us know if you need more information.

Many regards,
Dan
amyers3
Posts: 28
Joined: Sat Feb 16, 2019 8:43 pm

Re: Add topic file path to footer in PDF > CSS

Post by amyers3 »

Thank you so much, Dan. This worked exactly as I had hoped! Adam
Adam Myers
Technical Publications Manager
MATRIXX Software
Post Reply