AntennaHouse / pdf5-ml

Antenna House PDF5-ML DITA-OT Plug-in
23 stars 9 forks source link

Question: How to embed and link an external file in PDF #157

Closed steinbacher01 closed 4 years ago

steinbacher01 commented 4 years ago

I reviewed and tested the information from this tips-tricks page.

https://www.antennahouse.com/tips-tricks/2016/08/embed-a-file-into-pdf

I've attached my working files. See US470.zip.

When I processed a sample fo (US470\SampleOut\bm_US470 - Copy.fo), I realized the double-click link doesn't work unless the link target is already in the same folder.

I also tested a topic with xrefs to external files (US470\c_US470.dita). I noticed that these links will work if the external files are copied to the output folder after publishing.

When publishing to pdf5-ml from the DITA-OT, is there a way to automatically pass external files to the output directory?

In my sample, I manully copied them to the out directory: US470\out\ge-PDF5-ml.

Thanks,

Leroy Steinbacher

ToshihikoMakita commented 4 years ago

Several questions:

steinbacher01 commented 4 years ago

Yes and Yes.

We can add any valid dita element and attribute that is needed to the map.

We use Astoria. When publishing, Astoria exports the bookmap as a structured document so it pulls all referenced content to a local folder on the server where the DITA-OT is run.

Thanks,

Leroy

ToshihikoMakita commented 4 years ago

If you can author Excel file in map, it can be controlled by DITA-OT build processing. However it needs some build file trick. I will make a example using your map. Please give me a time little.

ToshihikoMakita commented 4 years ago

Please download (or fork) the develop-resource-copy branch of PDF5-ML plugin. https://github.com/AntennaHouse/pdf5-ml/tree/develop-resource-copy

I've added sample XSL and modified build.xml so that you can copy the target resource files into output directory automatically. I attached the sample build result. US470-2020-07-29.zip

steinbacher01 commented 4 years ago

Thanks for the quick response. I've downloaded and installed the new branch and the updated sample.

When I publish to the base pdf5.ml plugin it works as expected.

dita --format=pdf5.ml --input=samples\US470\bm_US470.ditamap --output=samples\US470\out\PDF5.ml

But when I publish to our custom plugin that extends the base PDF5-ML...

dita --format=ge-pdf5-ml --input=samples\US470\bm_US470.ditamap --output=samples\US470\out\ge-PDF5-ml

I'm getting the following error:

Error: The following error occurred while executing this line:
C:\dita-ot-3.4-Dev\plugins\com.antennahouse.pdf5.ml\build.xml:199: The following error occurred while executing this line:
C:\dita-ot-3.4-Dev\plugins\com.antennahouse.pdf5.ml\build.xml:211: stylesheet C:\dita-ot-3.4-Dev\plugins\com.ge.pdf5.ml\xsl\dita2fo_bookmap_to_xml_property.xsl doesn't exist.

It is looking for the xsl file in my custom plugin (com.ge.pdf5.ml) instead of the base plugin. I copied dita2fo_bookmap_to_xml_property.xsl to my custom plugin, but then it couldn't find these other files since they are also in the base and not in my custom plugin.

    <xsl:import href="dita2fo_constants.xsl"/>
    <xsl:import href="dita2fo_util.xsl"/>
    <xsl:import href="dita2fo_error_util.xsl"/>
    <xsl:import href="dita2fo_message.xsl/"/>

Any suggestions?

Thanks,

Leroy

ToshihikoMakita commented 4 years ago

I should consider the plug-in override. As you said dita2fo_bookmap_to_xml_property.xsl does not take into account about it is used in other plug-in. I will update the base plug-in as soon as possible.

ToshihikoMakita commented 4 years ago

I updated dita2fo_bookmap_to_xml_property.xsl.

<xsl:import href="plugin:com.antennahouse.pdf5.ml:xsl/dita2fo_constants.xsl"/>
<xsl:import href="plugin:com.antennahouse.pdf5.ml:xsl/dita2fo_util.xsl"/>
<xsl:import href="plugin:com.antennahouse.pdf5.ml:xsl/dita2fo_error_util.xsl"/>
<xsl:import href="plugin:com.antennahouse.pdf5.ml:xsl/dita2fo_message.xsl/"/>

Please try once again. This branch will be removed in the near feature.

steinbacher01 commented 4 years ago

Thank you again for your quick response. Just to confirm, this branch will not be merged with the master? So, I should install it our custom plugin? Our development practice is to not modify the base so we can always pull in the latest release from AntennaHouse without any changes (except our local reference to AHFormatter).

Thanks,

Leroy

ToshihikoMakita commented 4 years ago

Very important point. I will reconsider how to generalize this function and merge this branch with master when it become ready.

Regards,

steinbacher01 commented 4 years ago

Thanks. I tested both locally and from Astoria CMS. Everything is working as expected.

ToshihikoMakita commented 4 years ago

I've merged develop-resource-copy branch into master after generalization. Please set <property name="copy.link.target.to.output.dir" value="true"/> in your side build.xml file.

steinbacher01 commented 4 years ago

I downloaded the latest master and removed the previous changes from our custom ge-pdf5-ml plugin.

I also added to our custom build.xml file.

<?xml version="1.0" encoding="UTF-8"?>
<project name="com.ge.pdf5.ml.build"  basedir="." xmlns:if="ant:if">
    <import file="../com.antennahouse.pdf5.ml/build.xml"/>
    <property name="copy.link.target.to.output.dir" value="true"/>
</project>

For some reason, it is not overriding the "false" setting from the base plugin. The target files are not coming through unless I change the value to "true" in the base build.xml file.

Any suggestions?

Thanks,

Leroy

ToshihikoMakita commented 4 years ago

ant adopts the first defined property value and it is immutable. Please modify your build.xml and try again.

<?xml version="1.0" encoding="UTF-8"?>
<project name="com.ge.pdf5.ml.build"  basedir="." xmlns:if="ant:if">
    <property name="copy.link.target.to.output.dir" value="true"/>
    <import file="../com.antennahouse.pdf5.ml/build.xml"/>
</project>
steinbacher01 commented 4 years ago

Thanks for the response. Good to know.

It's now working as expected, however it seems that I have to have dita2fo_bookmap_to_xml_property.xsl in my custom plugin directory, or else I get this error.

C:\dita-ot-3.4-Dev\plugins\com.antennahouse.pdf5.ml\build.xml:219: stylesheet C:\dita-ot-3.4-Dev\plugins\com.ge.pdf5.ml\xsl\dita2fo_bookmap_to_xml_property.xsl doesn't exist.

Any suggestions?

Thanks,

Leroy

ToshihikoMakita commented 4 years ago

As long as you import the build.xml from com.antennahouse.pdf5.ml, your plugin should have same name stylesheet that imports original stylesheet. Probably you will need to make following stylesheets:

[com.ge.pdf5.ml/xsl/dita2fo_bookmap_to_xml_property.xsl]

<xsl:stylesheet version="2.0" 
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:xs="http://www.w3.org/2001/XMLSchema"
   xmlns:ahf="http://www.antennahouse.com/names/XSLT/Functions/Document"
   xmlns:ahs="http://www.antennahouse.com/names/XSLT/Document/Layout"
  exclude-result-prefixes="xs ahf ahs" 
  >
    <xsl:import href="plugin:com.antennahouse.pdf5.ml:xsl/dita2fo_bookmap_to_xml_property.xsl"/>
</xsl:stylesheet>
steinbacher01 commented 4 years ago

Thanks for the response. I followed your suggestion and it is working as expected.