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

DOCX File Not Opening in Microsoft Word When Using Margins Configuration #35

Closed
maxdinech opened this issue Jun 25, 2024 · 2 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@maxdinech
Copy link

maxdinech commented Jun 25, 2024

Hello,

I encountered an issue where DOCX files generated using the html-to-docx library fail to open in Microsoft Word. The error message displayed by Word is:

Word encountered an error trying to open the file.

After investigating the problem, I discovered that the issue is related to the margins object in the documentOptions configuration. When I remove the margins object, the DOCX file is generated correctly and opens without any issues in Word.

Steps to Reproduce:

  1. Use the following code to generate a DOCX file:
    import HTMLtoDOCX from '@turbodocx/html-to-docx';
    
    const htmlContent = `
      <html>
        <body>
          <h1>Hello, World!</h1>
          <p>This is a test document.</p>
        </body>
      </html>
    `;
    
    const documentOptions = {
      margins: {
        top: 1000,
        right: 1000,
        bottom: 1000,
        left: 1000,
      },
      font: 'Calibri',
    };
    
    const docxBuffer = await HTMLtoDOCX(htmlContent, '', documentOptions, '');
  2. Attempt to open the generated DOCX file in Microsoft Word.

Observed Behavior:

  • Word displays an error message and fails to open the file.

Expected Behavior:

  • Word should open the DOCX file without any errors.

Workaround:

  • Removing the margins object from the documentOptions allows the DOCX file to open correctly in Word.

Example of Working Code (without margins):

import HTMLtoDOCX from '@turbodocx/html-to-docx';

const htmlContent = `
  <html>
    <body>
      <h1>Hello, World!</h1>
      <p>This is a test document.</p>
    </body>
  </html>
`;

const documentOptions = {
  font: 'Calibri',
};

const docxBuffer = await HTMLtoDOCX(htmlContent, '', documentOptions, '');

Environment:

  • Library Version: @turbodocx/html-to-docx 1.9.3
  • Node.js Version: 22.2.0
  • Operating System: macOS
@maxdinech maxdinech changed the title Margins in the document options corrupt the Word files DOCX File Not Opening in Microsoft Word When Using Margins Configuration Jun 25, 2024
@nicolasiscoding
Copy link
Member

Thank you for submitting, we will take a look

@nicolasiscoding nicolasiscoding added the bug Something isn't working label Jun 25, 2024
nicolasiscoding added a commit that referenced this issue Jun 27, 2024
* Create npm-publish.yml (#27)

* fix: fixed a bug when margin are provided docx is not generated properly

* Feature/contributors update (#26)

* feat: add contributors

* fix: cleanup readme

* feat: add banner and updated package.json

* chore: fixes and update .gitignore

* chore: readme styling

* chore: readme refactor styling

* chore: add AmitSharma512 as a contributor

---------

Co-authored-by: Nicolas <nicolasiscoding@users.noreply.github.com>
Co-authored-by: nicolasiscoding <nicolascoding@gmail.com>
@nicolasiscoding
Copy link
Member

@maxdinech fixed in v1.9.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants