How to use the utils.addStringToBuffer function in utils

To help you get started, we’ve selected a few utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Hopding / pdf-lib / src / core / pdf-objects / PDFRawStream.ts View on Github external
copyBytesInto = (buffer: Uint8Array): Uint8Array => {
    this.validateDictionary();
    let remaining = this.dictionary.copyBytesInto(buffer);
    remaining = addStringToBuffer('\nstream\n', remaining);

    remaining.set(this.content, 0);
    remaining = remaining.subarray(this.content.length);

    remaining = addStringToBuffer('\nendstream', remaining);
    return remaining;
  };
}
github Hopding / pdf-lib / src / core / pdf-structures / PDFObjectStream.ts View on Github external
private copyContentBytesInto = (buffer: Uint8Array): Uint8Array => {
    const remaining = addStringToBuffer(this.leadingIntegerPairsStr(), buffer);
    return this.objects.reduce(
      (remBytes, obj) =>
        addStringToBuffer('\n', obj.pdfObject.copyBytesInto(remBytes)),
      remaining,
    );
  };
github Hopding / pdf-lib / src / core / pdf-operators / text / PDFTextObject.ts View on Github external
copyBytesInto = (buffer: Uint8Array): Uint8Array => {
    let remaining = addStringToBuffer('BT\n', buffer);

    remaining = this.operators
      .filter(Boolean)
      .reduce(
        (remBytes: Uint8Array, op: PDFOperator) => op.copyBytesInto(remBytes),
        remaining,
      );

    remaining = addStringToBuffer('ET\n', remaining);
    return remaining;
  };
}
github Hopding / pdf-lib / src / core / pdf-structures / PDFHeader.ts View on Github external
copyBytesInto = (buffer: Uint8Array): Uint8Array => {
    const remaining = addStringToBuffer(
      `%PDF-${this.major}.${this.minor}\n`,
      buffer,
    );
    remaining.set([charCode('%'), 130, 130, 130, 130, charCode('\n')], 0);
    return remaining.subarray(6);
  };
}
github Hopding / pdf-lib / src / core / pdf-objects / PDFArray.ts View on Github external
this.array.forEach((e, idx) => {
      if (e instanceof PDFIndirectObject) {
        remaining = addStringToBuffer(e.toReference(), remaining);
      } else if (e instanceof PDFObject) {
        remaining = e.copyBytesInto(remaining);
      } else {
        error(`Not a PDFObject: ${e}`);
      }
      remaining = addStringToBuffer(' ', remaining);
    });

utils

Fast, generic JavaScript/node.js utility functions.

MIT
Latest version published 9 years ago

Package Health Score

44 / 100
Full package analysis