All Projects → Jeday → React Docx

Jeday / React Docx

Licence: mit
React reconciler for DOCX.js.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to React Docx

workable-converter
基于libreoffice实现的文档转换项目,无框架依赖,即插即用
Stars: ✭ 74 (+221.74%)
Mutual labels:  docx
Docx2tex
Converts Microsoft Word docx to LaTeX
Stars: ✭ 271 (+1078.26%)
Mutual labels:  docx
Zettlr
A Markdown Editor for the 21st century.
Stars: ✭ 6,099 (+26417.39%)
Mutual labels:  docx
TemplaterExamples
Creating reports in .NET and Java
Stars: ✭ 37 (+60.87%)
Mutual labels:  docx
GemBox.Document.Examples
Read, write, convert and print document files (DOCX, DOC, PDF, HTML, XPS, RTF, and TXT) in a simple and efficient way.
Stars: ✭ 53 (+130.43%)
Mutual labels:  docx
Docx
a ruby library/gem for interacting with .docx files
Stars: ✭ 288 (+1152.17%)
Mutual labels:  docx
EbookReader
The EbookReader Android App. Support file format like epub, pdf, txt, html, mobi, azw, azw3, html, doc, docx,cbz, cbr. Support tts.
Stars: ✭ 37 (+60.87%)
Mutual labels:  docx
Phpword
A pure PHP library for reading and writing word processing documents
Stars: ✭ 6,017 (+26060.87%)
Mutual labels:  docx
Unioffice
Pure go library for creating and processing Office Word (.docx), Excel (.xlsx) and Powerpoint (.pptx) documents
Stars: ✭ 3,111 (+13426.09%)
Mutual labels:  docx
Docx2md
Convert Microsoft Word Document to Markdown
Stars: ✭ 498 (+2065.22%)
Mutual labels:  docx
markdown-to-document
A Markdown CLI to easily generate HTML documents from Markdown files
Stars: ✭ 28 (+21.74%)
Mutual labels:  docx
redmine preview office
Plugin for Redmine. Preview Microsoft Office Documents in Redmine's preview pane
Stars: ✭ 27 (+17.39%)
Mutual labels:  docx
Docx Templates
Template-based docx report creation
Stars: ✭ 382 (+1560.87%)
Mutual labels:  docx
docxmustache
laravel 8.x docx template manipulation class, based on mustache templating language
Stars: ✭ 34 (+47.83%)
Mutual labels:  docx
Koodo Reader
A modern ebook manager and reader with sync and backup capacities for Windows, macOS, Linux and Web
Stars: ✭ 2,938 (+12673.91%)
Mutual labels:  docx
Wedge
可配置的小说下载及电子书生成工具
Stars: ✭ 62 (+169.57%)
Mutual labels:  docx
Msoffcrypto Tool
Python tool and library for decrypting MS Office files with passwords or other keys
Stars: ✭ 274 (+1091.3%)
Mutual labels:  docx
Docconv
Converts PDF, DOC, DOCX, XML, HTML, RTF, etc to plain text
Stars: ✭ 735 (+3095.65%)
Mutual labels:  docx
Kodexplorer
A web based file manager,web IDE / browser based code editor
Stars: ✭ 5,490 (+23769.57%)
Mutual labels:  docx
Fiduswriter
Fidus Writer is an online collaborative editor for academics.
Stars: ✭ 405 (+1660.87%)
Mutual labels:  docx

react-docx https://www.npmjs.com/package/react-docx

react-docx is a React reconciler for DOCX.js.

Why

Largely inspired by R3F this library allows you write your DOCX documents in declarative style with reusable components. This is not a wrapper library and so DOCX classes are trasformed dynamicly into React components.

Limitations

In current early stage of library and because of inconsistent style of some methods in DOCX.js not all advanced DOCX features may work declaratively. Currently only single render run is supported, that means that using useState or passing another set of values to Context providers will have no effect. Alternatively you can call renderAsyncDocument again to rerender the document entirely.

Usage

Install peer dependencies React and Docx! They are needed for JSX and DOCX elements.

import React from "react"; // that is needed for jsx to work
import { renderAsyncDocument } from "react-docx";
import * as Docx from "docx"; // that is a peer dependency

renderAsyncDocument(
  <section>
    <paragraph heading={Docx.HeadingLevel.HEADING_1}>
      You can pass props as if you are passing them to constructor
    </paragraph>
    <p>There are some helpful shortcuts for often used tags, like this</p>
    <p>
      <t>this one is for TextRun</t>
    </p>
    <p>
      For text inside anything else than t or textrun tags, TextRun is created
      under the hood
      <t break>
        For when docx objects have functional methods, you can pass function
        name as a prop. Prop value will be passed as an argument, if you need to
        pass many arguments use array instead.
      </t>
    </p>
    <p>
      Docx object is considered a tag if it has a constructor signature and is
      exported out of DOCX.js. Object key is then converted to lowercase.
      Everything you can make with raw DOCX.js(including mistakes), you can make
      here.
    </p>
    <p>
      <img
        src="base64 string or buffer object works"
        width={200}
        height={200}
      />
      <href
        src="http://localhost:8080"
        label={"For images and links shortcuts object are provided"}
      />
      This allows for removal of boilerplate for often used objects. In future
      more such object will be implemented.
    </p>
    <p>
      Sections are root tags for valid DOCX. If you want to have multiple
      sections, pass React Fragment with them to renderAsyncDocument.
    </p>
    <Component text="You can use components of course, just like in react!">
      <t>A child</t>
    </Component>
  </section>
).then((document) => console.log("This is rendered docx document", document));

const Component = ({ children, text }) => {
  const ref = React.useRef(null); // use can use refs to access docx objects
  React.useLayoutEffect(() => {
    // you can use LayoutEffect hook in combination with refs to write imperative code( hacks for example)
    console.log(ref.current);
    // because of useLayoutEffect nature it will work in single render as opposed to regular useEffect
  }, []);
  return (
    <p ref={ref}>
      <t>{text}</t>
      {children}
    </p>
  );
};

API

For details on Docx refer to it's docs.

Core render function, returns promise that is resolved with rendered document object. You can use Docx tools to convert it to blob, as according to Docx examples.

renderAsyncDocument(ReactElements, DocumentProperites, FileProperties);

Future Plans

  • More shortcuts
  • More fictive objects to remove boilerplate
  • Add mutations to Document tree
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].