Page 1 of 1

How to hyperlink text to a slide

PostPosted: Tue Apr 10, 2012 12:05 pm
by Johnson
Hi,
Any one knows how to hyperlink text to a slide while creating the pptx. First I have the text and the slide is added later in the application.

Attached is the complete code that creates the text in a table and the slides.

I tried to create the Relationship
Code: Select all
if(i == 5){
                    org.docx4j.relationships.ObjectFactory factory = new org.docx4j.relationships.ObjectFactory();
                        org.docx4j.relationships.Relationship rel = factory.createRelationship();
                        rel.setType("Namespaces.PRESENTATIONML_SLIDE");
                        rel.setTarget("/ppt/slides/slide"+i+".xml");
                        mainPresentationPart.getRelationshipsPart().addRelationship(rel);
                        System.out.println(rel.getId());
                 }

and added code to link the text
Code: Select all
  + "<a:cs typeface=\"Times New Roman\"/>"
                                +"<a:hlinkClick r:id=\"rId8\" action=\"ppaction://hlinksldjump\"/>"
                            + "</a:rPr>


The code compiles fine. But when I open the files - says that it is corrupt and the slide is replaced with a blank one.

I am missing something. Not sure what it is.

Thanks
Johnson

Re: How to hyperlink text to a slide

PostPosted: Wed Apr 11, 2012 10:29 am
by jason
By way of background, a hyperlink to a web page requires a relationship to be set up:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
            <a:r>
              <a:rPr lang="en-AU" dirty="0" smtClean="0">
                <a:hlinkClick r:id="rId2"/>
              </a:rPr>
              <a:t>docx4j forums</a:t>
            </a:r>
 
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


A hyperlink to the next slide has no explicit rel:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
             <a:r>
              <a:rPr lang="en-AU" dirty="0" smtClean="0">
                <a:hlinkClick r:id="" action="ppaction://hlinkshowjump?jump=nextslide"/>
              </a:rPr>
              <a:t>Next Slide</a:t>
            </a:r>
 
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


(nextslide is special; looks like there would be similar short cuts for previous, first, and last).

Any other slide needs a rel to be set up:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
            <a:r>
              <a:rPr lang="en-AU" dirty="0" smtClean="0">
                <a:hlinkClick r:id="rId3" action="ppaction://hlinksldjump"/>
              </a:rPr>
              <a:t>slide 3</a:t>
            </a:r>
 
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


So you are on the right track.

Two things:

1. looks like you are adding the rel to mainPresentationPart; you need to add it to the slide you are putting the hyperlink on.
2. check that you are adding the right relId (you have rId8 hard coded).

Re: How to hyperlink text to a slide

PostPosted: Thu Apr 12, 2012 2:09 am
by Johnson
Jason,

It is working perfect. The attached java file has the complete code. It might save someone's time.

Thank you for the beautiful library and the quick support. :D

Cheers...
Johnson