πŸ“„ Create word documents with React

Overview

redocx

Build Status yarn license status

Create word documents with React

Introduction

redocx is a library which lets you create word documents with React. It provides a set of components which renders your declarative views and components to word documents.

Example

A simple component that renders a "Hello World" text to a word document.

import React from 'react'
import { render, Document, Text } from 'redocx'

class App extends React.Component {
  render() {
    return (
      <Document>
        <Text>Hello World</Text>
      </Document>
    )
  }
}

render(<App />, `${__dirname}/example.docx`)

Let's get started!

Install

Babel presets and cli

npm install --save-dev babel-cli babel-core babel-preset-env babel-preset-react babel-preset-stage-0

react and redocx

npm install --save react redocx

Usage

  • Create a .babelrc
{
  "presets": [
    "env",
    "stage-0",
    "react"
  ]
}
  • After configuring babel and assuming you've already created a file example.js with this example, run babel-node example.js. This will render your React component to word document.

Demo

git clone https://github.com/nitin42/redocx.git
cd redocx
npm install
npm run example

Documentation

See the detailed documentation here

Contributing

Contributing guide

License

MIT

Sponsor

Comments
  • `createBuffer` method

    `createBuffer` method

    Hi there!

    [This is an incomplete PR to start a conversation]

    Love redocx. I'm trying to make an http server that can serve up small word docs without hitting the filesystem. I figured I'd add a method to convert to a buffer but I'm running into some trouble understanding officegen. It seems like the finalize event that we pass to generate gets called before the stream gets its first data event. Does that make sense?

    opened by zekenie 6
  • Exclude regeneratorRuntime from compilation output

    Exclude regeneratorRuntime from compilation output

    ... otherwise there's stuff like this in the library (look for regeneratorRuntime):

    (excerpt from renderer/parse.js)

    'use strict';
    
    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports.testRenderer = exports.render = undefined;
    
    var renderToFile = function () {
      var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(element, filePath) {
        var container, node, output, stream;
        return regeneratorRuntime.wrap(function _callee$(_context) {
          while (1) {
            switch (_context.prev = _context.next) {
              case 0:
                container = (0, _createElement.createElement)('ROOT');
    
    
                (0, _renderUtils.validateElement)(element);
    
                (0, _renderUtils.validatePath)(filePath);
    
                node = _renderer.WordRenderer.createContainer(container);
    
    
                _renderer.WordRenderer.updateContainer(element, node, null);
    
                _context.next = 7;
                return (0, _parse2.default)(container).toBuffer();
    
              case 7:
                output = _context.sent;
                stream = _fs2.default.createWriteStream(filePath);
                _context.next = 11;
                return new Promise(function (resolve, reject) {
                  output.doc.generate(stream, (0, _renderUtils.Events)(filePath, resolve, reject));
    
                  (0, _renderUtils.openDocApp)(filePath);
                });
    
              case 11:
              case 'end':
                return _context.stop();
            }
          }
        }, _callee, this);
      }));
    
      ....
    

    ref: https://github.com/nitin42/redocx/issues/18

    This makes it problematic to use this library where babel runtime is not used.

    opened by runk 3
  • regeneratorRuntime is not defined

    regeneratorRuntime is not defined

    Uncaught ReferenceError: regeneratorRuntime is not defined at modules.js?hash=ef51e63ae4ee39b60c1820fb31cac832c0ce8cf6:231605 at render.js (modules.js?hash=ef51e63ae4ee39b60c1820fb31cac832c0ce8cf6:231647) at fileEvaluate (modules-runtime.js?hash=9f9bb5e055614ddf4eb3e743737b7a5b3cfd9d34:353) at require (modules-runtime.js?hash=9f9bb5e055614ddf4eb3e743737b7a5b3cfd9d34:248) at index.js (modules.js?hash=ef51e63ae4ee39b60c1820fb31cac832c0ce8cf6:231541) at fileEvaluate (modules-runtime.js?hash=9f9bb5e055614ddf4eb3e743737b7a5b3cfd9d34:353)

    opened by osamaabdalla 3
  • Issue with NPM V5.3.0

    Issue with NPM V5.3.0

    Not uncommon for new versions of npm to break babel or something on a few projects. Installing dependencies in a fresh new npm module using newest npm version results in an error like this:

    Error: Cannot find module 'react/lib/checkPropTypes'
        at Function.Module._resolveFilename (module.js:489:15)
        at Function.Module._load (module.js:439:25)
        at Module.require (module.js:517:17)
        at require (internal/module.js:11:18)
        at Object.<anonymous> (C:\Users\harmon\Desktop\redocx-testing\node_modules\react-dom\lib\checkReactTypeSpec.js:13:22)
        at Module._compile (module.js:573:30)
        at Module._extensions..js (module.js:584:10)
        at Object.require.extensions.(anonymous function) [as .js] (C:\Users\harmon\AppData\Roaming\npm\node_modules\babel-cli\node_modules\babel-register\lib\node.js:152:7)
        at Module.load (module.js:507:32)
        at tryModuleLoad (module.js:470:12)
    

    This may be a Just a Windows problem.. Removing node_modules folder, and reinstalled dependencies using yarn install resolved the problem!

    Figure I would make a post for people looking to try this out, that run into the same issue. Very cool library!

    opened by harmon25 3
  • [ImgBot] optimizes images

    [ImgBot] optimizes images

    Hey there. I've just optimized all of you images. They are the same dimensions and quality as before, only they take up less space now.

    \redocx.png (20.22%)) \examples\concr.png (23.97%))

    opened by ImgBotApp 2
  • Render in-memory

    Render in-memory

    This PR adds the ability to render the document to memory mapped stream instead of directly to FS. This is useful for APIs that need to return Docx, etc.

    opened by bigmstone 1
  • Added Platform API

    Added Platform API

    I added the Platform API to be consistent with React Native. A lot of other custom renderers (react-sketchapp, Apple TV, macOS, etc) all have it. It's useful for platform differences within universal components. πŸ˜€

    Feel free to change the platform name word to whatever you'd prefer.

    opened by peggyrayzis 1
  • Getting error, to up and running

    Getting error, to up and running

    babel-node ./demo/Word.js

    /usr/bin/env: β€˜node’: No such file or directory

    npm ERR! Linux 4.10.0-32-generic npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "run" "example" npm ERR! node v4.2.6 npm ERR! npm v3.5.2 npm ERR! file sh npm ERR! code ELIFECYCLE npm ERR! errno ENOENT npm ERR! syscall spawn npm ERR! [email protected] example: babel-node ./demo/Word.js npm ERR! spawn ENOENT npm ERR! npm ERR! Failed at the [email protected] example script 'babel-node ./demo/Word.js'. npm ERR! Make sure you have the latest version of node.js and npm installed. npm ERR! If you do, this is most likely a problem with the redocx package, npm ERR! not with npm itself. npm ERR! Tell the author that this fails on your system: npm ERR! babel-node ./demo/Word.js npm ERR! You can get information on how to open an issue for this project with: npm ERR! npm bugs redocx npm ERR! Or if that isn't available, you can get their info via: npm ERR! npm owner ls redocx npm ERR! There is likely additional logging output above.

    npm ERR! Please include the following file with any support request: npm ERR! /home/jsroyal/redocx/npm-debug.log

    I could not get it.

    opened by jitendra3109 1
  • Questions about the header component and also Column support

    Questions about the header component and also Column support

    Hi, Dear team,

    Thanks for the awesome efforts u guys put onto this project, it's great. Recently, Ive started using this cool stuff to create CV-like document. Ive seen a few limits, so wanna ask some questions here:

    1. Can header component render other intermediate components? just like Text component with the capability to render LineBreak/Image/Hr components, so that I could so things like this(looks like putting text on top of an image): image Alternatively, lets say in Text component, is it possible to align the text on top of an image?

    2. would Column be supported in the future? image

    opened by iLeviPro 0
  • is PolarChart possilble that export to word in redocx

    is PolarChart possilble that export to word in redocx

    i want to react page export to word(.docx) chart upper image is react PolarChart page i searched how to export to word for chart but all of your documentation can export to letter or image only

    opened by semi8583 0
  • Using Context Throws an Error

    Using Context Throws an Error

    If you wrap the document with a context provider, it throws the error

    Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.\n\nCheck the render method of `ContextProvider`.
    

    To Replicate

    import React, {createContext} from 'react'
    import { render, Document, Text } from 'redocx';
    
    const ContextProvider = createContext().Provider
    
    render(
        <ContextProvider>
            <Document>
                <Text>Hello</Text>
            </Document>
        </ContextProvider>
    );
    
    opened by hazem3500 0
  • Support base64 strings for Image component

    Support base64 strings for Image component

    This is mainly intended as a workaround to render images in a word document when rendering to a stream.

    Since it's not supported in the officegen package, the solution was based on this issue https://github.com/Ziv-Barber/officegen/issues/32.

    (Also updated dependencies and updated offigen to the latest version 0.6.4)

    opened by hstandaert 0
  • <ImageComponent /> not working when rendering to memory

    not working when rendering to memory

    When I add the <ImageComponent /> to the word-memory.js file, the process silently fails... The same document does work when rendering to a file directly.

    word-memory.js
    import fs from 'fs';
    import React, { Component } from 'react';
    import TextComponent from '../examples/Text';
    import { render, Document, Text } from '../src/';
    
    // Uncomment any of the below component to see what they render
    
    import FooterComponent from '../examples/Footer';
    import HeaderComponent from '../examples/Header';
    import HrComponent from '../examples/Hr';
    import LineBreakComponent from '../examples/LineBreak';
    import PageBreakComponent from '../examples/PageBreak';
    import TableComponent from '../examples/Table';
    import ListComponent from '../examples/List';
    import ImageComponent from '../examples/Image';
    
    class MyDocument extends Component {
      render() {
        return (
          <Document>
            <TextComponent />
            <ImageComponent />
          </Document>
        );
      }
    }
    
    render(<MyDocument />).then((stream) => {
      fs.open('./demo/Memory.docx', 'w+', stream.length, (err, fd) => {
        if (err) {
          console.log(err);
        }
        fs.write(fd, stream.toBuffer(), (writeErr) => {
          if (writeErr) {
            console.log(writeErr);
          }
          console.log('Docx generated and saved to ./demo/Memory.docx');
        });
      });
    });
    
    CLI output

    Screenshot 2020-09-09 at 17 15 25

    opened by hstandaert 1
  • Question: does this work with dynamic content

    Question: does this work with dynamic content

    Can this convert only after a click event?
    I need to wait for some user interactions and API requests to finish. I guess it would need an option to work at run time

    opened by conor909 0
Releases(1.1.3)
Owner
Nitin Tulswani
Nitin Tulswani
πŸ“„ Create PDF files using React

React renderer for creating PDF files on the browser and server Lost? This package is used to create PDFs using React. If you wish to display existing

Diego Muracciole 11.6k Jan 8, 2023
πŸŽ₯ Create videos programmatically in React

Join the Discord Remotion is a suite of libraries building a fundament for creating videos programmatically using React. Why create videos in React? L

Jonny Burger 14.9k Dec 30, 2022
React bindings to create and control a 3D scene using three.js

react-three-legacy Create/control a three.js canvas using React. To use React for drawing 2D using WebGL, try react-pixi. This react-three is deprecat

Gary Haussmann 1.5k Jan 2, 2023
Create amazing 360 and VR content using React

React 360 React 360 is a framework for the creation of interactive 360 experiences that run in your web browser. It pairs modern APIs like WebGL and W

Facebook Archive 8.7k Jan 5, 2023
Create elegant HTML email templates using React.

react-html-email ⚠️ Currently Unmaintained react-html-email is presently unmaintained. As React has matured, it is no longer as necessary to use a sep

Max Goodhart 889 Jan 3, 2023
React JSX Renderer is a React Component for rendering JSX to React nodes.

React JSX Renderer A React Component for Rendering JSX. Description React JSX Renderer is a React Component for rendering JSX to React nodes.

Sho Kusano 43 Nov 28, 2022
πŸ‡¨πŸ‡­ A React renderer for Three.js (web and react-native)

react-three-fiber react-three-fiber is a React renderer for threejs on the web and react-native. npm install three react-three-fiber These demos are r

Poimandres 20.9k Jan 8, 2023
πŸ™ A minimal implementation of react-dom using react-reconciler

react-tiny-dom react-tiny-dom is a minimal implementation of react-dom as custom renderer using React 16 official Renderer API. The purpose of this pr

Jiayi Hu 453 Jan 6, 2023
πŸ‡¨πŸ‡­ A React renderer for Three.js (web and react-native)

react-three-fiber react-three-fiber is a React renderer for threejs on the web and react-native. npm install three react-three-fiber These demos are r

Poimandres 20.9k Jan 8, 2023
[ Unmaintained due to raphamorim/react-ape ] React Renderer for low memory applications

React-TV Β· react-tv: React Renderer for low memory applications. react-tv-cli: React Packager for TVs. Currently under development. import React from

Raphael Amorim 2k Jan 6, 2023
React PDF viewer - A React component to view a PDF document

A React component to view a PDF document. It's written in TypeScript, and powered by React hooks completely.

React PDF Viewer 1.4k Jan 3, 2023
Osd-react-renderer - A custom React renderer for OpenSeadragon

osd-react-renderer A custom React renderer for OpenSeadragon viewer, built using

Lunit Inc. 4 Dec 5, 2022
🌈 React for interactive command-line apps

React for CLIs. Build and test your CLI output using components. Ink provides the same component-based UI building experience that React offers in the

Vadim Demedes 19.7k Jan 3, 2023
render React components to Sketch βš›οΈπŸ’Ž

render React components to Sketch; tailor-made for design systems Quick-start ??‍ First, make sure you have installed Sketch version 50+, & a recent n

Airbnb 14.9k Dec 30, 2022
βš›οΈ A React renderer for Figma

React Figma A React renderer for Figma. Use React components as a source for your designs. ?? Compatible with react-native, react-sketchapp, react-pri

React Figma 2.2k Jan 5, 2023
⃝ A react null renderer

Nothing to see here ... Quite so. This package allows you to bring Reacts high-level component abstraction to Node, or wherever you need it. Why not m

Poimandres 653 Dec 23, 2022
A React renderer for Hardware.

React Hardware React Hardware enables you to build firmata-based hardware applications using a consistent developer experience based on JavaScript and

Dustan Kasten 794 Dec 26, 2022
React Bridge to the ART Drawing Library

Note: This package is now part of the facebook/react monorepo. React ART React ART is a JavaScript library for drawing vector graphics using React. It

React Community 2k Dec 10, 2022
High performance canvas> rendering for React components

react-canvas Introductory blog post React Canvas adds the ability for React components to render to <canvas> rather than DOM. This project is a work-i

Flipboard 13k Dec 30, 2022