My image creation works fine. I'm trying to add a hyperlink on it.
The target xml in Word is :
<w:drawing>
<wp:inline distT="0" distB="0" distL="0" distR="0">
<wp:extent cx="1800000" cy="466394"/><wp:effectExtent l="19050" t="0" r="0" b="0"/>
<wp:docPr id="9999" name="ABC.png" descr="ABC">
<a:hlinkClick xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" r:id="rId7"/>
</wp:docPr>
I have used the Hyperlink sample to do this :
Inline inline = img.createImageInline("ABC.png", "ABC", 9999, 9998, false);
...
inline.getDocPr().setHlinkClick(createImageHyperLink(url));
...
public CTHyperlink createImageHyperLink(String url) throws JAXBException {
//add relationship to document
ObjectFactory factory = new ObjectFactory();
Relationship newRel = factory.createRelationship();
newRel.setType(Namespaces.HYPERLINK);
newRel.setTarget(url);
newRel.setTargetMode("External");
pack.getMainDocumentPart().getRelationshipsPart().addRelationship(newRel);
String hls = "<a:hlinkClick xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" r:id=\"" +
newRel.getId() +
"\"/>";
return (CTHyperlink) XmlUtils.unmarshalString(hls);
}
The unmarshal operation gives the the following error :
2011-01-29 16:39:11,403 INFO [org.docx4j.jaxb.JaxbValidationEventHandler] continuing (with possible element/attribute loss) (http-0.0.0.0-8080-1:)
2011-01-29 16:39:11,403 ERROR [STDERR] javax.xml.bind.UnmarshalException
- with linked exception:
[org.xml.sax.SAXParseException: The prefix "r" for attribute "r:id" associated with an element type "a:hlinkClick" is not bound.] (http-0.0.0.0-8080-1:)
2011-01-29 16:39:11,404 ERROR [STDERR] at javax.xml.bind.helpers.AbstractUnmarshallerImpl.createUnmarshalException(AbstractUnmarshallerImpl.java:315) (http-0.0.0.0-8080-1:)
2011-01-29 16:39:11,404 ERROR [STDERR] at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.createUnmarshalException(UnmarshallerImpl.java:514) (http-0.0.0.0-8080-1:)
2011-01-29 16:39:11,404 ERROR [STDERR] at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:215) (http-0.0.0.0-8080-1:)
2011-01-29 16:39:11,404 ERROR [STDERR] at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:184) (http-0.0.0.0-8080-1:)
2011-01-29 16:39:11,404 ERROR [STDERR] at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:137) (http-0.0.0.0-8080-1:)
2011-01-29 16:39:11,404 ERROR [STDERR] at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:105) (http-0.0.0.0-8080-1:)
2011-01-29 16:39:11,404 ERROR [STDERR] at org.docx4j.XmlUtils.unmarshalString(XmlUtils.java:239) (http-0.0.0.0-8080-1:)
2011-01-29 16:39:11,404 ERROR [STDERR] at org.docx4j.XmlUtils.unmarshalString(XmlUtils.java:219) (http-0.0.0.0-8080-1:)