How to use content from ditamap to customize the PDF output

Post here questions and problems related to editing and publishing DITA content.
GSejourne
Posts: 15
Joined: Tue Mar 15, 2011 12:56 pm

How to use content from ditamap to customize the PDF output

Post by GSejourne »

Hi,

I've been using DITA-OT for quite a while, and there's something I'm still unable to do.

In my app.ditamap file, I have the <prodinfo> properly filled, like :

Code: Select all

<prodinfo>
<prodname>Application Name</prodname>
<vrmlist>
<vrm modification="Oct 15, 2014" version="3.2"/>
</vrmlist>
</prodinfo>
In the ant build file, I have a target that creates the pdf based on that ditamap file:

Code: Select all

<target name="app.pdf" depends="integrate">
<echo>Publish the PDF version of application documentation.</echo>
<ant antfile="${dita.dir}${file.separator}build.xml" target="init">
<property name="transtype" value="pdf2"/>
<property name="args.input" value="${basedir}${file.separator}apps${file.separator}app.ditamap"/>
<property name="output.dir" value="${global.output.dir}${file.separator}app${file.separator}pdf"/>
<property name="dita.input.valfile" value="${basedir}${file.separator}conditions${file.separator}print.ditaval"/>
</ant>
</target>
What I'd like to do is use the vrm version that is set in the ditamap content to be retrieved so that I can customize the PDF filename that's created, and not just get
a filename based on the ditamap filename.

In other words, get a filename derived from xpath:

Code: Select all

/bookmap/bookmeta/prodinfo/prodname + _ + /bookmap/prodinfo/vrmlist/vrm[last()]/@version
Something like this.

Do you know anyway I can achieve this in the ant build file ?

Thanks a lot,

-Guillaume
Radu
Posts: 9045
Joined: Fri Jul 09, 2004 5:18 pm

Re: How to use content from ditamap to customize the PDF out

Post by Radu »

Hi Guillaume,

Maybe in the ANT build file before calling the main DITA OT build file you could run an xslt task over the DITA Map content and save the version number in a newly created properties file.
Then load the properties file in ANT (which will also load the name=>value parameters from it as ANT parameters) and delegate the parameter as a property to the DITA OT ANT task.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
GSejourne
Posts: 15
Joined: Tue Mar 15, 2011 12:56 pm

Re: How to use content from ditamap to customize the PDF out

Post by GSejourne »

Thanks, that sounds like a good idea.

I'm not familiar with ant that much though, and I'm using a single build file for many targets, which would all require specific property files.

Do you think that's still doable ?
And how would I call an xslt transformation within each target ?

Thanks
GSejourne
Posts: 15
Joined: Tue Mar 15, 2011 12:56 pm

Re: How to use content from ditamap to customize the PDF out

Post by GSejourne »

Actually, I've been able to do exactly what you describe, and got a nice xml file i can use, but how do I use it to customize the PDF output name?

There is an output.dir parameter, but nothing that gives me ways to control the pdf file name...
Radu
Posts: 9045
Joined: Fri Jul 09, 2004 5:18 pm

Re: How to use content from ditamap to customize the PDF out

Post by Radu »

Hi,

Indeed there is no official documented parameter to allow for the output file name customization.
But looking in the build files used for PDF generation, you should send to the DITA OT ANT task the property outputFile.base with the value being the name of the PDF file (without the PDF extension which will be automatically appended to it).

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
GSejourne
Posts: 15
Joined: Tue Mar 15, 2011 12:56 pm

Re: How to use content from ditamap to customize the PDF out

Post by GSejourne »

OK, here is what I've come up so far:

Code: Select all

<target name="app.main" depends="app.pdf">
<echo>Publish the PDF and HTML versions of Application documentation.</echo>
<xslt in="${basedir}${file.separator}apps${file.separator}app.ditamap"
out="${global.output.dir}${file.separator}app${file.separator}app.properties"
style="${basedir}${file.separator}pub_files${file.separator}init_apps.xsl"/>
<property file="${global.output.dir}${file.separator}app${file.separator}app.properties"/>
</target>
<target name="app.pdf" depends="integrate">
<echo>Publish the PDF version of application documentation.</echo>
<ant antfile="${dita.dir}${file.separator}build.xml" target="init">
<property file="${global.output.dir}${file.separator}commtouchas${file.separator}app.properties"/>
<property name="transtype" value="pdf2"/>
<property name="args.input" value="${basedir}${file.separator}apps${file.separator}app.ditamap"/>
<property name="output.dir" value="${global.output.dir}${file.separator}app${file.separator}pdf"/>
<property name="dita.input.valfile" value="${basedir}${file.separator}conditions${file.separator}print.ditaval"/>

</ant>
</target>
I also had to edit the global ./DITA-OT/demo/fo/build.xml file, cause the version I use (1.7) did not seem to use an outputFile.base arg. Had to edit the <param name="outputFile" value="pdf.file.name"/> so that it can pick up the property I set by the name pdf.file.name.

So far so good...

Except for the first run: for some reason, on the first run, when I call app.main, the property file is not created when the app.pdf triggers... which results in a ${pdf.file.name} output file.
The second pass is OK though, because the property file already is there from the previous pass.

Maybe something wrong I do in the order of the target depends I set.

I'll investigate more, but in any case, great thanks for that, as it turns out to do exactly what I want.
Radu
Posts: 9045
Joined: Fri Jul 09, 2004 5:18 pm

Re: How to use content from ditamap to customize the PDF out

Post by Radu »

Hi,

I'm not sure why the first run does not work, maybe as an alternative you can apply a regexp over the DITA Map to obtain the value and set that directly to a parameter. There seem to be some ways to do this:

http://stackoverflow.com/questions/7869 ... -in-a-file

Like load the entire DITA Map in one property and then create the final property using a propertyregex element:

http://ant-contrib.sourceforge.net/task ... regex.html

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
GSejourne
Posts: 15
Joined: Tue Mar 15, 2011 12:56 pm

Re: How to use content from ditamap to customize the PDF out

Post by GSejourne »

I finally got around, and this was due to a bad combinations of depends.

The only issue I'm having now is that since I had to modify the global demo/fo/build.xml file to make it work, I would have liked to fail gracefully and revert to the original ${outputFile} if the variable I'm passing is empty.

In pseudo, that would be:

if ${pdf.file.name} = '' > use ${outputFile}
else > use ${pdf.file.name}

But I don't know any way to do that inside an ant target... I have seen <condition> in use, but that seems to allow calling conditional targets; in my case, what I want to do is use a different variable depending on cases...
Radu
Posts: 9045
Joined: Fri Jul 09, 2004 5:18 pm

Re: How to use content from ditamap to customize the PDF out

Post by Radu »

I'm not entirely sure but I think you can use the ANT condition task for this:

https://ant.apache.org/manual/Tasks/condition.html

Something like:

Code: Select all

        <condition property="outputFile" value="${pdf.file.name}">
<isset property="pdf.file.name"/>
</condition>
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
GSejourne
Posts: 15
Joined: Tue Mar 15, 2011 12:56 pm

Re: How to use content from ditamap to customize the PDF out

Post by GSejourne »

Yes, I think I found the same Stackoverflow post :)
http://stackoverflow.com/questions/1355 ... rties-file

Tried it and it seems to work fine.
xephon
Posts: 140
Joined: Mon Nov 24, 2014 1:49 pm
Location: Greven/Germany

Re: How to use content from ditamap to customize the PDF output

Post by xephon »

@GSejourne: Could you please share your XSLT-Stylesheet you use to create the properties?
stefan-jung.org – Your DITA/DITA-OT XML consultant
GSejourne
Posts: 15
Joined: Tue Mar 15, 2011 12:56 pm

Re: How to use content from ditamap to customize the PDF output

Post by GSejourne »

@xephon

I ended up designing a custom plugin instead, and this is the portion of code I added to my custom "integrator.xml" file:

Code: Select all


<condition property="outputFile" value="${dita.map.output.dir}/${outputFile.base}${xsl.formatter.ext}">
<not><isset property="outputFile"/></not>
</condition>
<local name="outputFile"/>
<property name="outputFile" value="${output.dir}/${pdf.file.name}"/>
Post Reply