@ironsoftware/ironpdf
Version:
IronPDF for Node
112 lines • 5.57 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.stampBarcode = exports.stampImage = exports.stampText = exports.stampHtml = void 0;
const util_1 = require("../util");
const access_1 = require("../../access");
const page_1 = require("../pdfium/page");
const converter_1 = require("./converter");
function createStampStream(client, resolve, reject) {
return client.Chrome_Stamp_ApplyStamp((err, value) => {
if (err) {
reject(`${err.name}/n${err.message}`);
}
else if (value) {
(0, util_1.handleEmptyResultP__Output)(value, reject);
resolve();
}
});
}
function stampHtml(id, html, options) {
return __awaiter(this, void 0, void 0, function* () {
const client = yield access_1.Access.ensureConnection();
const pagesInfo = yield (0, page_1.getPageInfo)(id);
return new Promise((resolve, reject) => {
var _a;
const stream = createStampStream(client, resolve, reject);
const info = (0, converter_1.HtmlStampOptionsToProto)(id, pagesInfo, options === null || options === void 0 ? void 0 : options.password, options === null || options === void 0 ? void 0 : options.htmlStampOptions, options === null || options === void 0 ? void 0 : options.pageSelection);
stream.write({
info: info,
});
(_a = (0, util_1.chunkString)(html)) === null || _a === void 0 ? void 0 : _a.forEach((htmlChunk) => {
stream.write({
stampValue: htmlChunk,
});
});
stream.end();
});
});
}
exports.stampHtml = stampHtml;
function stampText(id, text, options) {
return __awaiter(this, void 0, void 0, function* () {
const client = yield access_1.Access.ensureConnection();
const pagesInfo = yield (0, page_1.getPageInfo)(id);
return new Promise((resolve, reject) => {
var _a;
const stream = createStampStream(client, resolve, reject);
const info = (0, converter_1.TextStampOptionsToProto)(id, pagesInfo, options === null || options === void 0 ? void 0 : options.password, options === null || options === void 0 ? void 0 : options.textStampOptions, options === null || options === void 0 ? void 0 : options.pageSelection);
stream.write({
info: info,
});
(_a = (0, util_1.chunkString)(text)) === null || _a === void 0 ? void 0 : _a.forEach((textChunk) => {
stream.write({
stampValue: textChunk,
});
});
stream.end();
});
});
}
exports.stampText = stampText;
function stampImage(id, imageBuffer, options) {
return __awaiter(this, void 0, void 0, function* () {
const client = yield access_1.Access.ensureConnection();
const pagesInfo = yield (0, page_1.getPageInfo)(id);
return new Promise((resolve, reject) => {
var _a;
const stream = createStampStream(client, resolve, reject);
const info = (0, converter_1.ImageStampOptionsToProto)(id, pagesInfo, options === null || options === void 0 ? void 0 : options.password, options === null || options === void 0 ? void 0 : options.imageStampOptions, options === null || options === void 0 ? void 0 : options.pageSelection);
stream.write({
info: info,
});
(_a = (0, util_1.chunkBuffer)(imageBuffer)) === null || _a === void 0 ? void 0 : _a.forEach((imageChunk) => {
stream.write({
stampImageBytes: imageChunk,
});
});
stream.end();
});
});
}
exports.stampImage = stampImage;
function stampBarcode(id, barcodeValue, options) {
return __awaiter(this, void 0, void 0, function* () {
const client = yield access_1.Access.ensureConnection();
const pagesInfo = yield (0, page_1.getPageInfo)(id);
return new Promise((resolve, reject) => {
var _a;
const stream = createStampStream(client, resolve, reject);
const info = (0, converter_1.BarcodeStampOptionsToProto)(id, pagesInfo, options === null || options === void 0 ? void 0 : options.password, options === null || options === void 0 ? void 0 : options.barcodeStampOptions, options === null || options === void 0 ? void 0 : options.pageSelection);
stream.write({
info: info,
});
(_a = (0, util_1.chunkString)(barcodeValue)) === null || _a === void 0 ? void 0 : _a.forEach((bv) => {
stream.write({
stampValue: bv,
});
});
stream.end();
});
});
}
exports.stampBarcode = stampBarcode;
//# sourceMappingURL=stamp.js.map