doctrack
v1.0.0
Published
Library for injecting tracking (spy) pixel url into Office Documents (Office Open XML)
Downloads
15
Maintainers
Readme
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';
// xlsx - new Xlsx, docm - new Docm and etc
const doctrack = new DocTrack(new Docx(inputFilePath), trackingPixelUrl);
// Write result document to file
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';
// As file
const doctrack = new DocTrack(new Docx('./input.docx'), trackingPixelUrl);
// As Buffer
const fileBuffer = await fsPromise.readFile('./input.docx');
const doctrack = new DocTrack(new Docx(fileBuffer), trackingPixelUrl);
// As Stream
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:
// Write result document to file
await doctrack.writeResultToFile('./output.docx');
// Write result document to buffer
const buffer = await doctrack.writeResultToBuffer();
// Write result document to stream
const stream = await doctrack.writeResultToStream();