Giter VIP home page Giter VIP logo

docxjs's People

Contributors

champkeh avatar dmitri-gb avatar fangd1997 avatar jrclaypool avatar volodymyrbaydalka avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

docxjs's Issues

index.vue:41 Uncaught Error: TypeError: n2.zip.loadAsync is not a function

i use docx-preview in vue 3 . And this is my code

import * as docx from 'docx-preview'
import Docxtemplater from 'docxtemplater'
import JSZipUtils from 'jszip-utils'
import { saveAs } from 'file-saver'
import * as JSZip from 'jszip'

onMounted(() => {
  window.JSZip = JSZip
})

const exportWord = () => {
  JSZipUtils.getBinaryContent('template.docx', function(error, content) {
    console.log('-----', content)
    if (error) {
      throw error
    }
    const zip = new JSZip(content)
    console.log('+++++', zip)
    const doc = new Docxtemplater()
    console.log('/////', doc)
    doc.loadZip(zip)
    console.log('=====', doc)
    doc.setData({
      ...toRaw(props.row)
    })
    try {
      doc.render()
    } catch (error) {
      const e = {
        message: error.message,
        name: error.name,
        stack: error.stack,
        properties: error.properties
      }
      console.log(JSON.stringify({ error: e }))
      throw error
    }
    const out = doc.getZip().generate({
      type: 'blob',
      mimeType:
        'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
    })
    previewShow.value = true
    docx.renderAsync(out, word)
    // saveAs(out, '测试.docx')
  })
}

how can i solve this problem.

Plans to support shapes?

Shapes in documents are skipped. I do know from my OpenXML work, this is one of the harder things to support.

Any plans to add shapes? simple sample docx attached

pill.docx

JSZip not found on OS with case sensitity

Hello,

I am contacting you to report a bug in your library that I have integrated into an Angular project.
On windows I have no problems, but on linux I have a message telling me that it does not find JSZip.

When I look closer, I see that the problem comes from the fact that "JSZip" is not present in node_modules, but "jszip" is.

To correct the problem, you just need to change the references to "JSZip" to "jszip" in your library.

Would it be possible to integrate this fix?

document is not defined when using on React

I am trying to use this library in a React app, but everytime I try to use renderAsync(), an error appears telling me "document is not defined".

Here is my code. I am using TypeScript on a next.js project.

import styles from '../styles/Home.module.css'
import { renderAsync, defaultOptions } from 'docx-preview'
import React, { useEffect, useRef, useState } from "react";
import DocViewer, {PDFRenderer} from 'react-doc-viewer';
import JSZip from 'jszip';

export default function Home() {

const [text, setText] = useState("Docx document reader");
const [file, setFile] = useState();
const [show, setShow] = useState(false);

const onChange = (e: any) => {
if (e !== null) {
setText("File uploaded !");
setFile(e)
}
};

const previewFile = () => {
if (file !== null) {

  setShow(true);

  if (typeof document !== "undefined") {
    // document exists
    let container = document.getElementById("preview") as HTMLElement;
    console.log(container)
    //Render the Word Document.
    renderAsync(file, container);
  } 
  else {
    // document does not exist
  }

}

}

return (


{text}

  <input type="file" accept='.docx' value={file} onChange={e => onChange(e.target.value)}/>
  <input type="button" id="btnPreview" value="Preview Word Document" onClick={previewFile} />

  <div id='preview' ></div>
  {/*(show && file !== undefined) && <DocViewer pluginRenderers={[PDFRenderer]} documents={[{uri: require('C:/Users/LudovicBORGES/Documents/wrd-reader/word.txt')}]}/>*/}

</div>

)
}

Can support charts?

Describe the bug

Can not load charts,there is a blank space instead!

Document

Any document which contains chart!

CSP Issues

Hello @zVolodymyr,

Unfortunately the creation of those style blocks result in violations to csp settings in regards to inline-styles.
Do you see any possibility to introduce an option, to style all elements directly with js calls, instead of providing a style block?

Thanks and best regards

Thiemo

Can't read the data of 'the loaded zip file'

Describe the bug
Can't read the data of 'the loaded zip file'. Is it in a supported JavaScript type (String, Blob, ArrayBuffer, etc)

Document
axios({ method: 'get', responseType: 'blob', url: '***' }).then(({ data }) => { console.log('测试数据', docx) docx.renderAsync(data, document.getElementById('documentDocx'), null, { renderHeaders: false, renderFooters: false, debug: true }).then(x => { console.log(x) }) });

page break

hi,
page break didn't work properly, because i guess you didn't check the lastRenderedPageBreak.

Basically there are 3 types of breaks:

  • page breaks
  • section breaks
  • lastRenderedPageBreak
    thank you.

How to show revisions in word docx

Describe the bug
Can't show revisions in docx preview.

Document
The file can't show revisions is uploaded below.
test.docx

Expected behavior
Hope to show revisions on website.

Screenshots
image

Desktop (please complete the following information):

  • OS: [Windows]
  • Browser [chrome]
  • Version [all]

Equation Editor (Microsoft Equation 3.0) and Shape not display when previewing in browser

Thanks for your excellent work. I found your lib is very helpful for my project, but I got some problems as described below:

Describe the bug

  1. Equation created by Equation Editor (Microsoft Equation 3.0) in Word file (.docx) can not display when previewing in browser
  2. Shape can not display when previewing in browser

Screenshots
Original document: https://drive.google.com/file/d/1P-y1PWbN-w07HIUyhJw2LQBlyCP9LKz5/view?usp=sharing
Display on browser: https://drive.google.com/file/d/1buz5_v-xU_MuwOVWjmyMQElkiZvhrF5U/view?usp=sharing

Document
Please check original document here: https://docs.google.com/document/d/1WWjMulUVjr0S2RD1TOTxazMNtatEHKQW/edit?usp=sharing&ouid=102073849288913805416&rtpof=true&sd=true

Thanks

Recursive style dependencies are not resolved properly

If there is a style a and it is based on b which itself is based on c, the current code (resolving it alphabeticcaly, due to the map) ignores the rules of c in the moment it copies to a.

I already have a fix for this and will open PR soon.

Sequence number conversion error

Describe the bug
when use 一、二、三 as Sequence number,it transform to 1、2、3

Expected behavior
i hope it can convert Chinese serial numbers

Pull Requests & Assistance

First I just want to say great project! You have a fairly solid implementation and its not too hard to follow as well.

I've been working on something similar over the past few days for fun and ended up stumbling on your implementation. I'd love to help push this project further if you're open to some assistance and partnership.

I've created two pull requests for review #8 and #9

Preview of image not working on firefox

Hello,

I am contacting you to report a bug in your library that I have integrated into an Angular project.
On Firefox it is impossible to visualize images in a document.

By looking closer, I realize that the problem comes from the URL API of the browser which is not implemented in the same way on Chrome as on Firefox.

Indeed, the toString method does not return the same result:

new URL("media/image2.png", "file://docx/" + "word/").toString()
Chrome => 'file://docx/word/media/image2.png'
Firefox => 'file:///word/media/image2.png'

To correct the problem, you just need to modify the "prefix" variable in the resolvePath method of your library by replacing the value "file://docx/" with "file:///docx/";

Would it be possible to integrate this fix?

e3.appendChild is not a function

I encountered this problem the first time I accessed it. Could you please help me take a look
quesition:
image

this is my code: Vue3

<template>
  <div class="container">
    <a-upload-dragger
      name="file"
      accept=".docx"
      action="https://www.mocky.io/v2/5cc8019d300000980a055e76"
      :before-upload="beforeUpload"
      :headers="{ 'X-Requested-With': null }"
    >
      <p class="ant-upload-drag-icon">
        <inbox-outlined></inbox-outlined>
      </p>
      <p class="ant-upload-text">Click or drag file to this area to upload</p>
      <p class="ant-upload-hint">
        Support for a single or bulk upload. Strictly prohibit from uploading
        company data or other band files
      </p>
    </a-upload-dragger>
    <div class="doc-preview" ref="docContainer"></div>
  </div>
</template>

<script setup>
import { ref } from 'vue';
import { renderAsync } from 'docx-preview'
const docContainer = ref(null)

const beforeUpload = file => {
  let fileReader = new FileReader();
  fileReader.readas
  fileReader.readAsArrayBuffer(file);
  fileReader.onload = () => {
    renderAsync(fileReader.result,docContainer)
  };
};

render image wrap in wrong position (feature request?)

.docx image wrap has 6 type of settings (wrap off, before, after, parallel, through, optimal)

wrap off sometimes in wrong lines

Thanks god, through is Normal

before, after, parallel, optimal is just css float:left

For example:

    This is what parallel wrap looks
like on microsoft  ########### word,
libreOffice writer #         # , or 
something else.    #  image  # test
words test word    #         # test 
words test word    ###########  test 
words test words  test  words  test 
    And this is what parallel wrap 
########### looks like on this npm
#         # package. words test 
#  image  # words test word  test 
#         # words test word  test 
########### words test word  test 
words test words  test  words  test 

.docx file rendered, but display not completely

Describe the bug
.docx file rendered, but display not completely, the file page's left part(about 4 letters width) is missing, I can't scroll left either, otherwise at least the right part can see when I scroll to the right.

mobile web pages.

Document

const docxOptions = Object.assign(defaultOptions, {
  debug: true, //enables additional logging
  experimental: true, //enables experimental features (tab stops calculation)
  // className: "docx", //class name/prefix for default and document style classes
  // inWrapper: false, //enables rendering of wrapper around document content
  // ignoreWidth: false, //disables rendering width of page
  // ignoreHeight: false, //disables rendering height of page
  // ignoreFonts: false, //disables fonts rendering
  // breakPages: false, //enables page breaking on page breaks
  // ignoreLastRenderedPageBreak: false, //disables page breaking on lastRenderedPageBreak elements
  // trimXmlDeclaration: false, //if true, xml declaration will be removed from xml documents before parsing
  // useBase64URL: false, //if true, images, fonts, etc. will be converted to base 64 URL, otherwise URL.createObjectURL is used
  // useMathMLPolyfill: false, //includes MathML polyfills for chrome, edge, etc.
});
await renderAsync(buffer, target, null, docxOptions);

Expected behavior
see the pages properly

Screenshots

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]: Chrome (see the screenshots)
  • Version [e.g. 22]: 103.0.5060.53

Additional context
"docx-preview": "^0.1.11",
"vue": "^2.6.14",

Can't find end of central directory (jszip)

Describe the bug
jszip: can‘t find end of central directory: is this a zip file?

Document
java use freemarker, ajax callback a blob, just like this:
image
i just renderAsync this blob, error.
maybe freemarker created blob is diffrent?

Expected behavior
i hope it working

Desktop (please complete the following information):

  • OS: windows
  • Browser chrome
  • Version 22

Line Breaks are not rendered

While the doucment Parser detects line breaks, those are not rendered.

I already have a fix and will create PR soon

TableCell rendering bug Td rowspan Is not correct

Describe the bug
TableCell rendering Td rowspan Is not correct!
360截图20221027152957198

Document

10kVbyqhzdl1.docx

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

Tables extend into right padding of main section tag

First let me say your library is the best I have tried so far so thanks for your amazing work.

For any document that has a standard table included in it the tables width after conversion to html extends into the padding. Typical word document have the parent section with a set padding around entire page. Tables extend into the right margin but start perfecting where the padding starts on the left as it should.

The table width should be consistent with the the display inside the document.

Page break

Thanks for your excellent work. I found a feature not documented in README. If there is not any page break inserted in the docx file, all content will be rendered in one page no matter how long it is. Is there any option to enable page break automatically just like Microsoft office?

Table of contents

Is there any way to get Table of content separately?
And can its links be used?

picture not showing

Describe the bug
Picture not showing see attachment

Document
If applicable, add *.docx document to help explain your problem.
docxjs_issues.docx

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.
docxjs
image
office
image

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Additional context
Add any other cont
docxjs_issues.docx
ext about the problem here.

Document serial number is missing.

For Chinese documents, the serial number is seriously lost, both Chinese and digital. Line breaks are also not accurate enough, and there are some problems with consistency.

Hyperlinks are not rendered as tag a

Hyperlinks are not rendered as tag a


This is part of the document.xml

    <w:p>
      <w:pPr>
        <w:ind w:firstLine="420" w:firstLineChars="0"/>
      </w:pPr>
      <w:r>
        <w:rPr>
          <w:color w:val="auto"/>
          <w:u w:val="none"/>
        </w:rPr>
        <w:fldChar w:fldCharType="begin"/>
      </w:r>
      <w:r>
        <w:rPr>
          <w:color w:val="auto"/>
          <w:u w:val="none"/>
        </w:rPr>
        <w:instrText xml:space="preserve"> HYPERLINK \l &quot;_# test title&quot; </w:instrText>
      </w:r>
      <w:r>
        <w:rPr>
          <w:color w:val="auto"/>
          <w:u w:val="none"/>
        </w:rPr>
        <w:fldChar w:fldCharType="separate"/>
      </w:r>
      <w:r>
        <w:rPr>
          <w:rStyle w:val="6"/>
        </w:rPr>
        <w:t>test</w:t>
      </w:r>
      <w:r>
        <w:rPr>
          <w:color w:val="auto"/>
          <w:u w:val="none"/>
        </w:rPr>
        <w:fldChar w:fldCharType="end"/>
      </w:r>
    </w:p>
    <w:p>
      <w:pPr>
        <w:ind w:left="420" w:leftChars="0" w:firstLine="420"/>
        <w:rPr>
          <w:rStyle w:val="6"/>
          <w:i/>
          <w:iCs/>
          <w:lang w:eastAsia="zh-Hans"/>
        </w:rPr>
      </w:pPr>
      <w:r>
        <w:rPr>
          <w:rFonts w:hint="eastAsia"/>
          <w:i/>
          <w:iCs/>
          <w:color w:val="auto"/>
          <w:u w:val="single"/>
          <w:lang w:eastAsia="zh-Hans"/>
        </w:rPr>
        <w:fldChar w:fldCharType="begin"/>
      </w:r>
      <w:r>
        <w:rPr>
          <w:rFonts w:hint="eastAsia"/>
          <w:i/>
          <w:iCs/>
          <w:color w:val="auto"/>
          <w:u w:val="single"/>
          <w:lang w:eastAsia="zh-Hans"/>
        </w:rPr>
        <w:instrText xml:space="preserve"> HYPERLINK &quot;https://www.baidu.com/&quot; </w:instrText>
      </w:r>
      <w:r>
        <w:rPr>
          <w:rFonts w:hint="eastAsia"/>
          <w:i/>
          <w:iCs/>
          <w:color w:val="auto"/>
          <w:u w:val="single"/>
          <w:lang w:eastAsia="zh-Hans"/>
        </w:rPr>
        <w:fldChar w:fldCharType="separate"/>
      </w:r>
      <w:r>
        <w:rPr>
          <w:rStyle w:val="6"/>
          <w:rFonts w:hint="eastAsia"/>
          <w:i/>
          <w:iCs/>
          <w:lang w:eastAsia="zh-Hans"/>
        </w:rPr>
        <w:t>敬请期待</w:t>
      </w:r>
    </w:p>

案例1.docx

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.