Ziv-Barber / officegen

Standalone Office Open XML files (Microsoft Office 2007 and later) generator for Word (docx), PowerPoint (pptx) and Excell (xlsx) in javascript. The output is a stream.
MIT License
2.65k stars 471 forks source link

There is no entry for `jpg` in [Content_Types].xml #315

Closed benvd closed 5 years ago

benvd commented 5 years ago

Environment

  1. node -v: v11.15.0
  2. npm -v: 6.7.0
  3. npm ls officegen: officegen@0.6.0
  4. Operating system: docx generated on Kubuntu 18.10, opened on macOS 10.14.4
  5. Microsoft Office version: Word for Mac 15.13.3
  6. Problem with Powerpoint, Excel or Word document: Word

Steps to Reproduce

Create a Word document using:

const docx = officegen('docx');

const p = docx.createP();
const image = 'photo.jpg';
p.addImage(path.resolve('images', image));

const out = fs.createWriteStream('test.docx');
docx.generate(out);

Expected Behavior

The resulting docx file should open properly in Word.

Actual Behavior

In Word for Mac, I get the following warning:

The Open XML file test.docx cannot be opened because there are problems with the contents or the file name might contain invalid characters (for example, \/). Details The file is corrupt and cannot be opened

Clicking "OK" results in the next message:

Word found unreadable content in test.docx. Do you want to recover the contents of this document? If you trust the source of this document, click yes.

Clicking "Yes" opens the document in Word, looking as it should.


What I did to fix this:

Alternatively calling addImage with a .jpeg file as opposed to .jpg does the trick as well.

fanlewis39 commented 5 years ago

I have encountered the same problem and hope that the addImage method can support images in jpg format.

Ziv-Barber commented 5 years ago

Fixed for version 0.6.3. It'll be out in the next few days. You can check it in the dev branch.