Docx: Creating hyperlink causes unreadable content prompt from Word

Created on 4 Dec 2019  路  7Comments  路  Source: dolanmiu/docx

Hello, hope all is well. Not sure if that has been reported or not but when a hyperlink is added to a document it causes word to prompt "Word found unreadable content in...". I am using the latest version rc-7.

I had added hyperlinks to a document I was creating and found that they were the issue. I then created the document in the hyperlinks demo and the issue was reproduced.

Here is a stackblitz of the issue: https://stackblitz.com/edit/angular-hm59la

Moderate bug

Most helpful comment

I'm having the same issue. Here's what I've done:

( async () => {

const doc = new Document();

const content = [
    new Paragraph ({
        children: [
            doc.createHyperlink('https://example.com', 'hyperlink')
        ]
    })
];

doc.addSection({
    properties: {},
    children: content,
});

let buffer;

try {
    buffer = await Packer.toBuffer(doc);

} catch (err) {
    return Promise.reject(err);
}

let file = `${process.env.HOME}/hyperlink.docx`;
require('fs').writeFileSync(file, buffer);

})()

If you try to open the file you'll see this:

Screen Shot 2019-12-04 at 3 21 01 PM

I'm using Node.js v10.16.0 and docx v5.0.0-rc7, and MS Word for Mac v16.31

All 7 comments

Will look into this

I'm having the same issue. Here's what I've done:

( async () => {

const doc = new Document();

const content = [
    new Paragraph ({
        children: [
            doc.createHyperlink('https://example.com', 'hyperlink')
        ]
    })
];

doc.addSection({
    properties: {},
    children: content,
});

let buffer;

try {
    buffer = await Packer.toBuffer(doc);

} catch (err) {
    return Promise.reject(err);
}

let file = `${process.env.HOME}/hyperlink.docx`;
require('fs').writeFileSync(file, buffer);

})()

If you try to open the file you'll see this:

Screen Shot 2019-12-04 at 3 21 01 PM

I'm using Node.js v10.16.0 and docx v5.0.0-rc7, and MS Word for Mac v16.31

I think this is fix with #448

if i'm true a new release to npm of the docxjs and an new import would fix the problem :)

@rvergar7 @jwerre try using docxjs from master and see if you still have the problem
@dolanmiu would it be possible to do a new release i'm currently using a fork with the fix but i would prefer to be base on this project

@Sraleik Yup! A release will be made very soon, just need to update the gif graphic on the README

This demo should also be updated, right?

demo/35-hyperlinks.ts

Should be up to date

This is fixed now, an example of how to do it is here:

https://github.com/dolanmiu/docx/blob/master/demo/35-hyperlinks.ts

Was this page helpful?
0 / 5 - 0 ratings