Issue with automatically generating PDF properties/meta-data

B-E-N
Posts: 117

Issue with automatically generating PDF properties/meta-data

Wed Apr 05, 2017 10:44 am

Hi,

when creating PDF, we want to automatically add meta-data to the PDF properties.

I used the xsl:template "createMedadata" in the root-processing_fop.xsl for this. Some things work fine, some don't.

What works so far:
  • Title of main ditamap is added as the title in the PDF properties
  • Language is set according to the xml:lang attribute of the main ditamap
  • Creator is the name of my company + the current year

But I can't get to work other things:
  • Keywords are not added to the properties
  • The copyright icon (©) makes the build fail, no matter how I insert it (© or © or © or ©, impended in xsl:text or just pasted into the dc:creator element)
  • The authors are not added to the properties

So this is the code:

Code: Select all

<xsl:template name="createMetadata">
    <fo:declarations>
      <x:xmpmeta>
        <rdf:RDF>
          <rdf:Description rdf:about="">
            <xsl:variable name="title" as="xs:string?">
              <xsl:apply-templates select="." mode="dita-ot:title-metadata"/>
            </xsl:variable>
            <xsl:if test="exists($title)">
              <dc:title>
                <xsl:value-of select="$title"/>
              </dc:title>
            </xsl:if>
            <xsl:variable name="author" as="xs:string?">
              <xsl:apply-templates select="." mode="dita-ot:author-metadata"/>
            </xsl:variable>
            <xsl:if test="exists($author)">
              <dc:creator>
                <xsl:value-of select="$author"/>
              </dc:creator>
            </xsl:if>
            <xsl:variable name="keywords" as="xs:string*">
              <xsl:apply-templates select="." mode="dita-ot:keywords-metadata"/>
            </xsl:variable>
            <xsl:if test="exists($keywords)">
              <pdf:Keywords>
                <xsl:value-of select="$keywords" separator=", "/>
              </pdf:Keywords>
            </xsl:if>
            <xsl:variable name="subject" as="xs:string?">
              <xsl:apply-templates select="." mode="dita-ot:subject-metadata"/>
            </xsl:variable>
            <xsl:if test="exists($subject)">
              <dc:description>
                <rdf:Alt>
                  <rdf:li xml:lang="x-default">
                    <xsl:value-of select="$subject"/>
                  </rdf:li>
                </rdf:Alt>
              </dc:description>
            </xsl:if>
            <dc:creator>Name of my company <xsl:value-of select="year-from-date(current-date())"/></dc:creator>
            <dc:language><xsl:value-of select="/map/@xml:lang"/></dc:language>
            <pdf:Keywords></pdf:Keywords>
          </rdf:Description>
        </rdf:RDF>
      </x:xmpmeta>
    </fo:declarations>
  </xsl:template>


So this works:

Code: Select all

<xsl:if test="exists($title)">
     <dc:title>
           <xsl:value-of select="$title"/>
     </dc:title>
</xsl:if>

<dc:creator>Name of my company <xsl:value-of select="year-from-date(current-date())"/></dc:creator>

<dc:language><xsl:value-of select="/map/@xml:lang"/></dc:language>


Does anybody have an idea how to make the rest work too?

For example, where does the transformation expect the keyword elements to be in the ditamap? I tried them at several locations, for example as topicmeta > metadata > keywords > keyword in the main ditamap.

The authors are located in the topicmeta > author element in the main ditamap.

We are using Oxygen 18.1, custom framework, DITA 2.x, Apache FOP
Radu
Posts: 5878

Re: Issue with automatically generating PDF properties/meta-data

Thu Apr 06, 2017 4:40 pm

Hi Ben,

I'm not sure how your DITA Map looks like (how it defines that metadata and so on).
This XSLT stylesheet:

OXYGEN_INSTALL_DIR/frameworks/dita/DITA-OT2.x/plugins/org.dita.pdf2/xsl/fo/root-processing.xsl

defines modes both for "dita-ot:keywords-metadata" and for "dita-ot:author-metadata". If you look at their xpaths, they seem to be targeted towards bookmeta so they seem to work only for DITA Bookmaps and not for regular DITA Maps.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
B-E-N
Posts: 117

Re: Issue with automatically generating PDF properties/meta-data

Thu Apr 13, 2017 10:56 am

Thank you for pointing this out. Too bad we are not using bookmaps. I will play around with the code a little bit to see if there are some workaround. At least some of the properties work already.

Return to “DITA (Editing and Publishing DITA Content)”

Who is online

Users browsing this forum: juhopvx and 3 guests