How to set PDF metadata from DITA Bookmeta?

Post here questions and problems related to editing and publishing DITA content.
reinierk
Posts: 36
Joined: Tue Feb 21, 2012 8:22 pm
Location: Rotterdam, the Netherlands
Contact:

How to set PDF metadata from DITA Bookmeta?

Post by reinierk »

When I generate PDF no PDF metadata is copied form the bookmeta block of the source. The Apache FOP page states this should be possible using a declaration as follows

Code: Select all

<fo:declarations>
<x:xmpmeta xmlns:x="adobe:ns:meta/">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about=""
xmlns:dc="http://purl.org/dc/elements/1.1/">
<!-- Dublin Core properties go here -->
<dc:title>Document title</dc:title>
<dc:creator>Document author</dc:creator>
<dc:description>Document subject</dc:description>
</rdf:Description>
<rdf:Description rdf:about=""
xmlns:xmp="http://ns.adobe.com/xap/1.0/">
<!-- XMP properties go here -->
<xmp:CreatorTool>Tool used to make the PDF</xmp:CreatorTool>
</rdf:Description>
</rdf:RDF>
</x:xmpmeta>
</fo:declarations>
Why is this block not inserted by the stylesheets as delivered?

Kind Regards,
REinier Kleipool
Kind Regards,
Reinier Kleipool,
Course Materials editor,
Open Source Academy
http://www.OpenSourceAcademy.eu
Radu
Posts: 9059
Joined: Fri Jul 09, 2004 5:18 pm

Re: How to set PDF metadata from DITA Bookmeta?

Post by Radu »

Hi Reinier,

Oxygen uses the DITA Open Toolkit to publish PDF documents to various output sources.
Indeed the DITA OT stylesheets do not set PDF metadata from the bookmeta.

One of the reasons probably is:

http://xmlgraphics.apache.org/fop/0.95/metadata.html
Therefore, there's no portable way to represent metadata in XSL-FO documents. Each implementation does it differently.
So your proposed code works good for Apache FOP but does not work when creating the PDF with AntennaHouse or XEP. But there seem to be ways to set the metadata for each FO processor:

http://dita.xml.org/blog/adding-pdf-doc ... p-metadata

How you could use the proposed code would be to edit the XSL:
OXYGEN_INSTALL_DIR/frameworks/dita/DITA-OT/demo/fo/xsl/fo/root-processing.xsl

and before this call-template:

Code: Select all

<xsl:call-template name="createBookmarks"/>
add your XSL code.

I also added a feature request on the DITA Open Toolkit features list:

https://sourceforge.net/tracker/?func=d ... tid=725077

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
reinierk
Posts: 36
Joined: Tue Feb 21, 2012 8:22 pm
Location: Rotterdam, the Netherlands
Contact:

Re: How to set PDF metadata from DITA Bookmeta?

Post by reinierk »

Thanks Radu for this reply!

You propose to edit the XML
OXYGEN_INSTALL_DIR/frameworks/dita/DITA-OT/demo/fo/xsl/fo/root-processing.xsl. But this involves changing the supplied files.
How can I do this using the Customization feature?
Should I copy the whole "rootTemplate" to ${customdir}/fo/xsl/custom.xsl so it overrides the supplied rootTemplate? Then add the extra stuff there?

Kind Regards,
Reinier
Kind Regards,
Reinier Kleipool,
Course Materials editor,
Open Source Academy
http://www.OpenSourceAcademy.eu
Radu
Posts: 9059
Joined: Fri Jul 09, 2004 5:18 pm

Re: How to set PDF metadata from DITA Bookmeta?

Post by Radu »

Hi Reinier,

Yes, this is the way to properly make the customization.
Or overwrite the template:

Code: Select all

<xsl:template name="createLayoutMasters">
and place your code at the end of the overwriting template after the layout masterset has been computed. The "createLayoutMasters" template has less content and may be less susceptible to changes in future DITA OT versions.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
reinierk
Posts: 36
Joined: Tue Feb 21, 2012 8:22 pm
Location: Rotterdam, the Netherlands
Contact:

Re: How to set PDF metadata from DITA Bookmeta?

Post by reinierk »

Sorry to bother you again...
This indeed does work without overwriting the original stuff.

But now I struggle to actually INSERT bookmap/mainbooktitle and others.

When I use:

Code: Select all

<d:title>
<xsl:apply-templates select="*[contains(@class,' bookmap/mainbooktitle ')]"/>
</dc:title>
nothing gets inserted...
when I use:

Code: Select all

<dc:title>
<xsl:apply-templates select="/bookmap/*[namespace-uri()='http://www.idiominc.com/opentopic' and local-name()='map']/booktitle/mainbooktitle"></xsl:apply-templates>
</dc:title>
I get:

Code: Select all

<dc:title>
<fo:inline xmlns:xs="http://www.w3.org/2001/XMLSchema" border-left-width="0pt" border-right-width="0pt" id="_Connect_42_H0121-90000">LI121 System and Network Administration I</fo:inline>
</dc:title>
What would be the right XPATH to use to just get the plain element contents without wrapping and attributes...

Greets,
Reinier
Kind Regards,
Reinier Kleipool,
Course Materials editor,
Open Source Academy
http://www.OpenSourceAcademy.eu
Radu
Posts: 9059
Joined: Fri Jul 09, 2004 5:18 pm

Re: How to set PDF metadata from DITA Bookmeta?

Post by Radu »

Hi Reinier,

In situations like this when the context XML node is unclear I usually add an XSL message like:

Code: Select all

 <xsl:message>^^^^^^^^^^^^^^^^^^^^
<xsl:copy-of select="."></xsl:copy-of>
^^^^^^^^^^^^^^^^^^^^</xsl:message>
You can see the message output in the DITA Transformation console after the transformation finishes.

The XML over which the XSL gets applied is an XML which contains merged in it both the map and the topics, a way to get to the main book title seems to be using this XPath expression:

Code: Select all

<xsl:value-of select="*[contains(@class,' map/map ')]/opentopic:map/*[contains(@class,' bookmap/booktitle ')]/*[contains(@class,' bookmap/mainbooktitle ')]"/>
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
reinierk
Posts: 36
Joined: Tue Feb 21, 2012 8:22 pm
Location: Rotterdam, the Netherlands
Contact:

Re: How to set PDF metadata from DITA Bookmeta?

Post by reinierk »

Thanks for the xpath expression. Even easier is:

Code: Select all

<xsl:value-of select="//*[contains(@class,' bookmap/publisherinformation ')]"/>
This is what I ended up with:

Code: Select all

<x:xmpmeta>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about="">
<!-- Dublin Core properties go here -->
<dc:title>
<rdf:Alt><rdf:li xml:lang="x-default"><xsl:value-of select="//*[contains(@class,' bookmap/mainbooktitle ')]"/></rdf:li></rdf:Alt>
</dc:title>
<dc:creator>
<rdf:Seq><rdf:li><xsl:value-of select="//*[contains(@class,' bookmap/publisherinformation ')]"/></rdf:li></rdf:Seq>
</dc:creator>
<dc:description><xsl:value-of select="//*[contains(@class,' bookmap/booktitlealt ')]"/></dc:description>
<dc:publisher>
<xsl:value-of select="//*/bookmeta/publisherinformation"/>
</dc:publisher>
<dc:rights>
<rdf:Alt>
<rdf:li xml:lang="x-default"><xsl:value-of select="//*/bookmeta/publisherinformation"/><xsl:value-of select="//*/bookmeta/bookrights/bookrestriction/@value"/></rdf:li>
</rdf:Alt>
</dc:rights>
<dc:language>
<xsl:value-of select="/bookmap/@xml:lang"/>
</dc:language>
</rdf:Description>
<rdf:Description rdf:about="">
<!-- XMP properties go here -->
<xmp:CreatorTool>Oxigen Author</xmp:CreatorTool>
<xmp:Identifier>
<rdf:Bag>
<rdf:li>ISBN: <xsl:value-of select="//*[contains(@class,' bookmap/isbn ')]"/></rdf:li>
<rdf:li>Order No: <xsl:value-of select="//*[contains(@class,' bookmap/bookpartno ')]"/></rdf:li>
</rdf:Bag>
</xmp:Identifier>
<xmpRights:Marked>True</xmpRights:Marked>
</rdf:Description>
</rdf:RDF>
</x:xmpmeta>
Unfortunately FOP does not support the xmpRights schema, so the Marked property is not set. I included it anyway in the hope they will support it one day...
Kind Regards,
Reinier Kleipool,
Course Materials editor,
Open Source Academy
http://www.OpenSourceAcademy.eu
Radu
Posts: 9059
Joined: Fri Jul 09, 2004 5:18 pm

Re: How to set PDF metadata from DITA Bookmeta?

Post by Radu »

Hi Reinier,

This enhancement seems to have been done for the upcoming DITA OT 1.6:

http://sourceforge.net/tracker/?func=de ... _id=132728

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
BrianL
Posts: 4
Joined: Tue Aug 12, 2014 5:45 pm

Re: How to set PDF metadata from DITA Bookmeta?

Post by BrianL »

Hi,

I found this thread when troubleshooting an issue with using xmpRights to set the Copyright Status value to Copyrighted in the PDF properties. I declared the xmpRights namespace at the top of my custom.xsl file and used part of the code snippet in reinierk's last reply, but the copyright status is not set in the output PDF.

Radu, should the link in your last response link to a specific feature request? Clikcing the link takes me to the main DITA OT project page on sourceforge.net.

Thanks,

BrianL
Radu
Posts: 9059
Joined: Fri Jul 09, 2004 5:18 pm

Re: How to set PDF metadata from DITA Bookmeta?

Post by Radu »

Hi Brian,
I found this thread when troubleshooting an issue with using xmpRights to set the Copyright Status value to Copyrighted in the PDF properties. I declared the xmpRights namespace at the top of my custom.xsl file and used part of the code snippet in reinierk's last reply, but the copyright status is not set in the output PDF.
It's possible you made changes in the wrong place. What DITA OT version are you using? The issue seems to have been resolved in DITA OT 1.6.
Radu, should the link in your last response link to a specific feature request? Clikcing the link takes me to the main DITA OT project page on sourceforge.net.
The link worked when I posted it, in the meantime all DITA Open Toolkit issues have been migrated to GitHub. The migrated issue is this one:

https://github.com/dita-ot/dita-ot/issues/1198

The issue seems to contain links to the commits in the XSLT stylesheets so it should help you see where the changes have been made.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
BrianL
Posts: 4
Joined: Tue Aug 12, 2014 5:45 pm

Re: How to set PDF metadata from DITA Bookmeta?

Post by BrianL »

Thanks for the response, Radu.

I am using a standalone instance of DITA-OT1.7.1 to build PDFs from a command line prompt.

I reviewed the example FOP implementation accessible from your GitHub link. Maybe I'm overlooking it, but it's not clear where I need to add the <fo:declarations> element or how I can add it as an override in the custom.xsl file in my custom PDF plug-in.

The note at the bottom of the example mentions adding <fo:declarations> after </fo:layout-master-set> and before the first <page-sequence>. I found <fo:layout-master-set> in \plugins\org.dita.pdf2\cfg\fo\layout-masters.xsl. I tried adding <fo:declarations> to the very bottom of the createDefaultLayoutMasters template and then tried adding it immediately following the createDefaultLayoutMasters template, but it did not work.
Radu
Posts: 9059
Joined: Fri Jul 09, 2004 5:18 pm

Re: How to set PDF metadata from DITA Bookmeta?

Post by Radu »

Hi Brian,

I do not quite understand.
As you are using DITA OT 1.7 this issue should already be fixed in it (because it was fixed in DITA OT 1.6).

Here's what I tested:

If I have a bookmap containing content like this:

Code: Select all

    <booktitle>
<booklibrary>Retro Tools</booklibrary>
<mainbooktitle>Product tasks</mainbooktitle>
<booktitlealt>Tasks and what they can do</booktitlealt>
</booktitle>
<bookmeta>
<author>Howe Tuduit</author>
<bookid>
<isbn>071271271X</isbn>
<booknumber>SG99-9999-00</booknumber>
<maintainer>
<organization>Retro Tools</organization>
<person/>
</maintainer>
</bookid>
<bookrights>
<copyrfirst>
<year>2004</year>
</copyrfirst>
<copyrlast>
<year>2007</year>
</copyrlast>
<bookowner>
<organization>Retro Tools, Inc.</organization>
</bookowner>
</bookrights>
</bookmeta>
and generate PDF using Apache FOP, the XSL-FO will contain this:

Code: Select all


<fo:declarations>
<x:xmpmeta>
<rdf:RDF>
<rdf:Description rdf:about="">
<dc:title>Product tasks</dc:title>
<dc:creator>Howe Tuduit</dc:creator>
<xmp:CreatorTool>DITA Open Toolkit</xmp:CreatorTool>
</rdf:Description>
</rdf:RDF>
</x:xmpmeta>
</fo:declarations>
This information will get imprinted in the PDF and when I open the PDF,right click inside it and choose "Document Properties" I will see this information there.

The XSLT code which does this is in the XSLT:

DITA-OT\plugins\org.dita.pdf2\xsl\fo\root-processing_fop.xsl

in the XSLT template named createMetadata.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
BrianL
Posts: 4
Joined: Tue Aug 12, 2014 5:45 pm

Re: How to set PDF metadata from DITA Bookmeta?

Post by BrianL »

Hi Radu,

Sorry for the confusion.

Yes, to set the basic properties, I added the createMetadata template to my custom.xml file and configured XPath expressions for our map structure. That works fine.

The issue that I am referring to is specific to xmpRights. I am trying to set the Copyright Status value (accessible by clicking Additional Metadata on the Document Properties Description tab) to Copyrighted. I declared the namespace

Code: Select all

xmlns:xmpRights="http://ns.adobe.com/xap/1.0/rights/"
at the top of my custom.xml file and added

Code: Select all

<xmpRights:Marked>True</xmpRights:Marked>
below

Code: Select all

<xmp:CreatorTool>DITA Open Toolkit</xmp:CreatorTool>
but it did not work. As reinier pointed out in an earlier post, Apache FOP probably still does not support the xmpRights schema. I thought support for this was added to DITA OT 1.6.

Thanks,

Brian
Radu
Posts: 9059
Joined: Fri Jul 09, 2004 5:18 pm

Re: How to set PDF metadata from DITA Bookmeta?

Post by Radu »

Hi Brian,

Sorry, your intentions would have been more clear to me if I would have read the post more carefully.
I think the best thing would be to ask this on the Apache FOP users list, they know more about what they support in regard to metadata.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
BrianL
Posts: 4
Joined: Tue Aug 12, 2014 5:45 pm

Re: How to set PDF metadata from DITA Bookmeta?

Post by BrianL »

Yeah, I figured it might be best to switch over to the Apache FOP users list. Thanks for all your help!
Post Reply