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
Operating system: docx generated on Kubuntu 18.10, opened on macOS 10.14.4
Microsoft Office version: Word for Mac 15.13.3
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:
I unzipped test.docx and opened [Content_Types].xml
In that file, there was this: <Default Extension="jpeg" ContentType="image/jpeg"/>
Right after that chunk, I added: <Default Extension="jpg" ContentType="image/jpg"/> (i.e. jpg instead of jpeg)
I re-zipped everything as a docx file, which now did open properly in Word, without warnings.
Alternatively calling addImage with a .jpeg file as opposed to .jpg does the trick as well.
Environment
node -v
: v11.15.0npm -v
: 6.7.0npm ls officegen
: officegen@0.6.0Steps to Reproduce
Create a Word document using:
Expected Behavior
The resulting docx file should open properly in Word.
Actual Behavior
In Word for Mac, I get the following warning:
Clicking "OK" results in the next message:
Clicking "Yes" opens the document in Word, looking as it should.
What I did to fix this:
test.docx
and opened[Content_Types].xml
<Default Extension="jpeg" ContentType="image/jpeg"/>
<Default Extension="jpg" ContentType="image/jpg"/>
(i.e.jpg
instead ofjpeg
)Alternatively calling
addImage
with a.jpeg
file as opposed to.jpg
does the trick as well.