Package Exports
- doctrack
- doctrack/dist/src/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (doctrack) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
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();