Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong DOCX format when using Google Docs #1794

Open
yukal opened this issue Nov 23, 2022 · 6 comments
Open

Wrong DOCX format when using Google Docs #1794

yukal opened this issue Nov 23, 2022 · 6 comments
Labels

Comments

@yukal
Copy link

yukal commented Nov 23, 2022

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.

@dolanmiu
Copy link
Owner

Can you send me some reproduction steps? The code you used to build the docx file?

@rizedr
Copy link

rizedr commented Mar 23, 2023

Getting something similar with a fresh generated document.
image

However, if I take that generated docx:

  1. Open in Microsoft Word
  2. Do a small edit
  3. Save
  4. 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).

@dolanmiu
Copy link
Owner

Thank you yes please, create some reproduction steps

@dolanmiu dolanmiu added the bug label Mar 23, 2023
@rizedr
Copy link

rizedr commented Mar 23, 2023

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.

@dolanmiu
Copy link
Owner

Is this because it is illegal to base a style on itself? Does removing that basedOn line fix it?

@rizedr
Copy link

rizedr commented Mar 23, 2023

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants