Doctrack
Library for injecting tracking (spy) pixel url into Office Documents (Office Open XML).
Support formats:
- docx
- docm
- dotm
- dotx
- xlsx
- xlsm
- xltm
- xltx
npm i doctrack -S
Example
import { DocTrack, Docx, Docm, Dotm, Dotx, Xlsx, Xlsm, Xltm, Xltx } from 'doctrack';
const inputFilePath = './input.docx';
const outputFilePath = './output.docx';
const trackingPixelUrl = 'http://localhost:5001/tracking';
const doctrack = new DocTrack(new Docx(inputFilePath), trackingPixelUrl);
await doctrack.writeResultToFile(outputFilePath);
After open result document (output.docx) with office editor will be requested url: http://localhost:5001/tracking
.
Input data
You can pass input file as buffer, stream or file:
import fsPromise from 'node:fs/promises';
const doctrack = new DocTrack(new Docx('./input.docx'), trackingPixelUrl);
const fileBuffer = await fsPromise.readFile('./input.docx');
const doctrack = new DocTrack(new Docx(fileBuffer), trackingPixelUrl);
const fileStream = fs.createReadStream('./input.docx');
const doctrack = new DocTrack(new Docx(fileStream), trackingPixelUrl);
Output data
You get result file as buffer, stream or file:
await doctrack.writeResultToFile('./output.docx');
const buffer = await doctrack.writeResultToBuffer();
const stream = await doctrack.writeResultToStream();