How to use content from ditamap to customize the PDF output
Post here questions and problems related to editing and publishing DITA content.
How to use content from ditamap to customize the PDF output
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 :
In the ant build file, I have a target that creates the pdf based on that ditamap file:
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:
Something like this.
Do you know anyway I can achieve this in the ant build file ?
Thanks a lot,
-Guillaume
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>
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>
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
Do you know anyway I can achieve this in the ant build file ?
Thanks a lot,
-Guillaume
Re: How to use content from ditamap to customize the PDF out
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
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
<oXygen/> XML Editor
http://www.oxygenxml.com
Re: How to use content from ditamap to customize the PDF out
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
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
Re: How to use content from ditamap to customize the PDF out
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...
There is an output.dir parameter, but nothing that gives me ways to control the pdf file name...
Re: How to use content from ditamap to customize the PDF out
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
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
<oXygen/> XML Editor
http://www.oxygenxml.com
Re: How to use content from ditamap to customize the PDF out
OK, here is what I've come up so far:
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.
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>
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.
Re: How to use content from ditamap to customize the PDF out
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
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
<oXygen/> XML Editor
http://www.oxygenxml.com
Re: How to use content from ditamap to customize the PDF out
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...
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...
Re: How to use content from ditamap to customize the PDF out
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:
Regards,
Radu
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>
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
Re: How to use content from ditamap to customize the PDF out
Yes, I think I found the same Stackoverflow post
http://stackoverflow.com/questions/1355 ... rties-file
Tried it and it seems to work fine.
http://stackoverflow.com/questions/1355 ... rties-file
Tried it and it seems to work fine.
Re: How to use content from ditamap to customize the PDF output
@GSejourne: Could you please share your XSLT-Stylesheet you use to create the properties?
stefan-jung.org – Your DITA/DITA-OT XML consultant
Re: How to use content from ditamap to customize the PDF output
@xephon
I ended up designing a custom plugin instead, and this is the portion of code I added to my custom "integrator.xml" file:
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}"/>
Return to “DITA (Editing and Publishing DITA Content)”
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service