Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

doctrack

dm-kamaev13ISC1.0.0TypeScript support: included

Library for injecting tracking (spy) pixel url into Office Documents (Office Open XML)

doctrack, tracking pixel, tracking pixel url, spy url, office open xml, docx, docm, dotm, dotx, xlsx, xlsm, xltm, xltx

readme

Doctrack

Actions Status Coverage

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();