How to modify the pdf properties using CSS Customization

Having trouble installing Oxygen? Got a bug to report? Post it all here.
antoterrence
Posts: 30
Joined: Sat May 04, 2019 5:55 pm

How to modify the pdf properties using CSS Customization

Post by antoterrence »

We are using the CSS Customization option to build our custom PDF output templates.
By default, the title filed on the description tab in the PDF properties shows only the value of the maintitle. We want to include the booktitlealt value as well.
These pages do not talk about how to set the properties dynamically.
https://www.oxygenxml.com/doc/versions/ ... utput.html
https://www.oxygenxml.com/doc/versions/ ... p_metadata

Please guide us.
Dan
Posts: 501
Joined: Mon Feb 03, 2003 10:56 am

Re: How to modify the pdf properties using CSS Customization

Post by Dan »

The title element of a bookmap is quite complex, and contains elements for the book library and an alternate title:

Code: Select all

 <booktitle>
    <booklibrary>Retro Tools</booklibrary>
    <mainbooktitle>Main Book Title</mainbooktitle>
    <booktitlealt>Book Title Alternative</booktitlealt>
  </booktitle>
The builtin CSS uses for the publication title only the content of the mainbooktitle. If you want to collect all the text from the booktitle, you can add the following rule to your customization CSS:

Code: Select all

:root {
    -oxy-pdf-meta-title: oxy_xpath('(//*[contains(@class, "bookmap/mainbooktitle")])[1]/text()')  " " oxy_xpath('(//*[contains(@class, "bookmap/booktitlealt")])[1]/text()');
    -oxy-pdf-meta-description: "";
}
We used an XPath expression to collect all the mainbooktitle and booktitlealt elements from the merged map, select the first of each, then use their text.
The builtin CSS uses the booktitlealt as PDF description. We cleared this property since it was moved into the title.

Many regards,
Dan
antoterrence
Posts: 30
Joined: Sat May 04, 2019 5:55 pm

Re: How to modify the pdf properties using CSS Customization

Post by antoterrence »

Dan wrote: Wed Sep 18, 2019 3:37 pm The title element of a bookmap is quite complex, and contains elements for the book library and an alternate title:

Code: Select all

 <booktitle>
    <booklibrary>Retro Tools</booklibrary>
    <mainbooktitle>Main Book Title</mainbooktitle>
    <booktitlealt>Book Title Alternative</booktitlealt>
  </booktitle>
The builtin CSS uses for the publication title only the content of the mainbooktitle. If you want to collect all the text from the booktitle, you can add the following rule to your customization CSS:

Code: Select all

:root {
    -oxy-pdf-meta-title: oxy_xpath('(//*[contains(@class, "bookmap/mainbooktitle")])[1]/text()')  " " oxy_xpath('(//*[contains(@class, "bookmap/booktitlealt")])[1]/text()');
    -oxy-pdf-meta-description: "";
}
We used an XPath expression to collect all the mainbooktitle and booktitlealt elements from the merged map, select the first of each, then use their text.
The builtin CSS uses the booktitlealt as PDF description. We cleared this property since it was moved into the title.

Many regards,
Dan
Thanks, Dan. Since I could not locate the :root css property in your documentation, I added a custom xslt script that modifies the title element in the head element. And it worked. However, I will go ahead and use the CSS approach that you just shared.
Modified XSLT template

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="xs"
    xmlns:oxy="http://www.oxygenxml.com/extensions/author"
    version="2.0">

    
    <!-- Add the publication title to the HTML head. -->
    <xsl:template name="generateChapterTitle">
        <title>
            
            <xsl:choose>
                <xsl:when test="@title">
                    <xsl:value-of select="@title"/>
                </xsl:when>
                <xsl:when test="*[contains(@class, ' topic/title ')]">
                    <xsl:value-of select="*[contains(@class, ' topic/title ')]"/>            
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="*[contains(@class, ' front-page/front-page ')]
                        /*[contains(@class, ' front-page/front-page-title ')]
                        /*[contains(@class, ' bookmap/booktitle ')]
                        /*[contains(@class, ' bookmap/mainbooktitle ')]"/>
                    
                    <!--custom xslt for adding the alt title to the PDF properties added by Antony. -->
                    <xsl:value-of select="*[contains(@class, ' front-page/front-page ')]
                        /*[contains(@class, ' front-page/front-page-title ')]
                        /*[contains(@class, ' bookmap/booktitle ')]
                        /*[contains(@class, ' bookmap/booktitlealt ')]"/>
                </xsl:otherwise>
            </xsl:choose>
            
        </title>
    </xsl:template>
</xsl:stylesheet>
Post Reply