docx
docx copied to clipboard
Wrong DOCX format when using Google Docs
My generated Docx file seems corrupted when I try to view it on Google Docs or when I share it by email with someone else. I upload the generated Docx file to Google Docs, and when I try to read it, I see a black page. Someone tries to read it by email and can't open it, they see a black page too.
Can you send me some reproduction steps? The code you used to build the docx file?
Getting something similar with a fresh generated document.
However, if I take that generated docx:
- Open in Microsoft Word
- Do a small edit
- Save
- Upload to google drive => The document opens with no issue in google docs this time.
Trying to reproduce the issue at a smaller case (dealing with a big docx right now & will follow up).
Thank you yes please, create some reproduction steps
Yes, so TLDR; the issue (in my case at least) is because of defining the Normal
paragraphStyles basedOn Normal
-- this is what caused Google Docs to error.
const doc = new Document({
title: 'Google test',
styles: {
paragraphStyles: [
{
id: 'Normal',
name: 'Normal',
basedOn: 'Normal', // the error
next: 'Normal',
quickFormat: true,
run: {
font: 'Helvetica Neue',
size: 24,
},
paragraph: {
alignment: AlignmentType.LEFT,
spacing: {
line: 240 * 1.15,
},
},
}
],
},
sections: [
{
children: [
new Paragraph({
text: 'Hello world',
}),
],
},
],
});
So it was just that -- not sure it is the same issue as the OP had, I've certainly did not see a black page & the gmail previews would work just fine.
I think you can close this as IMO is not a bug. Maybe just a docs update to include details on how to change the Normal text paragraph in the library.
Is this because it is illegal to base a style on itself? Does removing that basedOn
line fix it?
Apparently for Google Docs, yes is illegal, causes their app to crash.
And yes, if you remove that line it fixes the issue.
Furthermore, if you base a style on itself, generate the doc, and then, if you open in Microsoft Word & save the file, it will remove that basedOn from the file (works afterwards when you upload to the Google Docs black box)