Extension point add an intermediate processing step for PDF?

66 views
Skip to first unread message

Martin Pipho

unread,
Jun 6, 2019, 3:34:35 PM6/6/19
to DITA-OT Users
Hi,
I am redesigning an old PDF implementation that makes use of Ken Holman's PSMI to achieve intermixed portrait and landscape pages.


In the old implementation, demo/fo/build.xml, in the transform.topic2fo target (see below), was modified to process stage3.fo with bctpsmi.xsl. The result was stage4.fo with the added psmi markup. 

<java classname="com.icl.saxon.StyleSheet" classpathref="project.class.path" fork="true">
            <arg line='-o "${buildDir}/stage4.fo"'/>
            <arg line="${saxon.resolver.command.line}"/>
            <arg line='"${buildDir}/stage3.fo"'/>
            <arg line='"${dita.dir}/Customizations/BCT_Custom_Common/fo/xsl/bctpsmi.xsl"'/>
             <arg line='"customizationDir=${customization.dir}"'/>
            <sysproperty key="xml.catalog.files" value="${xml.catalog.files}"/>
</java> 

 <java classname="com.icl.saxon.StyleSheet" classpathref="project.class.path" fork="true">
            <arg line='-o "${outputFile}"'/>
            <arg line="${saxon.resolver.command.line}"/>
            <arg line='"${buildDir}/stage4.fo"'/>
            <arg line='"${xsl.fo.dir}/i18n-postprocess.xsl"'/>
            <sysproperty key="xml.catalog.files" value="${xml.catalog.files}"/>
  </java>


It seems that I need to add a processing step between stage2.fo i18n-preprocessing and topic.fo. Is there an extension point or mechanism to accomplish this in my new PDF plugin?

Thanks!
Martin

Radu Coravu

unread,
Jun 7, 2019, 3:26:59 AM6/7/19
to Martin Pipho, DITA-OT Users
Hi,

You can look in the equivalent build file "plugins/org.dita.pdf2/build_template.xml" at the template "transform.topic2fo".
It does not seem to allow an extra target between the "transform.topic2fo.main" and "transform.topic2fo.i18n" targets.
But there is a dependency called "depend.org.dita.pdf2.format.pre" which allows you to call a custom ANT target after all the XSL-FO has been processed (so after the " "transform.topic2fo.i18n") but before the XSL-FO is processed to PDF.
As an example I used that particular "depend.org.dita.pdf2.format.pre" dependency in this plugin:


Regards,
Radu

--
You received this message because you are subscribed to the Google Groups "DITA-OT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dita-ot-user...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/dita-ot-users/a41ed597-c3c8-491b-a26b-3e99629d1970%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Martin Pipho

unread,
Jun 14, 2019, 4:02:00 PM6/14/19
to DITA-OT Users
Thanks Radu, this was helpful.

I added the following to my plugin.xml
<feature extension="depend.org.dita.pdf2.format.pre" value="psmi"/>
and the following to my build.xml
  <target name="psmi" >
    <xslt in="${dita.temp.dir}/stage2.fo
      out="${dita.temp.dir}/stage3.fo
      style="${dita.plugin.com.bct.common.pdf.dir}/cfg/fo/xsl/bctpsmi.xsl">
    </xslt>
  </target>
And it works. I now have a new stage3.fo that has been processed with my bctpsmi.xsl. 

So now how do I continue processing with my new stage3.fo? I haven't been to figure out to do this. Any ideas?

Thanks!
Martin
To unsubscribe from this group and stop receiving emails from it, send an email to dita-o...@googlegroups.com.

Radu Coravu

unread,
Jun 15, 2019, 2:07:11 AM6/15/19
to Martin Pipho, DITA-OT Users
Hi Martin,

Maybe in your custom target after you obtain your custom stage3.fo, you can copy it over the older stage2.fo so that the processing afterwards continues as normal by looking into the stage2.fo:

<copy file="${dita.temp.dir}/stage3.fo" tofile="${dita.temp.dir}/stage2.fo" failonerror="yes"/>

Regards,
Radu

To unsubscribe from this group and stop receiving emails from it, send an email to dita-ot-user...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/dita-ot-users/84bd71e1-385f-453d-98b6-db7bfb98e407%40googlegroups.com.

Martin Pipho

unread,
Jun 25, 2019, 3:42:29 PM6/25/19
to DITA-OT Users
Hi Radu,

Copying my custom stage3.fo over stage2.fo seems to happen too late in the processing sequence. The transform.topic2fo.i18n.filter target is still using the original stage2.fo to output topic.fo.

As a test, I was able to accomplish my goal by making a few changes to org.dita.pdf2/build.xml. (I know I shouldn't modify this file, but I wanted to see what would happen.) Here's what I changed (highlighted in yellow)

In the transform.topic2fo.main target, I added my <xslt> to process stage2.fo with my bctpsmi.xsl.

  <target name="transform.topic2fo.main">
    <!--makeurl seems to output file:/C: style instead of file:///C:, but xep, fop, and ah all accept it.-->
    <makeurl property="artworkPrefixUrl" file="${artworkPrefix}"/>
    <makeurl property="dita.map.output.dir.url" file="${pdf2.temp.dir}" validate="no"/>
    <makeurl property="work.dir.url" file="${dita.temp.dir}" validate="no"/>
    <makeurl property="customization.dir.url" file="${customization.dir}" validate="no"/>
    <makeurl property="user.input.dir.url" file="${user.input.dir}" validate="no"/>    
    <makeurl property="variable.file.url" file="${variable.file}" validate="no"/>

    <pipeline>
    <xslt style="${temp.transformation.file}" in="${dita.temp.dir}/stage1.xml" out="${dita.temp.dir}/stage2.fo">
      <param name="locale" expression="${document.locale}"/>
      <param name="customizationDir.url" expression="${customization.dir.url}" if:set="customization.dir"/>
      <param name="input.dir.url" expression="${user.input.dir.url}"/>
      <param name="DRAFT" expression="${args.draft}"/>
      <param name="output.dir.url" expression="${dita.map.output.dir.url}"/>
      <param name="work.dir.url" expression="${work.dir.url}"/>
      <param name="artworkPrefix" expression="${artworkPrefixUrl}"/>
      <param name="publishRequiredCleanup" expression="${publish.required.cleanup}"/>
      <param name="artLabel" expression="${args.artlbl}" if:set="args.artlbl"/>
      <param name="antArgsBookmarkStyle" expression="${args.bookmark.style}"/>
      <param name="antArgsChapterLayout" expression="${args.chapter.layout}"/>
      <param name="include.rellinks" expression="${include.rellinks}"/>
      <param name="antArgsGenerateTaskLabels" expression="${args.gen.task.lbl}"/>
      <param name="pdfFormatter" expression="${pdf.formatter}"/>
      <param name="bookmap-order" expression="${args.bookmap-order}"/>
      <param name="figurelink.style" expression="${args.figurelink.style}"/>
      <param name="tablelink.style" expression="${args.tablelink.style}"/>
      <param name="variableFiles.url" expression="${variable.file.url}" if:set="variable.file.exists"/>
      <param name="defaultLanguage" expression="${default.language}"/>
      
      <xmlcatalog refid="xml.catalog"/>
    </xslt>
      <xslt in="${dita.temp.dir}/stage2.fo
        out="${dita.temp.dir}/stage3.fo
        style="${dita.plugin.com.bct.common.pdf.dir}/cfg/fo/xsl/bctpsmi.xsl">
      </xslt>
    </pipeline>
  </target>

In the transform.topic2fo.i18n.filter target, I modified the <i18-preprocess> to use stage3.fo as an input instead of stage2.fo.

  <target name="transform.topic2fo.i18n.filter" unless="pdf2.i18n.skip">
    <taskdef classname="com.idiominc.ws.opentopic.fo.i18n.PreprocessorTask" name="i18n-preprocess" classpathref="project.class.path"/>
    
    <condition property="i18n.config.file" value="${customization.dir}/fo/i18n/${document.locale}.xml">
      <and>
        <not><isset property="i18n.config.file"/></not>
        <available file="${customization.dir}/fo/i18n/${document.locale}.xml"/>
      </and>
    </condition>
    <condition property="i18n.config.file" value="${cfg.fo.dir}/i18n/${document.locale}.xml">
      <and>
        <not><isset property="i18n.config.file"/></not>
        <available file="${cfg.fo.dir}/i18n/${document.locale}.xml"/>
      </and>
    </condition>
    <condition property="i18n.config.file" value="${customization.dir}/fo/i18n/${document.language}.xml">
      <and>
        <not><isset property="i18n.config.file"/></not>
        <available file="${customization.dir}/fo/i18n/${document.language}.xml"/>
      </and>
    </condition>
    <condition property="i18n.config.file" value="${cfg.fo.dir}/i18n/${document.language}.xml">
      <and>
        <not><isset property="i18n.config.file"/></not>
        <available file="${cfg.fo.dir}/i18n/${document.language}.xml"/>
      </and>
    </condition>
    <condition property="i18n.config.file" value="${cfg.fo.dir}/i18n/${default.language}.xml">
      <not><isset property="i18n.config.file"/></not>
    </condition>

    <i18n-preprocess input="${dita.temp.dir}/stage3.fo" output="${pdf2.temp.dir}/topic.fo" config="${i18n.config.file}" style="${xsl.fo.dir}/i18n-postprocess.xsl">
      <xmlcatalog refid="xml.catalog"/>
    </i18n-preprocess>
  </target>


How do I override these targets in the build.xml for my plug-in? I haven't been able to find any guides that show how to do this.

Thank for your help!

Martin 

Radu Coravu

unread,
Jun 27, 2019, 1:17:20 AM6/27/19
to Martin Pipho, DITA-OT Users
Hi Martin,

I do not see a way how you could override these entire targets from your plugin.
Looking again at using the "org.dita.pdf2.format.pre" extension:
So the target "transform.topic2pdf" calls first the target "transform.topic2fo" and then your custom target.
And " transform.topic2fo " calls as its last target the "transform.topic2fo.i18n" which calls "transform.topic2fo.i18n.filter" which outputs the final XSL-FO file to "${pdf2.temp.dir}/topic.fo".
So this might mean that you would actually need to process the "${pdf2.temp.dir}/topic.fo", save the result to some other file and then overwrite the same "${pdf2.temp.dir}/topic.fo"with the contents so that the FO processor takes the topic.fo further on and creates the PDF.
But this needs to be tested.

Regards,
Radu

To unsubscribe from this group and stop receiving emails from it, send an email to dita-ot-user...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/dita-ot-users/a9701a86-a6f0-42c9-8075-0eea137dd814%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages