html-to-docx icon indicating copy to clipboard operation
html-to-docx copied to clipboard

Downloaded documents cannot be open and message: "Word experienced an error trying to open the file..." appears

Open ocelph opened this issue 1 year ago • 5 comments

Hi! So, I am using node.js v22, and using html-to-docx v1.8.0 to convert an html page to docx format. This docx file can then be downloaded when I activated the download button. There are several button and each are for different content. The content is all there as i can see it in the preview however, every time I try to open in I get the following error:

Word experienced an error trying to open the file. Try these suggestions.

  • Check the file permissions for the document or drive.
  • Make sure there is sufficient free memory and disk space.
  • Open the file with the Text Recovery converter.

My coworker have also try to download the files but we keep getting the same error. We also tried to lower the node version to v16 but the problem persisted. (This is happening on Linux and MacOs)

If you have a solution or any idea of why this could be happening please let me know!

ocelph avatar Jul 25 '24 19:07 ocelph

Hello, I encountered the same problem (node.js v16, html-to-docx v1.8.0). For me this seems to occur only in desktop MS Word, but in WordPad, google docs and MS Word online (Microsoft 365) everything works fine. Also I can still open a file in desktop MS Word if I open it in read-only mode manually. Hope it helps.

leafnx avatar Jul 30 '24 11:07 leafnx

We were / are using html-docx-js but switching to html-to-docx and having the problem with both packages. We seemed to have fixed the problem by getting it to create a temporary html file first to a folder on the drive and then converting that file to a docx file, then allowing the user to download it from our app.

See the PR here, using html-docx-js: create temporary file for Word generator by shawnthompson · Pull Request #71 · aaact-aatia/a11y-ict-wizard.

Now I'm working on switching to html-to-docx, and it works.

shawnthompson avatar Aug 01 '24 17:08 shawnthompson

I'm facing the same issue, any updates?

rossanodr avatar Oct 31 '24 16:10 rossanodr

Just seeing this now... I am facing the same error (Issue 257). Did anyone find a solution ? Thanks!

C00kieMonsta avatar Jan 24 '25 12:01 C00kieMonsta

Hey, if you are using the params to define you files' margins, you have to define all of the params :

// WILL WORK
{
  "margins": {
    "header": 240,
    "footer": 240,
    "top": 80,
    "bottom": 80,
    "left": 90,
    "right": 90
  }
}
// WON'T WORK
{
  "margins": {
    "header": 240,
    "footer": 240,
    "top": 80,
    "bottom": 80,
    "left": 90
    // "right": 90
  }
}

See #57 for more info

AngrySquirrell avatar Feb 20 '25 15:02 AngrySquirrell