Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to write metadata to the docx file in Node.js?

In Node.js, I'm able to write metadata in pdf file using hummus npm, but I also need to write metadata to docx file.

Please let me know if someone has suggestions for this.

like image 309
wangdev87 Avatar asked Dec 22 '25 00:12

wangdev87


1 Answers

A Docx file comprises of a collection of XML files that are contained inside a ZIP archive. The contents of a new Word document can be viewed by unzipping its contents.

So, to edit write docx file's metadata is to

  1. Unzip the docx file.

you can use unzipper npm to unzip docx file.

  fs.createReadStream('path/to/archive.zip')
    .pipe(unzipper.Extract({ path: 'output/path' }));

2. Once unzip the docx file, you can see app.xml and core.xml files in docProps directory, and update this as you require for the metadata of the docx file.

  1. Zip the entire folder. It's important that the files that make up the docx are not within another folder, i.e. [Content_Types].xml must be in the root of the resulting zipped file. When you open (or extract to the current directory) the zip file, you should have something similar to the following:
./docProps/
./word/
./_rels/
./customXml/
./[Content_Types].xml
like image 110
wangdev87 Avatar answered Dec 23 '25 16:12

wangdev87



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!