You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
Use the following code to generate a DOCX file:
importHTMLtoDOCXfrom'@turbodocx/html-to-docx';consthtmlContent=` <html> <body> <h1>Hello, World!</h1> <p>This is a test document.</p> </body> </html>`;constdocumentOptions={margins: {top: 1000,right: 1000,bottom: 1000,left: 1000,},font: 'Calibri',};constdocxBuffer=awaitHTMLtoDOCX(htmlContent,'',documentOptions,'');
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):
importHTMLtoDOCXfrom'@turbodocx/html-to-docx';consthtmlContent=` <html> <body> <h1>Hello, World!</h1> <p>This is a test document.</p> </body> </html>`;constdocumentOptions={font: 'Calibri',};constdocxBuffer=awaitHTMLtoDOCX(htmlContent,'',documentOptions,'');
Environment:
Library Version: @turbodocx/html-to-docx 1.9.3
Node.js Version: 22.2.0
Operating System: macOS
The text was updated successfully, but these errors were encountered:
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
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:After investigating the problem, I discovered that the issue is related to the
margins
object in thedocumentOptions
configuration. When I remove themargins
object, the DOCX file is generated correctly and opens without any issues in Word.Steps to Reproduce:
Observed Behavior:
Expected Behavior:
Workaround:
margins
object from thedocumentOptions
allows the DOCX file to open correctly in Word.Example of Working Code (without margins):
Environment:
@turbodocx/html-to-docx
1.9.3The text was updated successfully, but these errors were encountered: