Comments (3)
@ghilaslinz fs is not available on react, its stubbed out by design. Ref: https://stackoverflow.com/questions/55301477/fs-writefile-is-not-working-on-my-reactjs-nodejs-app
You can use packages like save-file.
from html-to-docx.
import HTMLtoDOCX from 'html-to-docx';
import { save } from 'save-file'
const htmlString = `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Document</title>
</head>
<body>
<div>
<p>Taken from wikipedia</p>
<img
src="data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="
alt="Red dot"
/>
</div>
<div>
<h1>This is heading 1</h1>
<p>Content</p>
<h2>This is heading 2</h2>
<p>Content</p>
<h3>This is heading 3</h3>
<p>Content</p>
<h4>This is heading 4</h4>
<p>Content</p>
<h5>This is heading 5</h5>
<p>Content</p>
<h6>This is heading 6</h6>
<p>Content</p>
</div>
<p>
<strong>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make
a type specimen book.
</strong>
<i>It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.</i>
<u>It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages,</u>and more recently with desktop publishing software
<span style="color: hsl(0, 75%, 60%);"> like Aldus PageMaker </span>including versions of Lorem Ipsum.
<span style="background-color: hsl(0, 75%, 60%);">Where does it come from? Contrary to popular belief, Lorem Ipsum is not simply random text.</span>
It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old.
</p>
<blockquote>
For 50 years, WWF has been protecting the future of nature. The world's leading conservation organization, WWF works in 100 countries and is supported by 1.2 million members in the United States and close to 5 million globally.
</blockquote>
<p>
<strong>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make
a type specimen book.
</strong>
</p>
<ul style="list-style-type: circle;">
<li>Unordered list element</li>
</ul>
<br>
<ol style="list-style-type: decimal;">
<li>Ordered list element</li>
</ol>
<div class="page-break" style="page-break-after: always"></div>
<ul>
<li>
<a href="https://en.wikipedia.org/wiki/Coffee">
<strong>
<u>Coffee</u>
</strong>
</a>
</li>
<li>Tea
<ol>
<li>Black tea
<ol>
<li>Srilankan <strong>Tea</strong>
<ul>
<li>Uva <b>Tea</b></li>
</ul>
</li>
<li>Assam Tea</li>
</ol>
</li>
<li>Green tea</li>
</ol>
</li>
<li>Milk
<ol>
<li>Cow Milk</li>
<li>Soy Milk</li>
</ol>
</li>
</ul>
<br>
<table>
<tr>
<th>Country</th>
<th>Capital</th>
</tr>
<tr>
<td>India</td>
<td>New Delhi</td>
</tr>
<tr>
<td>United States of America</td>
<td>Washington DC</td>
</tr>
</table>
</body>
</html>`;
const downloadFile = async () => {
const fileBuffer = await HTMLtoDOCX(htmlString, null, {
table: { row: { cantSplit: true } },
footer: true,
pageNumber: true,
});
await save(fileBuffer, 'trial.docx')
};
function App() {
return (
<div className="App">
<header className="App-header">
<button onClick={downloadFile}>HELLO</button>
</header>
</div>
);
}
export default App;
Attaching my example for reference. And closing the issue.
from html-to-docx.
Thank you, it's working
from html-to-docx.
Related Issues (20)
- How to resize images - is it possible?
- Images & style doesn't apply well in .docx file HOT 4
- html to docx conversion raise an error when it transform a table with merged cell
- Margins don't work
- ADD page break if content doesn't have enough room
- XML error when using with Vite (React or Vue)
- browser webpack error
- How to preserve border-bottom without table
- Refactoring work done HOT 4
- bug: when an image is nested under spans, xml-builder doesn't pick up the img tag
- README.md does not show how to load the HTMLtoDOCX function HOT 2
- Nested formatting tags are not getting applied
- STRIKE THROUGH Not working HOT 3
- Reference error : ReferenceError: HTMLToDOCX is not defined.
- Uncaught TypeError: Class extends value undefined is not a constructor or null
- ul element not properly displayed HOT 1
- Nuxt 3 (no SSR)+ Vite not working - Cannot read properties of undefined (reading 'prototype')
- Cannot read properties of undefined (reading 'getVNodeKey') HOT 1
- console.warning is not a function
- Module not found: Error: Can't resolve 'encoding' HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from html-to-docx.