question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ExternalHyperLink not working with images

See original GitHub issue

The code from the documentation (https://github.com/dolanmiu/docx/blob/master/demo/35-hyperlinks.ts) beginning at line 84 is not working for me:

new Paragraph({
  children: [
      new ExternalHyperlink({
          children: [
              new ImageRun({
                  data: fs.readFileSync("./demo/images/image1.jpeg"),
                  transformation: {
                      width: 100,
                      height: 100,
                  },
              }),
          ],
          link: "http://www.google.com",
      }),
  ],
})

When I copy this very snippet into my code, the image is rendered as expected but there is no link being integrated. It seems like the ExternalHyperLink element is not working specifically with images, as it works flawlessly when trying to add the link to a TextRun element. I tested also if it was a problem related to the code being positioned within the header section but the behaviour is the same when shifting the code to the body of the document.

I am using the latest version of docx. Is this a bug or can you give an advice what is going wrong here?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
dolanmiucommented, Dec 26, 2022

A pull request is made here to fix this issue:

https://github.com/dolanmiu/docx/pull/1853

Will be deployed in v8.0.0

0reactions
Niccobercommented, Dec 26, 2022

Dear @dolanmiu, thanks for the further effort you put into it. I’m glad you could reproduce it - I checked the provided files and can confirm that it is also the same behaviour for me. The finding regarding the a:hlinkClick property seems indeed promising.

As I would love to use the feature in my projects, I normally would just go ahead and create a PR for that on my own but unfortunately I am not very familiar with the code of docx js. I would really appreciate if the feature could be added within a future version of this project! If I can be of any help in terms of further investigation (e.g. if it does not work right away with the approach at hand) just let me know.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Fix Broken Images and Links on Your Website
Broken links or images cannot be caused by problems on the server side. They can only be caused by incorrect HTML coding or...
Read more >
Link on an image not working HTML - Stack Overflow
However this doesn't seem to work, Nothing happens on the image and it is not even clickable. Am I missing something? Should I...
Read more >
What will you do when an image or a hyperlink is not ... - Quora
Press Alt-Ctrl-Shift-S to bring up the Styles panel. Find the Hyperlink style in the list. (If the name is not visible, click “Options…”...
Read more >
Why is my link and image not working? - Codecademy
Hi Jason, your link is unfinished. You need to close it > add a title and close it again </a> . No spaces....
Read more >
Why is my image with URL that links to external site in a ...
The problem is the images aren't showing up and only showing up as broken links so there's a problem with the img src...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found