Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Scout » Hyperlink in docx4j(I'm trying to make a hyperlink inside a Paragraph, but I fail)
icon5.gif  Hyperlink in docx4j [message #1738510] Wed, 20 July 2016 13:16 Go to next message
Steven Engelen is currently offline Steven EngelenFriend
Messages: 4
Registered: April 2015
Junior Member
I'm trying to get this as a result as a footer in my word document:

In toepassing van de wet tot bescherming van de persoonlijke levenssfeer in verband met de verwerking van persoonsgegevens, informeert de hogervermelde licentiehouder u, als verantwoordelijke verwerker van deze gegevens, dat de door u meegedeelde persoonlijke gegevens, uitsluitend verwerkt worden om aan uw verzoek te voldoen tot het opstellen van een fiscale raming. Verder wordt verwezen naar de Privacybepaling van de licentiehouder.

with the "privacybepaling" linking to a website.
The problems are:
* the link isn't to www.google.com but to c:\users\steven\downloads\test.docx#www.google.com

*I want the link in another style than the rest of the Paragraph, but it's not.

my code to add the part:

String disclaimer = "In toepassing van de wet tot bescherming van de persoonlijke levenssfeer in verband met de verwerking van persoonsgegevens, informeert de hogervermelde licentiehouder u, als verantwoordelijke verwerker van deze gegevens, dat de door u meegedeelde persoonlijke gegevens, uitsluitend verwerkt worden om aan uw verzoek te voldoen tot het opstellen van een fiscale raming. Verder wordt verwezen naar de "
String buildDate = formatDate(service.getBuildDate());
disclaimer = disclaimer.replace("$BUILD_DATE$", buildDate);
P paragraph = createParagraph(disclaimer, DocxStyle.DISCLAIMER);

if (addHyperlink) {
String url = "www.google.com";
Hyperlink hyperlink = createHyperlink("Privacybepaling", url);
paragraph.getContent().add(hyperlink);

String disclaimerPart2 = "van de licentiehouder.";
P paragraph2 = createParagraph(disclaimerPart2, DocxStyle.DISCLAIMER);
paragraph.getContent().add(paragraph2);
}

lst.add(paragraph);
addObjects(lst, true);


protected Hyperlink createHyperlink(String displayText, String url) {
String hpl = "<w:hyperlink w:anchor=\"" + url
+ "\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" " +
"w:history=\"1\" >" +
"<w:r>" +
"<w:rPr>" +
"<w:rStyle w:val=\"Intensieve verwijzing\" />" + // TODO: enable this style in the document!
"</w:rPr>" +
"<w:t xml:space=\"preserve\">" + " " + displayText + " " + "</w:t>" +
"</w:r>" +
"</w:hyperlink>";

try {
return (Hyperlink) XmlUtils.unmarshalString(hpl);
}
catch (JAXBException e) {
// Shouldn't happen
e.printStackTrace();
return null;
}
}

protected void addObjects(List<Object> lst, boolean keepNext) {
if (lst != null && !lst.isEmpty()) {
setKeepNext(lst);
for (int i = 0; i < lst.size(); i++) {
if (lst.get(i) != null) {
getMainDocumentPart().getContent().add(lst.get(i));
}
}
}
}

protected P createParagraph(String text, DocxStyle style) {
ObjectFactory factory = Context.getWmlObjectFactory();
P par = getMainDocumentPart().createStyledParagraphOfText(style.getStyleName(), "");

if (getCompanySettingsID() != null && !getCompanySettingsID().equals(-1L)) {
try {
if (!SERVICES.getService(ICompanySettingsAccessService.class).getCompanySettingsByID(getCompanySettingsID()).isJustifyDisclaimerText()) {
PPr paragraphProperties = par.getPPr();
Jc justification = factory.createJc();
justification.setVal(JcEnumeration.LEFT);
paragraphProperties.setJc(justification);
}
}
catch (ProcessingException e) {
LOG.error("Error getting companySettings " + e.getMessage());
}
}
List<R> runs = getAllElementFromObject(par, R.class);
if (runs != null && !runs.isEmpty()) {
R run = runs.get(0);
Text t = null;
for (Object o : run.getContent()) {
if (o.getClass().equals(Text.class)) {
t = (Text) o;
break;
}
}

String[] lines = text.split("\n");
for (int i = 0; i < lines.length; i++) {
String line = lines[i];
if (t != null) {
t.setValue(line);
t = null;
}
else {
Text txt = factory.createText();
txt.setValue(line);
run.getContent().add(txt);
}

if (i < lines.length - 1) {
Br br = factory.createBr();
br.setType(STBrType.TEXT_WRAPPING);
run.getContent().add(br);
}
}
}

return par;
}

[Updated on: Wed, 20 July 2016 13:17]

Report message to a moderator

Re: Hyperlink in docx4j [message #1738583 is a reply to message #1738510] Thu, 21 July 2016 06:54 Go to previous messageGo to next message
Beat Schwarzentrub is currently offline Beat SchwarzentrubFriend
Messages: 207
Registered: November 2010
Senior Member
This seems to be a completely Docx4j related problem. Have you tried adding "http://" as a prefix to the URL? For an answer from the experts, you should probably ask your question in the Docx4j forum. Or have look at this test code from the official Docx4j repository: http://www.docx4java.org/svn/docx4j/trunk/docx4j/src/main/java/org/docx4j/samples/HyperlinkTest.java

Regards,
Beat
Re: Hyperlink in docx4j [message #1860891 is a reply to message #1738510] Thu, 07 September 2023 11:33 Go to previous messageGo to next message
Cătălin Burca is currently offline Cătălin BurcaFriend
Messages: 1
Registered: September 2023
Junior Member
Hello,

Did you find a solution for the problem?
Re: Hyperlink in docx4j [message #1860897 is a reply to message #1860891] Thu, 07 September 2023 15:05 Go to previous message
Beat Schwarzentrub is currently offline Beat SchwarzentrubFriend
Messages: 207
Registered: November 2010
Senior Member
Hi Cătălin

I don't think you will get an answer from the original author as the question was asked over 7 years ago. ;-)

Again: This problem is totally unrelated to Eclipse Scout. You should ask the docx4j community for advice. Please also make sure to read the Eclipes Scout Forum Rules. Thank you.

Regards,
Beat
Previous Topic:Thrown VetoException not visible from Login form
Next Topic:Drag And Drop in TileGrid
Goto Forum:
  


Current Time: Wed May 08 13:01:39 GMT 2024

Powered by FUDForum. Page generated in 0.04006 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top