first commit
This commit is contained in:
138
node_modules/pdf-lib/es/api/form/PDFButton.d.ts
generated
vendored
Normal file
138
node_modules/pdf-lib/es/api/form/PDFButton.d.ts
generated
vendored
Normal file
@@ -0,0 +1,138 @@
|
||||
import PDFDocument from "../PDFDocument";
|
||||
import PDFPage from "../PDFPage";
|
||||
import PDFFont from "../PDFFont";
|
||||
import PDFImage from "../PDFImage";
|
||||
import { ImageAlignment } from "../image/alignment";
|
||||
import { AppearanceProviderFor } from "./appearances";
|
||||
import PDFField, { FieldAppearanceOptions } from "./PDFField";
|
||||
import { PDFRef, PDFAcroPushButton } from "../../core";
|
||||
/**
|
||||
* Represents a button field of a [[PDFForm]].
|
||||
*
|
||||
* [[PDFButton]] fields are interactive controls that users can click with their
|
||||
* mouse. This type of [[PDFField]] is not stateful. The purpose of a button
|
||||
* is to perform an action when the user clicks on it, such as opening a print
|
||||
* modal or resetting the form. Buttons are typically rectangular in shape and
|
||||
* have a text label describing the action that they perform when clicked.
|
||||
*/
|
||||
export default class PDFButton extends PDFField {
|
||||
/**
|
||||
* > **NOTE:** You probably don't want to call this method directly. Instead,
|
||||
* > consider using the [[PDFForm.getButton]] method, which will create an
|
||||
* > instance of [[PDFButton]] for you.
|
||||
*
|
||||
* Create an instance of [[PDFButton]] from an existing acroPushButton and ref
|
||||
*
|
||||
* @param acroPushButton The underlying `PDFAcroPushButton` for this button.
|
||||
* @param ref The unique reference for this button.
|
||||
* @param doc The document to which this button will belong.
|
||||
*/
|
||||
static of: (acroPushButton: PDFAcroPushButton, ref: PDFRef, doc: PDFDocument) => PDFButton;
|
||||
/** The low-level PDFAcroPushButton wrapped by this button. */
|
||||
readonly acroField: PDFAcroPushButton;
|
||||
private constructor();
|
||||
/**
|
||||
* Display an image inside the bounds of this button's widgets. For example:
|
||||
* ```js
|
||||
* const pngImage = await pdfDoc.embedPng(...)
|
||||
* const button = form.getButton('some.button.field')
|
||||
* button.setImage(pngImage, ImageAlignment.Center)
|
||||
* ```
|
||||
* This will update the appearances streams for each of this button's widgets.
|
||||
* @param image The image that should be displayed.
|
||||
* @param alignment The alignment of the image.
|
||||
*/
|
||||
setImage(image: PDFImage, alignment?: ImageAlignment): void;
|
||||
/**
|
||||
* Set the font size for this field. Larger font sizes will result in larger
|
||||
* text being displayed when PDF readers render this button. Font sizes may
|
||||
* be integer or floating point numbers. Supplying a negative font size will
|
||||
* cause this method to throw an error.
|
||||
*
|
||||
* For example:
|
||||
* ```js
|
||||
* const button = form.getButton('some.button.field')
|
||||
* button.setFontSize(4)
|
||||
* button.setFontSize(15.7)
|
||||
* ```
|
||||
*
|
||||
* > This method depends upon the existence of a default appearance
|
||||
* > (`/DA`) string. If this field does not have a default appearance string,
|
||||
* > or that string does not contain a font size (via the `Tf` operator),
|
||||
* > then this method will throw an error.
|
||||
*
|
||||
* @param fontSize The font size to be used when rendering text in this field.
|
||||
*/
|
||||
setFontSize(fontSize: number): void;
|
||||
/**
|
||||
* Show this button on the specified page with the given text. For example:
|
||||
* ```js
|
||||
* const ubuntuFont = await pdfDoc.embedFont(ubuntuFontBytes)
|
||||
* const page = pdfDoc.addPage()
|
||||
*
|
||||
* const form = pdfDoc.getForm()
|
||||
* const button = form.createButton('some.button.field')
|
||||
*
|
||||
* button.addToPage('Do Stuff', page, {
|
||||
* x: 50,
|
||||
* y: 75,
|
||||
* width: 200,
|
||||
* height: 100,
|
||||
* textColor: rgb(1, 0, 0),
|
||||
* backgroundColor: rgb(0, 1, 0),
|
||||
* borderColor: rgb(0, 0, 1),
|
||||
* borderWidth: 2,
|
||||
* rotate: degrees(90),
|
||||
* font: ubuntuFont,
|
||||
* })
|
||||
* ```
|
||||
* This will create a new widget for this button field.
|
||||
* @param text The text to be displayed for this button widget.
|
||||
* @param page The page to which this button widget should be added.
|
||||
* @param options The options to be used when adding this button widget.
|
||||
*/
|
||||
addToPage(text: string, page: PDFPage, options?: FieldAppearanceOptions): void;
|
||||
/**
|
||||
* Returns `true` if this button has been marked as dirty, or if any of this
|
||||
* button's widgets do not have an appearance stream. For example:
|
||||
* ```js
|
||||
* const button = form.getButton('some.button.field')
|
||||
* if (button.needsAppearancesUpdate()) console.log('Needs update')
|
||||
* ```
|
||||
* @returns Whether or not this button needs an appearance update.
|
||||
*/
|
||||
needsAppearancesUpdate(): boolean;
|
||||
/**
|
||||
* Update the appearance streams for each of this button's widgets using
|
||||
* the default appearance provider for buttons. For example:
|
||||
* ```js
|
||||
* const helvetica = await pdfDoc.embedFont(StandardFonts.Helvetica)
|
||||
* const button = form.getButton('some.button.field')
|
||||
* button.defaultUpdateAppearances(helvetica)
|
||||
* ```
|
||||
* @param font The font to be used for creating the appearance streams.
|
||||
*/
|
||||
defaultUpdateAppearances(font: PDFFont): void;
|
||||
/**
|
||||
* Update the appearance streams for each of this button's widgets using
|
||||
* the given appearance provider. If no `provider` is passed, the default
|
||||
* appearance provider for buttons will be used. For example:
|
||||
* ```js
|
||||
* const helvetica = await pdfDoc.embedFont(StandardFonts.Helvetica)
|
||||
* const button = form.getButton('some.button.field')
|
||||
* button.updateAppearances(helvetica, (field, widget, font) => {
|
||||
* ...
|
||||
* return {
|
||||
* normal: drawButton(...),
|
||||
* down: drawButton(...),
|
||||
* }
|
||||
* })
|
||||
* ```
|
||||
* @param font The font to be used for creating the appearance streams.
|
||||
* @param provider Optionally, the appearance provider to be used for
|
||||
* generating the contents of the appearance streams.
|
||||
*/
|
||||
updateAppearances(font: PDFFont, provider?: AppearanceProviderFor<PDFButton>): void;
|
||||
private updateWidgetAppearance;
|
||||
}
|
||||
//# sourceMappingURL=PDFButton.d.ts.map
|
||||
1
node_modules/pdf-lib/es/api/form/PDFButton.d.ts.map
generated
vendored
Normal file
1
node_modules/pdf-lib/es/api/form/PDFButton.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"PDFButton.d.ts","sourceRoot":"","sources":["../../../src/api/form/PDFButton.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,uBAA4B;AAC9C,OAAO,OAAO,mBAAwB;AACtC,OAAO,OAAO,mBAAwB;AACtC,OAAO,QAAQ,oBAAyB;AACxC,OAAO,EAAE,cAAc,EAAE,2BAAgC;AACzD,OAAO,EACL,qBAAqB,EAGtB,sBAAiC;AAClC,OAAO,QAAQ,EAAE,EACf,sBAAsB,EAEvB,mBAA8B;AAI/B,OAAO,EACL,MAAM,EAEN,iBAAiB,EAElB,mBAAiB;AAGlB;;;;;;;;GAQG;AACH,MAAM,CAAC,OAAO,OAAO,SAAU,SAAQ,QAAQ;IAC7C;;;;;;;;;;OAUG;IACH,MAAM,CAAC,EAAE,mBACS,iBAAiB,OAC5B,MAAM,OACN,WAAW,eAC2B;IAE7C,8DAA8D;IAC9D,QAAQ,CAAC,SAAS,EAAE,iBAAiB,CAAC;IAEtC,OAAO;IAcP;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,KAAK,EAAE,QAAQ,EAAE,SAAS,iBAAwB;IAe3D;;;;;;;;;;;;;;;;;;;OAmBG;IACH,WAAW,CAAC,QAAQ,EAAE,MAAM;IAM5B;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACH,SAAS,CAEP,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,OAAO,EACb,OAAO,CAAC,EAAE,sBAAsB;IAkClC;;;;;;;;OAQG;IACH,sBAAsB,IAAI,OAAO;IAcjC;;;;;;;;;OASG;IACH,wBAAwB,CAAC,IAAI,EAAE,OAAO;IAKtC;;;;;;;;;;;;;;;;;;OAkBG;IACH,iBAAiB,CACf,IAAI,EAAE,OAAO,EACb,QAAQ,CAAC,EAAE,qBAAqB,CAAC,SAAS,CAAC;IAY7C,OAAO,CAAC,sBAAsB;CAS/B"}
|
||||
218
node_modules/pdf-lib/es/api/form/PDFButton.js
generated
vendored
Normal file
218
node_modules/pdf-lib/es/api/form/PDFButton.js
generated
vendored
Normal file
@@ -0,0 +1,218 @@
|
||||
import { __extends } from "tslib";
|
||||
import PDFPage from "../PDFPage";
|
||||
import PDFFont from "../PDFFont";
|
||||
import { ImageAlignment } from "../image/alignment";
|
||||
import { normalizeAppearance, defaultButtonAppearanceProvider, } from "./appearances";
|
||||
import PDFField, { assertFieldAppearanceOptions, } from "./PDFField";
|
||||
import { rgb } from "../colors";
|
||||
import { degrees } from "../rotations";
|
||||
import { PDFStream, PDFAcroPushButton, } from "../../core";
|
||||
import { assertIs, assertOrUndefined, assertPositive } from "../../utils";
|
||||
/**
|
||||
* Represents a button field of a [[PDFForm]].
|
||||
*
|
||||
* [[PDFButton]] fields are interactive controls that users can click with their
|
||||
* mouse. This type of [[PDFField]] is not stateful. The purpose of a button
|
||||
* is to perform an action when the user clicks on it, such as opening a print
|
||||
* modal or resetting the form. Buttons are typically rectangular in shape and
|
||||
* have a text label describing the action that they perform when clicked.
|
||||
*/
|
||||
var PDFButton = /** @class */ (function (_super) {
|
||||
__extends(PDFButton, _super);
|
||||
function PDFButton(acroPushButton, ref, doc) {
|
||||
var _this = _super.call(this, acroPushButton, ref, doc) || this;
|
||||
assertIs(acroPushButton, 'acroButton', [
|
||||
[PDFAcroPushButton, 'PDFAcroPushButton'],
|
||||
]);
|
||||
_this.acroField = acroPushButton;
|
||||
return _this;
|
||||
}
|
||||
/**
|
||||
* Display an image inside the bounds of this button's widgets. For example:
|
||||
* ```js
|
||||
* const pngImage = await pdfDoc.embedPng(...)
|
||||
* const button = form.getButton('some.button.field')
|
||||
* button.setImage(pngImage, ImageAlignment.Center)
|
||||
* ```
|
||||
* This will update the appearances streams for each of this button's widgets.
|
||||
* @param image The image that should be displayed.
|
||||
* @param alignment The alignment of the image.
|
||||
*/
|
||||
PDFButton.prototype.setImage = function (image, alignment) {
|
||||
if (alignment === void 0) { alignment = ImageAlignment.Center; }
|
||||
var widgets = this.acroField.getWidgets();
|
||||
for (var idx = 0, len = widgets.length; idx < len; idx++) {
|
||||
var widget = widgets[idx];
|
||||
var streamRef = this.createImageAppearanceStream(widget, image, alignment);
|
||||
this.updateWidgetAppearances(widget, { normal: streamRef });
|
||||
}
|
||||
this.markAsClean();
|
||||
};
|
||||
/**
|
||||
* Set the font size for this field. Larger font sizes will result in larger
|
||||
* text being displayed when PDF readers render this button. Font sizes may
|
||||
* be integer or floating point numbers. Supplying a negative font size will
|
||||
* cause this method to throw an error.
|
||||
*
|
||||
* For example:
|
||||
* ```js
|
||||
* const button = form.getButton('some.button.field')
|
||||
* button.setFontSize(4)
|
||||
* button.setFontSize(15.7)
|
||||
* ```
|
||||
*
|
||||
* > This method depends upon the existence of a default appearance
|
||||
* > (`/DA`) string. If this field does not have a default appearance string,
|
||||
* > or that string does not contain a font size (via the `Tf` operator),
|
||||
* > then this method will throw an error.
|
||||
*
|
||||
* @param fontSize The font size to be used when rendering text in this field.
|
||||
*/
|
||||
PDFButton.prototype.setFontSize = function (fontSize) {
|
||||
assertPositive(fontSize, 'fontSize');
|
||||
this.acroField.setFontSize(fontSize);
|
||||
this.markAsDirty();
|
||||
};
|
||||
/**
|
||||
* Show this button on the specified page with the given text. For example:
|
||||
* ```js
|
||||
* const ubuntuFont = await pdfDoc.embedFont(ubuntuFontBytes)
|
||||
* const page = pdfDoc.addPage()
|
||||
*
|
||||
* const form = pdfDoc.getForm()
|
||||
* const button = form.createButton('some.button.field')
|
||||
*
|
||||
* button.addToPage('Do Stuff', page, {
|
||||
* x: 50,
|
||||
* y: 75,
|
||||
* width: 200,
|
||||
* height: 100,
|
||||
* textColor: rgb(1, 0, 0),
|
||||
* backgroundColor: rgb(0, 1, 0),
|
||||
* borderColor: rgb(0, 0, 1),
|
||||
* borderWidth: 2,
|
||||
* rotate: degrees(90),
|
||||
* font: ubuntuFont,
|
||||
* })
|
||||
* ```
|
||||
* This will create a new widget for this button field.
|
||||
* @param text The text to be displayed for this button widget.
|
||||
* @param page The page to which this button widget should be added.
|
||||
* @param options The options to be used when adding this button widget.
|
||||
*/
|
||||
PDFButton.prototype.addToPage = function (
|
||||
// TODO: This needs to be optional, e.g. for image buttons
|
||||
text, page, options) {
|
||||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
||||
assertOrUndefined(text, 'text', ['string']);
|
||||
assertOrUndefined(page, 'page', [[PDFPage, 'PDFPage']]);
|
||||
assertFieldAppearanceOptions(options);
|
||||
// Create a widget for this button
|
||||
var widget = this.createWidget({
|
||||
x: ((_a = options === null || options === void 0 ? void 0 : options.x) !== null && _a !== void 0 ? _a : 0) - ((_b = options === null || options === void 0 ? void 0 : options.borderWidth) !== null && _b !== void 0 ? _b : 0) / 2,
|
||||
y: ((_c = options === null || options === void 0 ? void 0 : options.y) !== null && _c !== void 0 ? _c : 0) - ((_d = options === null || options === void 0 ? void 0 : options.borderWidth) !== null && _d !== void 0 ? _d : 0) / 2,
|
||||
width: (_e = options === null || options === void 0 ? void 0 : options.width) !== null && _e !== void 0 ? _e : 100,
|
||||
height: (_f = options === null || options === void 0 ? void 0 : options.height) !== null && _f !== void 0 ? _f : 50,
|
||||
textColor: (_g = options === null || options === void 0 ? void 0 : options.textColor) !== null && _g !== void 0 ? _g : rgb(0, 0, 0),
|
||||
backgroundColor: (_h = options === null || options === void 0 ? void 0 : options.backgroundColor) !== null && _h !== void 0 ? _h : rgb(0.75, 0.75, 0.75),
|
||||
borderColor: options === null || options === void 0 ? void 0 : options.borderColor,
|
||||
borderWidth: (_j = options === null || options === void 0 ? void 0 : options.borderWidth) !== null && _j !== void 0 ? _j : 0,
|
||||
rotate: (_k = options === null || options === void 0 ? void 0 : options.rotate) !== null && _k !== void 0 ? _k : degrees(0),
|
||||
caption: text,
|
||||
hidden: options === null || options === void 0 ? void 0 : options.hidden,
|
||||
page: page.ref,
|
||||
});
|
||||
var widgetRef = this.doc.context.register(widget.dict);
|
||||
// Add widget to this field
|
||||
this.acroField.addWidget(widgetRef);
|
||||
// Set appearance streams for widget
|
||||
var font = (_l = options === null || options === void 0 ? void 0 : options.font) !== null && _l !== void 0 ? _l : this.doc.getForm().getDefaultFont();
|
||||
this.updateWidgetAppearance(widget, font);
|
||||
// Add widget to the given page
|
||||
page.node.addAnnot(widgetRef);
|
||||
};
|
||||
/**
|
||||
* Returns `true` if this button has been marked as dirty, or if any of this
|
||||
* button's widgets do not have an appearance stream. For example:
|
||||
* ```js
|
||||
* const button = form.getButton('some.button.field')
|
||||
* if (button.needsAppearancesUpdate()) console.log('Needs update')
|
||||
* ```
|
||||
* @returns Whether or not this button needs an appearance update.
|
||||
*/
|
||||
PDFButton.prototype.needsAppearancesUpdate = function () {
|
||||
var _a;
|
||||
if (this.isDirty())
|
||||
return true;
|
||||
var widgets = this.acroField.getWidgets();
|
||||
for (var idx = 0, len = widgets.length; idx < len; idx++) {
|
||||
var widget = widgets[idx];
|
||||
var hasAppearances = ((_a = widget.getAppearances()) === null || _a === void 0 ? void 0 : _a.normal) instanceof PDFStream;
|
||||
if (!hasAppearances)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
/**
|
||||
* Update the appearance streams for each of this button's widgets using
|
||||
* the default appearance provider for buttons. For example:
|
||||
* ```js
|
||||
* const helvetica = await pdfDoc.embedFont(StandardFonts.Helvetica)
|
||||
* const button = form.getButton('some.button.field')
|
||||
* button.defaultUpdateAppearances(helvetica)
|
||||
* ```
|
||||
* @param font The font to be used for creating the appearance streams.
|
||||
*/
|
||||
PDFButton.prototype.defaultUpdateAppearances = function (font) {
|
||||
assertIs(font, 'font', [[PDFFont, 'PDFFont']]);
|
||||
this.updateAppearances(font);
|
||||
};
|
||||
/**
|
||||
* Update the appearance streams for each of this button's widgets using
|
||||
* the given appearance provider. If no `provider` is passed, the default
|
||||
* appearance provider for buttons will be used. For example:
|
||||
* ```js
|
||||
* const helvetica = await pdfDoc.embedFont(StandardFonts.Helvetica)
|
||||
* const button = form.getButton('some.button.field')
|
||||
* button.updateAppearances(helvetica, (field, widget, font) => {
|
||||
* ...
|
||||
* return {
|
||||
* normal: drawButton(...),
|
||||
* down: drawButton(...),
|
||||
* }
|
||||
* })
|
||||
* ```
|
||||
* @param font The font to be used for creating the appearance streams.
|
||||
* @param provider Optionally, the appearance provider to be used for
|
||||
* generating the contents of the appearance streams.
|
||||
*/
|
||||
PDFButton.prototype.updateAppearances = function (font, provider) {
|
||||
assertIs(font, 'font', [[PDFFont, 'PDFFont']]);
|
||||
assertOrUndefined(provider, 'provider', [Function]);
|
||||
var widgets = this.acroField.getWidgets();
|
||||
for (var idx = 0, len = widgets.length; idx < len; idx++) {
|
||||
var widget = widgets[idx];
|
||||
this.updateWidgetAppearance(widget, font, provider);
|
||||
}
|
||||
};
|
||||
PDFButton.prototype.updateWidgetAppearance = function (widget, font, provider) {
|
||||
var apProvider = provider !== null && provider !== void 0 ? provider : defaultButtonAppearanceProvider;
|
||||
var appearances = normalizeAppearance(apProvider(this, widget, font));
|
||||
this.updateWidgetAppearanceWithFont(widget, font, appearances);
|
||||
};
|
||||
/**
|
||||
* > **NOTE:** You probably don't want to call this method directly. Instead,
|
||||
* > consider using the [[PDFForm.getButton]] method, which will create an
|
||||
* > instance of [[PDFButton]] for you.
|
||||
*
|
||||
* Create an instance of [[PDFButton]] from an existing acroPushButton and ref
|
||||
*
|
||||
* @param acroPushButton The underlying `PDFAcroPushButton` for this button.
|
||||
* @param ref The unique reference for this button.
|
||||
* @param doc The document to which this button will belong.
|
||||
*/
|
||||
PDFButton.of = function (acroPushButton, ref, doc) { return new PDFButton(acroPushButton, ref, doc); };
|
||||
return PDFButton;
|
||||
}(PDFField));
|
||||
export default PDFButton;
|
||||
//# sourceMappingURL=PDFButton.js.map
|
||||
1
node_modules/pdf-lib/es/api/form/PDFButton.js.map
generated
vendored
Normal file
1
node_modules/pdf-lib/es/api/form/PDFButton.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"PDFButton.js","sourceRoot":"","sources":["../../../src/api/form/PDFButton.ts"],"names":[],"mappings":";AACA,OAAO,OAAO,mBAAwB;AACtC,OAAO,OAAO,mBAAwB;AAEtC,OAAO,EAAE,cAAc,EAAE,2BAAgC;AACzD,OAAO,EAEL,mBAAmB,EACnB,+BAA+B,GAChC,sBAAiC;AAClC,OAAO,QAAQ,EAAE,EAEf,4BAA4B,GAC7B,mBAA8B;AAC/B,OAAO,EAAE,GAAG,EAAE,kBAAuB;AACrC,OAAO,EAAE,OAAO,EAAE,qBAA0B;AAE5C,OAAO,EAEL,SAAS,EACT,iBAAiB,GAElB,mBAAiB;AAClB,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,cAAc,EAAE,oBAAkB;AAExE;;;;;;;;GAQG;AACH;IAAuC,6BAAQ;IAqB7C,mBACE,cAAiC,EACjC,GAAW,EACX,GAAgB;QAHlB,YAKE,kBAAM,cAAc,EAAE,GAAG,EAAE,GAAG,CAAC,SAOhC;QALC,QAAQ,CAAC,cAAc,EAAE,YAAY,EAAE;YACrC,CAAC,iBAAiB,EAAE,mBAAmB,CAAC;SACzC,CAAC,CAAC;QAEH,KAAI,CAAC,SAAS,GAAG,cAAc,CAAC;;IAClC,CAAC;IAED;;;;;;;;;;OAUG;IACH,4BAAQ,GAAR,UAAS,KAAe,EAAE,SAAiC;QAAjC,0BAAA,EAAA,YAAY,cAAc,CAAC,MAAM;QACzD,IAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE,CAAC;QAC5C,KAAK,IAAI,GAAG,GAAG,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,EAAE,GAAG,GAAG,GAAG,EAAE,GAAG,EAAE,EAAE;YACxD,IAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;YAC5B,IAAM,SAAS,GAAG,IAAI,CAAC,2BAA2B,CAChD,MAAM,EACN,KAAK,EACL,SAAS,CACV,CAAC;YACF,IAAI,CAAC,uBAAuB,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC;SAC7D;QAED,IAAI,CAAC,WAAW,EAAE,CAAC;IACrB,CAAC;IAED;;;;;;;;;;;;;;;;;;;OAmBG;IACH,+BAAW,GAAX,UAAY,QAAgB;QAC1B,cAAc,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;QACrC,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;QACrC,IAAI,CAAC,WAAW,EAAE,CAAC;IACrB,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACH,6BAAS,GAAT;IACE,0DAA0D;IAC1D,IAAY,EACZ,IAAa,EACb,OAAgC;;QAEhC,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;QAC5C,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;QACxD,4BAA4B,CAAC,OAAO,CAAC,CAAC;QAEtC,kCAAkC;QAClC,IAAM,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC;YAC/B,CAAC,EAAE,OAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,CAAC,mCAAI,CAAC,CAAC,GAAG,OAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,mCAAI,CAAC,CAAC,GAAG,CAAC;YACtD,CAAC,EAAE,OAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,CAAC,mCAAI,CAAC,CAAC,GAAG,OAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,mCAAI,CAAC,CAAC,GAAG,CAAC;YACtD,KAAK,QAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,KAAK,mCAAI,GAAG;YAC5B,MAAM,QAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM,mCAAI,EAAE;YAC7B,SAAS,QAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,SAAS,mCAAI,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;YAC7C,eAAe,QAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,eAAe,mCAAI,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC;YAClE,WAAW,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW;YACjC,WAAW,QAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,mCAAI,CAAC;YACtC,MAAM,QAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM,mCAAI,OAAO,CAAC,CAAC,CAAC;YACrC,OAAO,EAAE,IAAI;YACb,MAAM,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM;YACvB,IAAI,EAAE,IAAI,CAAC,GAAG;SACf,CAAC,CAAC;QACH,IAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAEzD,2BAA2B;QAC3B,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;QAEpC,oCAAoC;QACpC,IAAM,IAAI,SAAG,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,mCAAI,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,cAAc,EAAE,CAAC;QAClE,IAAI,CAAC,sBAAsB,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAE1C,+BAA+B;QAC/B,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;IAChC,CAAC;IAED;;;;;;;;OAQG;IACH,0CAAsB,GAAtB;;QACE,IAAI,IAAI,CAAC,OAAO,EAAE;YAAE,OAAO,IAAI,CAAC;QAEhC,IAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE,CAAC;QAC5C,KAAK,IAAI,GAAG,GAAG,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,EAAE,GAAG,GAAG,GAAG,EAAE,GAAG,EAAE,EAAE;YACxD,IAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;YAC5B,IAAM,cAAc,GAClB,OAAA,MAAM,CAAC,cAAc,EAAE,0CAAE,MAAM,aAAY,SAAS,CAAC;YACvD,IAAI,CAAC,cAAc;gBAAE,OAAO,IAAI,CAAC;SAClC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;;;;;;;;OASG;IACH,4CAAwB,GAAxB,UAAyB,IAAa;QACpC,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;QAC/C,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;IAED;;;;;;;;;;;;;;;;;;OAkBG;IACH,qCAAiB,GAAjB,UACE,IAAa,EACb,QAA2C;QAE3C,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;QAC/C,iBAAiB,CAAC,QAAQ,EAAE,UAAU,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;QAEpD,IAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE,CAAC;QAC5C,KAAK,IAAI,GAAG,GAAG,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,EAAE,GAAG,GAAG,GAAG,EAAE,GAAG,EAAE,EAAE;YACxD,IAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;YAC5B,IAAI,CAAC,sBAAsB,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;SACrD;IACH,CAAC;IAEO,0CAAsB,GAA9B,UACE,MAA2B,EAC3B,IAAa,EACb,QAA2C;QAE3C,IAAM,UAAU,GAAG,QAAQ,aAAR,QAAQ,cAAR,QAAQ,GAAI,+BAA+B,CAAC;QAC/D,IAAM,WAAW,GAAG,mBAAmB,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;QACxE,IAAI,CAAC,8BAA8B,CAAC,MAAM,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC;IACjE,CAAC;IAtOD;;;;;;;;;;OAUG;IACI,YAAE,GAAG,UACV,cAAiC,EACjC,GAAW,EACX,GAAgB,IACb,OAAA,IAAI,SAAS,CAAC,cAAc,EAAE,GAAG,EAAE,GAAG,CAAC,EAAvC,CAAuC,CAAC;IAwN/C,gBAAC;CAAA,AAxOD,CAAuC,QAAQ,GAwO9C;eAxOoB,SAAS"}
|
||||
143
node_modules/pdf-lib/es/api/form/PDFCheckBox.d.ts
generated
vendored
Normal file
143
node_modules/pdf-lib/es/api/form/PDFCheckBox.d.ts
generated
vendored
Normal file
@@ -0,0 +1,143 @@
|
||||
import PDFDocument from "../PDFDocument";
|
||||
import PDFPage from "../PDFPage";
|
||||
import { AppearanceProviderFor } from "./appearances";
|
||||
import PDFField, { FieldAppearanceOptions } from "./PDFField";
|
||||
import { PDFRef, PDFAcroCheckBox } from "../../core";
|
||||
/**
|
||||
* Represents a check box field of a [[PDFForm]].
|
||||
*
|
||||
* [[PDFCheckBox]] fields are interactive boxes that users can click with their
|
||||
* mouse. This type of [[PDFField]] has two states: `on` and `off`. The purpose
|
||||
* of a check box is to enable users to select from one or more options, where
|
||||
* each option is represented by a single check box. Check boxes are typically
|
||||
* square in shape and display a check mark when they are in the `on` state.
|
||||
*/
|
||||
export default class PDFCheckBox extends PDFField {
|
||||
/**
|
||||
* > **NOTE:** You probably don't want to call this method directly. Instead,
|
||||
* > consider using the [[PDFForm.getCheckBox]] method, which will create an
|
||||
* > instance of [[PDFCheckBox]] for you.
|
||||
*
|
||||
* Create an instance of [[PDFCheckBox]] from an existing acroCheckBox and ref
|
||||
*
|
||||
* @param acroCheckBox The underlying `PDFAcroCheckBox` for this check box.
|
||||
* @param ref The unique reference for this check box.
|
||||
* @param doc The document to which this check box will belong.
|
||||
*/
|
||||
static of: (acroCheckBox: PDFAcroCheckBox, ref: PDFRef, doc: PDFDocument) => PDFCheckBox;
|
||||
/** The low-level PDFAcroCheckBox wrapped by this check box. */
|
||||
readonly acroField: PDFAcroCheckBox;
|
||||
private constructor();
|
||||
/**
|
||||
* Mark this check box. This operation is analogous to a human user clicking
|
||||
* a check box to fill it in a PDF reader. This method will update the
|
||||
* underlying state of the check box field to indicate it has been selected.
|
||||
* PDF libraries and readers will be able to extract this value from the
|
||||
* saved document and determine that it was selected.
|
||||
*
|
||||
* For example:
|
||||
* ```js
|
||||
* const checkBox = form.getCheckBox('some.checkBox.field')
|
||||
* checkBox.check()
|
||||
* ```
|
||||
*
|
||||
* This method will mark this check box as dirty, causing its appearance
|
||||
* streams to be updated when either [[PDFDocument.save]] or
|
||||
* [[PDFForm.updateFieldAppearances]] is called. The updated appearance
|
||||
* streams will display a check mark inside the widgets of this check box
|
||||
* field.
|
||||
*/
|
||||
check(): void;
|
||||
/**
|
||||
* Clears this check box. This operation is analogous to a human user clicking
|
||||
* a check box to unmark it in a PDF reader. This method will update the
|
||||
* underlying state of the check box field to indicate it has been deselected.
|
||||
* PDF libraries and readers will be able to extract this value from the
|
||||
* saved document and determine that it was not selected.
|
||||
*
|
||||
* For example:
|
||||
* ```js
|
||||
* const checkBox = form.getCheckBox('some.checkBox.field')
|
||||
* checkBox.uncheck()
|
||||
* ```
|
||||
*
|
||||
* This method will mark this check box as dirty. See [[PDFCheckBox.check]]
|
||||
* for more details about what this means.
|
||||
*/
|
||||
uncheck(): void;
|
||||
/**
|
||||
* Returns `true` if this check box is selected (either by a human user via
|
||||
* a PDF reader, or else programmatically via software). For example:
|
||||
* ```js
|
||||
* const checkBox = form.getCheckBox('some.checkBox.field')
|
||||
* if (checkBox.isChecked()) console.log('check box is selected')
|
||||
* ```
|
||||
* @returns Whether or not this check box is selected.
|
||||
*/
|
||||
isChecked(): boolean;
|
||||
/**
|
||||
* Show this check box on the specified page. For example:
|
||||
* ```js
|
||||
* const helvetica = await pdfDoc.embedFont(StandardFonts.Helvetica)
|
||||
* const page = pdfDoc.addPage()
|
||||
*
|
||||
* const form = pdfDoc.getForm()
|
||||
* const checkBox = form.createCheckBox('some.checkBox.field')
|
||||
*
|
||||
* checkBox.addToPage(page, {
|
||||
* x: 50,
|
||||
* y: 75,
|
||||
* width: 25,
|
||||
* height: 25,
|
||||
* textColor: rgb(1, 0, 0),
|
||||
* backgroundColor: rgb(0, 1, 0),
|
||||
* borderColor: rgb(0, 0, 1),
|
||||
* borderWidth: 2,
|
||||
* rotate: degrees(90),
|
||||
* })
|
||||
* ```
|
||||
* This will create a new widget for this check box field.
|
||||
* @param page The page to which this check box widget should be added.
|
||||
* @param options The options to be used when adding this check box widget.
|
||||
*/
|
||||
addToPage(page: PDFPage, options?: FieldAppearanceOptions): void;
|
||||
/**
|
||||
* Returns `true` if any of this check box's widgets do not have an
|
||||
* appearance stream for its current state. For example:
|
||||
* ```js
|
||||
* const checkBox = form.getCheckBox('some.checkBox.field')
|
||||
* if (checkBox.needsAppearancesUpdate()) console.log('Needs update')
|
||||
* ```
|
||||
* @returns Whether or not this check box needs an appearance update.
|
||||
*/
|
||||
needsAppearancesUpdate(): boolean;
|
||||
/**
|
||||
* Update the appearance streams for each of this check box's widgets using
|
||||
* the default appearance provider for check boxes. For example:
|
||||
* ```js
|
||||
* const checkBox = form.getCheckBox('some.checkBox.field')
|
||||
* checkBox.defaultUpdateAppearances()
|
||||
* ```
|
||||
*/
|
||||
defaultUpdateAppearances(): void;
|
||||
/**
|
||||
* Update the appearance streams for each of this check box's widgets using
|
||||
* the given appearance provider. If no `provider` is passed, the default
|
||||
* appearance provider for check boxs will be used. For example:
|
||||
* ```js
|
||||
* const checkBox = form.getCheckBox('some.checkBox.field')
|
||||
* checkBox.updateAppearances((field, widget) => {
|
||||
* ...
|
||||
* return {
|
||||
* normal: { on: drawCheckBox(...), off: drawCheckBox(...) },
|
||||
* down: { on: drawCheckBox(...), off: drawCheckBox(...) },
|
||||
* }
|
||||
* })
|
||||
* ```
|
||||
* @param provider Optionally, the appearance provider to be used for
|
||||
* generating the contents of the appearance streams.
|
||||
*/
|
||||
updateAppearances(provider?: AppearanceProviderFor<PDFCheckBox>): void;
|
||||
private updateWidgetAppearance;
|
||||
}
|
||||
//# sourceMappingURL=PDFCheckBox.d.ts.map
|
||||
1
node_modules/pdf-lib/es/api/form/PDFCheckBox.d.ts.map
generated
vendored
Normal file
1
node_modules/pdf-lib/es/api/form/PDFCheckBox.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"PDFCheckBox.d.ts","sourceRoot":"","sources":["../../../src/api/form/PDFCheckBox.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,uBAA4B;AAC9C,OAAO,OAAO,mBAAwB;AACtC,OAAO,EACL,qBAAqB,EAGtB,sBAAiC;AAGlC,OAAO,QAAQ,EAAE,EACf,sBAAsB,EAEvB,mBAA8B;AAE/B,OAAO,EAEL,MAAM,EAEN,eAAe,EAEhB,mBAAiB;AAGlB;;;;;;;;GAQG;AACH,MAAM,CAAC,OAAO,OAAO,WAAY,SAAQ,QAAQ;IAC/C;;;;;;;;;;OAUG;IACH,MAAM,CAAC,EAAE,iBAAkB,eAAe,OAAO,MAAM,OAAO,WAAW,iBAC/B;IAE1C,+DAA+D;IAC/D,QAAQ,CAAC,SAAS,EAAE,eAAe,CAAC;IAEpC,OAAO;IAcP;;;;;;;;;;;;;;;;;;OAkBG;IACH,KAAK;IAML;;;;;;;;;;;;;;;OAeG;IACH,OAAO;IAKP;;;;;;;;OAQG;IACH,SAAS,IAAI,OAAO;IAKpB;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,SAAS,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,sBAAsB;IAsCzD;;;;;;;;OAQG;IACH,sBAAsB,IAAI,OAAO;IAcjC;;;;;;;OAOG;IACH,wBAAwB;IAIxB;;;;;;;;;;;;;;;;OAgBG;IACH,iBAAiB,CAAC,QAAQ,CAAC,EAAE,qBAAqB,CAAC,WAAW,CAAC;IAa/D,OAAO,CAAC,sBAAsB;CAS/B"}
|
||||
234
node_modules/pdf-lib/es/api/form/PDFCheckBox.js
generated
vendored
Normal file
234
node_modules/pdf-lib/es/api/form/PDFCheckBox.js
generated
vendored
Normal file
@@ -0,0 +1,234 @@
|
||||
import { __extends } from "tslib";
|
||||
import PDFPage from "../PDFPage";
|
||||
import { normalizeAppearance, defaultCheckBoxAppearanceProvider, } from "./appearances";
|
||||
import { rgb } from "../colors";
|
||||
import { degrees } from "../rotations";
|
||||
import PDFField, { assertFieldAppearanceOptions, } from "./PDFField";
|
||||
import { PDFName, PDFDict, PDFAcroCheckBox, } from "../../core";
|
||||
import { assertIs, assertOrUndefined } from "../../utils";
|
||||
/**
|
||||
* Represents a check box field of a [[PDFForm]].
|
||||
*
|
||||
* [[PDFCheckBox]] fields are interactive boxes that users can click with their
|
||||
* mouse. This type of [[PDFField]] has two states: `on` and `off`. The purpose
|
||||
* of a check box is to enable users to select from one or more options, where
|
||||
* each option is represented by a single check box. Check boxes are typically
|
||||
* square in shape and display a check mark when they are in the `on` state.
|
||||
*/
|
||||
var PDFCheckBox = /** @class */ (function (_super) {
|
||||
__extends(PDFCheckBox, _super);
|
||||
function PDFCheckBox(acroCheckBox, ref, doc) {
|
||||
var _this = _super.call(this, acroCheckBox, ref, doc) || this;
|
||||
assertIs(acroCheckBox, 'acroCheckBox', [
|
||||
[PDFAcroCheckBox, 'PDFAcroCheckBox'],
|
||||
]);
|
||||
_this.acroField = acroCheckBox;
|
||||
return _this;
|
||||
}
|
||||
/**
|
||||
* Mark this check box. This operation is analogous to a human user clicking
|
||||
* a check box to fill it in a PDF reader. This method will update the
|
||||
* underlying state of the check box field to indicate it has been selected.
|
||||
* PDF libraries and readers will be able to extract this value from the
|
||||
* saved document and determine that it was selected.
|
||||
*
|
||||
* For example:
|
||||
* ```js
|
||||
* const checkBox = form.getCheckBox('some.checkBox.field')
|
||||
* checkBox.check()
|
||||
* ```
|
||||
*
|
||||
* This method will mark this check box as dirty, causing its appearance
|
||||
* streams to be updated when either [[PDFDocument.save]] or
|
||||
* [[PDFForm.updateFieldAppearances]] is called. The updated appearance
|
||||
* streams will display a check mark inside the widgets of this check box
|
||||
* field.
|
||||
*/
|
||||
PDFCheckBox.prototype.check = function () {
|
||||
var _a;
|
||||
var onValue = (_a = this.acroField.getOnValue()) !== null && _a !== void 0 ? _a : PDFName.of('Yes');
|
||||
this.markAsDirty();
|
||||
this.acroField.setValue(onValue);
|
||||
};
|
||||
/**
|
||||
* Clears this check box. This operation is analogous to a human user clicking
|
||||
* a check box to unmark it in a PDF reader. This method will update the
|
||||
* underlying state of the check box field to indicate it has been deselected.
|
||||
* PDF libraries and readers will be able to extract this value from the
|
||||
* saved document and determine that it was not selected.
|
||||
*
|
||||
* For example:
|
||||
* ```js
|
||||
* const checkBox = form.getCheckBox('some.checkBox.field')
|
||||
* checkBox.uncheck()
|
||||
* ```
|
||||
*
|
||||
* This method will mark this check box as dirty. See [[PDFCheckBox.check]]
|
||||
* for more details about what this means.
|
||||
*/
|
||||
PDFCheckBox.prototype.uncheck = function () {
|
||||
this.markAsDirty();
|
||||
this.acroField.setValue(PDFName.of('Off'));
|
||||
};
|
||||
/**
|
||||
* Returns `true` if this check box is selected (either by a human user via
|
||||
* a PDF reader, or else programmatically via software). For example:
|
||||
* ```js
|
||||
* const checkBox = form.getCheckBox('some.checkBox.field')
|
||||
* if (checkBox.isChecked()) console.log('check box is selected')
|
||||
* ```
|
||||
* @returns Whether or not this check box is selected.
|
||||
*/
|
||||
PDFCheckBox.prototype.isChecked = function () {
|
||||
var onValue = this.acroField.getOnValue();
|
||||
return !!onValue && onValue === this.acroField.getValue();
|
||||
};
|
||||
/**
|
||||
* Show this check box on the specified page. For example:
|
||||
* ```js
|
||||
* const helvetica = await pdfDoc.embedFont(StandardFonts.Helvetica)
|
||||
* const page = pdfDoc.addPage()
|
||||
*
|
||||
* const form = pdfDoc.getForm()
|
||||
* const checkBox = form.createCheckBox('some.checkBox.field')
|
||||
*
|
||||
* checkBox.addToPage(page, {
|
||||
* x: 50,
|
||||
* y: 75,
|
||||
* width: 25,
|
||||
* height: 25,
|
||||
* textColor: rgb(1, 0, 0),
|
||||
* backgroundColor: rgb(0, 1, 0),
|
||||
* borderColor: rgb(0, 0, 1),
|
||||
* borderWidth: 2,
|
||||
* rotate: degrees(90),
|
||||
* })
|
||||
* ```
|
||||
* This will create a new widget for this check box field.
|
||||
* @param page The page to which this check box widget should be added.
|
||||
* @param options The options to be used when adding this check box widget.
|
||||
*/
|
||||
PDFCheckBox.prototype.addToPage = function (page, options) {
|
||||
var _a, _b, _c, _d, _e, _f;
|
||||
assertIs(page, 'page', [[PDFPage, 'PDFPage']]);
|
||||
assertFieldAppearanceOptions(options);
|
||||
if (!options)
|
||||
options = {};
|
||||
if (!('textColor' in options))
|
||||
options.textColor = rgb(0, 0, 0);
|
||||
if (!('backgroundColor' in options))
|
||||
options.backgroundColor = rgb(1, 1, 1);
|
||||
if (!('borderColor' in options))
|
||||
options.borderColor = rgb(0, 0, 0);
|
||||
if (!('borderWidth' in options))
|
||||
options.borderWidth = 1;
|
||||
// Create a widget for this check box
|
||||
var widget = this.createWidget({
|
||||
x: (_a = options.x) !== null && _a !== void 0 ? _a : 0,
|
||||
y: (_b = options.y) !== null && _b !== void 0 ? _b : 0,
|
||||
width: (_c = options.width) !== null && _c !== void 0 ? _c : 50,
|
||||
height: (_d = options.height) !== null && _d !== void 0 ? _d : 50,
|
||||
textColor: options.textColor,
|
||||
backgroundColor: options.backgroundColor,
|
||||
borderColor: options.borderColor,
|
||||
borderWidth: (_e = options.borderWidth) !== null && _e !== void 0 ? _e : 0,
|
||||
rotate: (_f = options.rotate) !== null && _f !== void 0 ? _f : degrees(0),
|
||||
hidden: options.hidden,
|
||||
page: page.ref,
|
||||
});
|
||||
var widgetRef = this.doc.context.register(widget.dict);
|
||||
// Add widget to this field
|
||||
this.acroField.addWidget(widgetRef);
|
||||
// Set appearance streams for widget
|
||||
widget.setAppearanceState(PDFName.of('Off'));
|
||||
this.updateWidgetAppearance(widget, PDFName.of('Yes'));
|
||||
// Add widget to the given page
|
||||
page.node.addAnnot(widgetRef);
|
||||
};
|
||||
/**
|
||||
* Returns `true` if any of this check box's widgets do not have an
|
||||
* appearance stream for its current state. For example:
|
||||
* ```js
|
||||
* const checkBox = form.getCheckBox('some.checkBox.field')
|
||||
* if (checkBox.needsAppearancesUpdate()) console.log('Needs update')
|
||||
* ```
|
||||
* @returns Whether or not this check box needs an appearance update.
|
||||
*/
|
||||
PDFCheckBox.prototype.needsAppearancesUpdate = function () {
|
||||
var _a;
|
||||
var widgets = this.acroField.getWidgets();
|
||||
for (var idx = 0, len = widgets.length; idx < len; idx++) {
|
||||
var widget = widgets[idx];
|
||||
var state = widget.getAppearanceState();
|
||||
var normal = (_a = widget.getAppearances()) === null || _a === void 0 ? void 0 : _a.normal;
|
||||
if (!(normal instanceof PDFDict))
|
||||
return true;
|
||||
if (state && !normal.has(state))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
/**
|
||||
* Update the appearance streams for each of this check box's widgets using
|
||||
* the default appearance provider for check boxes. For example:
|
||||
* ```js
|
||||
* const checkBox = form.getCheckBox('some.checkBox.field')
|
||||
* checkBox.defaultUpdateAppearances()
|
||||
* ```
|
||||
*/
|
||||
PDFCheckBox.prototype.defaultUpdateAppearances = function () {
|
||||
this.updateAppearances();
|
||||
};
|
||||
/**
|
||||
* Update the appearance streams for each of this check box's widgets using
|
||||
* the given appearance provider. If no `provider` is passed, the default
|
||||
* appearance provider for check boxs will be used. For example:
|
||||
* ```js
|
||||
* const checkBox = form.getCheckBox('some.checkBox.field')
|
||||
* checkBox.updateAppearances((field, widget) => {
|
||||
* ...
|
||||
* return {
|
||||
* normal: { on: drawCheckBox(...), off: drawCheckBox(...) },
|
||||
* down: { on: drawCheckBox(...), off: drawCheckBox(...) },
|
||||
* }
|
||||
* })
|
||||
* ```
|
||||
* @param provider Optionally, the appearance provider to be used for
|
||||
* generating the contents of the appearance streams.
|
||||
*/
|
||||
PDFCheckBox.prototype.updateAppearances = function (provider) {
|
||||
var _a;
|
||||
assertOrUndefined(provider, 'provider', [Function]);
|
||||
var widgets = this.acroField.getWidgets();
|
||||
for (var idx = 0, len = widgets.length; idx < len; idx++) {
|
||||
var widget = widgets[idx];
|
||||
var onValue = (_a = widget.getOnValue()) !== null && _a !== void 0 ? _a : PDFName.of('Yes');
|
||||
if (!onValue)
|
||||
continue;
|
||||
this.updateWidgetAppearance(widget, onValue, provider);
|
||||
}
|
||||
this.markAsClean();
|
||||
};
|
||||
PDFCheckBox.prototype.updateWidgetAppearance = function (widget, onValue, provider) {
|
||||
var apProvider = provider !== null && provider !== void 0 ? provider : defaultCheckBoxAppearanceProvider;
|
||||
var appearances = normalizeAppearance(apProvider(this, widget));
|
||||
this.updateOnOffWidgetAppearance(widget, onValue, appearances);
|
||||
};
|
||||
/**
|
||||
* > **NOTE:** You probably don't want to call this method directly. Instead,
|
||||
* > consider using the [[PDFForm.getCheckBox]] method, which will create an
|
||||
* > instance of [[PDFCheckBox]] for you.
|
||||
*
|
||||
* Create an instance of [[PDFCheckBox]] from an existing acroCheckBox and ref
|
||||
*
|
||||
* @param acroCheckBox The underlying `PDFAcroCheckBox` for this check box.
|
||||
* @param ref The unique reference for this check box.
|
||||
* @param doc The document to which this check box will belong.
|
||||
*/
|
||||
PDFCheckBox.of = function (acroCheckBox, ref, doc) {
|
||||
return new PDFCheckBox(acroCheckBox, ref, doc);
|
||||
};
|
||||
return PDFCheckBox;
|
||||
}(PDFField));
|
||||
export default PDFCheckBox;
|
||||
//# sourceMappingURL=PDFCheckBox.js.map
|
||||
1
node_modules/pdf-lib/es/api/form/PDFCheckBox.js.map
generated
vendored
Normal file
1
node_modules/pdf-lib/es/api/form/PDFCheckBox.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"PDFCheckBox.js","sourceRoot":"","sources":["../../../src/api/form/PDFCheckBox.ts"],"names":[],"mappings":"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"}
|
||||
403
node_modules/pdf-lib/es/api/form/PDFDropdown.d.ts
generated
vendored
Normal file
403
node_modules/pdf-lib/es/api/form/PDFDropdown.d.ts
generated
vendored
Normal file
@@ -0,0 +1,403 @@
|
||||
import PDFDocument from "../PDFDocument";
|
||||
import PDFPage from "../PDFPage";
|
||||
import PDFFont from "../PDFFont";
|
||||
import PDFField, { FieldAppearanceOptions } from "./PDFField";
|
||||
import { AppearanceProviderFor } from "./appearances";
|
||||
import { PDFRef, PDFAcroComboBox } from "../../core";
|
||||
/**
|
||||
* Represents a dropdown field of a [[PDFForm]].
|
||||
*
|
||||
* [[PDFDropdown]] fields are interactive text boxes that display a single
|
||||
* element (the currently selected value). The purpose of a dropdown is to
|
||||
* enable users to select a single option from a set of possible options. Users
|
||||
* can click on a dropdown to view the full list of options it provides.
|
||||
* Clicking on an option in the list will cause it to be selected and displayed
|
||||
* in the dropdown's text box. Some dropdowns allow users to enter text
|
||||
* directly into the box from their keyboard, rather than only being allowed to
|
||||
* choose an option from the list (see [[PDFDropdown.isEditable]]).
|
||||
*/
|
||||
export default class PDFDropdown extends PDFField {
|
||||
/**
|
||||
* > **NOTE:** You probably don't want to call this method directly. Instead,
|
||||
* > consider using the [[PDFForm.getDropdown]] method, which will create an
|
||||
* > instance of [[PDFDropdown]] for you.
|
||||
*
|
||||
* Create an instance of [[PDFDropdown]] from an existing acroComboBox and ref
|
||||
*
|
||||
* @param acroComboBox The underlying `PDFAcroComboBox` for this dropdown.
|
||||
* @param ref The unique reference for this dropdown.
|
||||
* @param doc The document to which this dropdown will belong.
|
||||
*/
|
||||
static of: (acroComboBox: PDFAcroComboBox, ref: PDFRef, doc: PDFDocument) => PDFDropdown;
|
||||
/** The low-level PDFAcroComboBox wrapped by this dropdown. */
|
||||
readonly acroField: PDFAcroComboBox;
|
||||
private constructor();
|
||||
/**
|
||||
* Get the list of available options for this dropdown. These options will be
|
||||
* displayed to users who click on this dropdown in a PDF reader.
|
||||
* For example:
|
||||
* ```js
|
||||
* const dropdown = form.getDropdown('some.dropdown.field')
|
||||
* const options = dropdown.getOptions()
|
||||
* console.log('Dropdown options:', options)
|
||||
* ```
|
||||
* @returns The options for this dropdown.
|
||||
*/
|
||||
getOptions(): string[];
|
||||
/**
|
||||
* Get the selected options for this dropdown. These are the values that were
|
||||
* selected by a human user via a PDF reader, or programatically via
|
||||
* software.
|
||||
* For example:
|
||||
* ```js
|
||||
* const dropdown = form.getDropdown('some.dropdown.field')
|
||||
* const selections = dropdown.getSelected()
|
||||
* console.log('Dropdown selections:', selections)
|
||||
* ```
|
||||
* > **NOTE:** Note that PDF readers only display one selected option when
|
||||
* > rendering dropdowns. However, the PDF specification does allow for
|
||||
* > multiple values to be selected in a dropdown. As such, the `pdf-lib`
|
||||
* > API supports this. However, in most cases the array returned by this
|
||||
* > method will contain only a single element (or no elements).
|
||||
* @returns The selected options in this dropdown.
|
||||
*/
|
||||
getSelected(): string[];
|
||||
/**
|
||||
* Set the list of options that are available for this dropdown. These are
|
||||
* the values that will be available for users to select when they view this
|
||||
* dropdown in a PDF reader. Note that preexisting options for this dropdown
|
||||
* will be removed. Only the values passed as `options` will be available to
|
||||
* select.
|
||||
* For example:
|
||||
* ```js
|
||||
* const dropdown = form.getDropdown('planets.dropdown')
|
||||
* dropdown.setOptions(['Earth', 'Mars', 'Pluto', 'Venus'])
|
||||
* ```
|
||||
* @param options The options that should be available in this dropdown.
|
||||
*/
|
||||
setOptions(options: string[]): void;
|
||||
/**
|
||||
* Add to the list of options that are available for this dropdown. Users
|
||||
* will be able to select these values in a PDF reader. In addition to the
|
||||
* values passed as `options`, any preexisting options for this dropdown will
|
||||
* still be available for users to select.
|
||||
* For example:
|
||||
* ```js
|
||||
* const dropdown = form.getDropdown('rockets.dropdown')
|
||||
* dropdown.addOptions(['Saturn IV', 'Falcon Heavy'])
|
||||
* ```
|
||||
* @param options New options that should be available in this dropdown.
|
||||
*/
|
||||
addOptions(options: string | string[]): void;
|
||||
/**
|
||||
* Select one or more values for this dropdown. This operation is analogous
|
||||
* to a human user opening the dropdown in a PDF reader and clicking on a
|
||||
* value to select it. This method will update the underlying state of the
|
||||
* dropdown to indicate which values have been selected. PDF libraries and
|
||||
* readers will be able to extract these values from the saved document and
|
||||
* determine which values were selected.
|
||||
*
|
||||
* For example:
|
||||
* ```js
|
||||
* const dropdown = form.getDropdown('best.superhero.dropdown')
|
||||
* dropdown.select('One Punch Man')
|
||||
* ```
|
||||
*
|
||||
* This method will mark this dropdown as dirty, causing its appearance
|
||||
* streams to be updated when either [[PDFDocument.save]] or
|
||||
* [[PDFForm.updateFieldAppearances]] is called. The updated streams will
|
||||
* display the selected option inside the widgets of this dropdown.
|
||||
*
|
||||
* **IMPORTANT:** The default font used to update appearance streams is
|
||||
* [[StandardFonts.Helvetica]]. Note that this is a WinAnsi font. This means
|
||||
* that encoding errors will be thrown if the selected option for this field
|
||||
* contains characters outside the WinAnsi character set (the latin alphabet).
|
||||
*
|
||||
* Embedding a custom font and passing it to
|
||||
* [[PDFForm.updateFieldAppearances]] or [[PDFDropdown.updateAppearances]]
|
||||
* allows you to generate appearance streams with characters outside the
|
||||
* latin alphabet (assuming the custom font supports them).
|
||||
*
|
||||
* Selecting an option that does not exist in this dropdown's option list
|
||||
* (see [[PDFDropdown.getOptions]]) will enable editing on this dropdown
|
||||
* (see [[PDFDropdown.enableEditing]]).
|
||||
*
|
||||
* > **NOTE:** PDF readers only display one selected option when rendering
|
||||
* > dropdowns. However, the PDF specification does allow for multiple values
|
||||
* > to be selected in a dropdown. As such, the `pdf-lib` API supports this.
|
||||
* > However, it is not recommended to select more than one value with this
|
||||
* > method, as only one will be visible. [[PDFOptionList]] fields are better
|
||||
* > suited for displaying multiple selected values.
|
||||
*
|
||||
* @param options The options to be selected.
|
||||
* @param merge Whether or not existing selections should be preserved.
|
||||
*/
|
||||
select(options: string | string[], merge?: boolean): void;
|
||||
/**
|
||||
* Clear all selected values for this dropdown. This operation is equivalent
|
||||
* to selecting an empty list. This method will update the underlying state
|
||||
* of the dropdown to indicate that no values have been selected.
|
||||
* For example:
|
||||
* ```js
|
||||
* const dropdown = form.getDropdown('some.dropdown.field')
|
||||
* dropdown.clear()
|
||||
* ```
|
||||
* This method will mark this text field as dirty. See [[PDFDropdown.select]]
|
||||
* for more details about what this means.
|
||||
*/
|
||||
clear(): void;
|
||||
/**
|
||||
* Set the font size for this field. Larger font sizes will result in larger
|
||||
* text being displayed when PDF readers render this dropdown. Font sizes may
|
||||
* be integer or floating point numbers. Supplying a negative font size will
|
||||
* cause this method to throw an error.
|
||||
*
|
||||
* For example:
|
||||
* ```js
|
||||
* const dropdown = form.getDropdown('some.dropdown.field')
|
||||
* dropdown.setFontSize(4)
|
||||
* dropdown.setFontSize(15.7)
|
||||
* ```
|
||||
*
|
||||
* > This method depends upon the existence of a default appearance
|
||||
* > (`/DA`) string. If this field does not have a default appearance string,
|
||||
* > or that string does not contain a font size (via the `Tf` operator),
|
||||
* > then this method will throw an error.
|
||||
*
|
||||
* @param fontSize The font size to be used when rendering text in this field.
|
||||
*/
|
||||
setFontSize(fontSize: number): void;
|
||||
/**
|
||||
* Returns `true` if users are allowed to edit the selected value of this
|
||||
* dropdown directly and are not constrained by the list of available
|
||||
* options. See [[PDFDropdown.enableEditing]] and
|
||||
* [[PDFDropdown.disableEditing]]. For example:
|
||||
* ```js
|
||||
* const dropdown = form.getDropdown('some.dropdown.field')
|
||||
* if (dropdown.isEditable()) console.log('Editing is enabled')
|
||||
* ```
|
||||
* @returns Whether or not this dropdown is editable.
|
||||
*/
|
||||
isEditable(): boolean;
|
||||
/**
|
||||
* Allow users to edit the selected value of this dropdown in PDF readers
|
||||
* with their keyboard. This means that the selected value of this dropdown
|
||||
* will not be constrained by the list of available options. However, if this
|
||||
* dropdown has any available options, users will still be allowed to select
|
||||
* from that list.
|
||||
* For example:
|
||||
* ```js
|
||||
* const dropdown = form.getDropdown('some.dropdown.field')
|
||||
* dropdown.enableEditing()
|
||||
* ```
|
||||
*/
|
||||
enableEditing(): void;
|
||||
/**
|
||||
* Do not allow users to edit the selected value of this dropdown in PDF
|
||||
* readers with their keyboard. This will constrain the selected value of
|
||||
* this dropdown to the list of available options. Users will only be able
|
||||
* to select an option from that list.
|
||||
* For example:
|
||||
* ```js
|
||||
* const dropdown = form.getDropdown('some.dropdown.field')
|
||||
* dropdown.disableEditing()
|
||||
* ```
|
||||
*/
|
||||
disableEditing(): void;
|
||||
/**
|
||||
* Returns `true` if the option list of this dropdown is always displayed
|
||||
* in alphabetical order, irrespective of the order in which the options
|
||||
* were added to the dropdown. See [[PDFDropdown.enableSorting]] and
|
||||
* [[PDFDropdown.disableSorting]]. For example:
|
||||
* ```js
|
||||
* const dropdown = form.getDropdown('some.dropdown.field')
|
||||
* if (dropdown.isSorted()) console.log('Sorting is enabled')
|
||||
* ```
|
||||
* @returns Whether or not this dropdown's options are sorted.
|
||||
*/
|
||||
isSorted(): boolean;
|
||||
/**
|
||||
* Always display the option list of this dropdown in alphabetical order,
|
||||
* irrespective of the order in which the options were added to this dropdown.
|
||||
* For example:
|
||||
* ```js
|
||||
* const dropdown = form.getDropdown('some.dropdown.field')
|
||||
* dropdown.enableSorting()
|
||||
* ```
|
||||
*/
|
||||
enableSorting(): void;
|
||||
/**
|
||||
* Do not always display the option list of this dropdown in alphabetical
|
||||
* order. Instead, display the options in whichever order they were added
|
||||
* to the list. For example:
|
||||
* ```js
|
||||
* const dropdown = form.getDropdown('some.dropdown.field')
|
||||
* dropdown.disableSorting()
|
||||
* ```
|
||||
*/
|
||||
disableSorting(): void;
|
||||
/**
|
||||
* Returns `true` if multiple options can be selected from this dropdown's
|
||||
* option list. See [[PDFDropdown.enableMultiselect]] and
|
||||
* [[PDFDropdown.disableMultiselect]]. For example:
|
||||
* ```js
|
||||
* const dropdown = form.getDropdown('some.dropdown.field')
|
||||
* if (dropdown.isMultiselect()) console.log('Multiselect is enabled')
|
||||
* ```
|
||||
* @returns Whether or not multiple options can be selected.
|
||||
*/
|
||||
isMultiselect(): boolean;
|
||||
/**
|
||||
* Allow users to select more than one option from this dropdown's option
|
||||
* list. For example:
|
||||
* ```js
|
||||
* const dropdown = form.getDropdown('some.dropdown.field')
|
||||
* dropdown.enableMultiselect()
|
||||
* ```
|
||||
*/
|
||||
enableMultiselect(): void;
|
||||
/**
|
||||
* Do not allow users to select more than one option from this dropdown's
|
||||
* option list. For example:
|
||||
* ```js
|
||||
* const dropdown = form.getDropdown('some.dropdown.field')
|
||||
* dropdown.disableMultiselect()
|
||||
* ```
|
||||
*/
|
||||
disableMultiselect(): void;
|
||||
/**
|
||||
* Returns `true` if the selected option should be spell checked by PDF
|
||||
* readers. Spell checking will only be performed if this dropdown allows
|
||||
* editing (see [[PDFDropdown.isEditable]]). See
|
||||
* [[PDFDropdown.enableSpellChecking]] and
|
||||
* [[PDFDropdown.disableSpellChecking]]. For example:
|
||||
* ```js
|
||||
* const dropdown = form.getDropdown('some.dropdown.field')
|
||||
* if (dropdown.isSpellChecked()) console.log('Spell checking is enabled')
|
||||
* ```
|
||||
* @returns Whether or not this dropdown can be spell checked.
|
||||
*/
|
||||
isSpellChecked(): boolean;
|
||||
/**
|
||||
* Allow PDF readers to spell check the selected option of this dropdown.
|
||||
* For example:
|
||||
* ```js
|
||||
* const dropdown = form.getDropdown('some.dropdown.field')
|
||||
* dropdown.enableSpellChecking()
|
||||
* ```
|
||||
*/
|
||||
enableSpellChecking(): void;
|
||||
/**
|
||||
* Do not allow PDF readers to spell check the selected option of this
|
||||
* dropdown. For example:
|
||||
* ```js
|
||||
* const dropdown = form.getDropdown('some.dropdown.field')
|
||||
* dropdown.disableSpellChecking()
|
||||
* ```
|
||||
*/
|
||||
disableSpellChecking(): void;
|
||||
/**
|
||||
* Returns `true` if the option selected by a user is stored, or "committed",
|
||||
* when the user clicks the option. The alternative is that the user's
|
||||
* selection is stored when the user leaves this dropdown field (by clicking
|
||||
* outside of it - on another field, for example). See
|
||||
* [[PDFDropdown.enableSelectOnClick]] and
|
||||
* [[PDFDropdown.disableSelectOnClick]]. For example:
|
||||
* ```js
|
||||
* const dropdown = form.getDropdown('some.dropdown.field')
|
||||
* if (dropdown.isSelectOnClick()) console.log('Select on click is enabled')
|
||||
* ```
|
||||
* @returns Whether or not options are selected immediately after they are
|
||||
* clicked.
|
||||
*/
|
||||
isSelectOnClick(): boolean;
|
||||
/**
|
||||
* Store the option selected by a user immediately after the user clicks the
|
||||
* option. Do not wait for the user to leave this dropdown field (by clicking
|
||||
* outside of it - on another field, for example). For example:
|
||||
* ```js
|
||||
* const dropdown = form.getDropdown('some.dropdown.field')
|
||||
* dropdown.enableSelectOnClick()
|
||||
* ```
|
||||
*/
|
||||
enableSelectOnClick(): void;
|
||||
/**
|
||||
* Wait to store the option selected by a user until they leave this dropdown
|
||||
* field (by clicking outside of it - on another field, for example).
|
||||
* For example:
|
||||
* ```js
|
||||
* const dropdown = form.getDropdown('some.dropdown.field')
|
||||
* dropdown.disableSelectOnClick()
|
||||
* ```
|
||||
*/
|
||||
disableSelectOnClick(): void;
|
||||
/**
|
||||
* Show this dropdown on the specified page. For example:
|
||||
* ```js
|
||||
* const ubuntuFont = await pdfDoc.embedFont(ubuntuFontBytes)
|
||||
* const page = pdfDoc.addPage()
|
||||
*
|
||||
* const form = pdfDoc.getForm()
|
||||
* const dropdown = form.createDropdown('best.gundam')
|
||||
* dropdown.setOptions(['Exia', 'Dynames'])
|
||||
* dropdown.select('Exia')
|
||||
*
|
||||
* dropdown.addToPage(page, {
|
||||
* x: 50,
|
||||
* y: 75,
|
||||
* width: 200,
|
||||
* height: 100,
|
||||
* textColor: rgb(1, 0, 0),
|
||||
* backgroundColor: rgb(0, 1, 0),
|
||||
* borderColor: rgb(0, 0, 1),
|
||||
* borderWidth: 2,
|
||||
* rotate: degrees(90),
|
||||
* font: ubuntuFont,
|
||||
* })
|
||||
* ```
|
||||
* This will create a new widget for this dropdown field.
|
||||
* @param page The page to which this dropdown widget should be added.
|
||||
* @param options The options to be used when adding this dropdown widget.
|
||||
*/
|
||||
addToPage(page: PDFPage, options?: FieldAppearanceOptions): void;
|
||||
/**
|
||||
* Returns `true` if this dropdown has been marked as dirty, or if any of
|
||||
* this dropdown's widgets do not have an appearance stream. For example:
|
||||
* ```js
|
||||
* const dropdown = form.getDropdown('some.dropdown.field')
|
||||
* if (dropdown.needsAppearancesUpdate()) console.log('Needs update')
|
||||
* ```
|
||||
* @returns Whether or not this dropdown needs an appearance update.
|
||||
*/
|
||||
needsAppearancesUpdate(): boolean;
|
||||
/**
|
||||
* Update the appearance streams for each of this dropdown's widgets using
|
||||
* the default appearance provider for dropdowns. For example:
|
||||
* ```js
|
||||
* const helvetica = await pdfDoc.embedFont(StandardFonts.Helvetica)
|
||||
* const dropdown = form.getDropdown('some.dropdown.field')
|
||||
* dropdown.defaultUpdateAppearances(helvetica)
|
||||
* ```
|
||||
* @param font The font to be used for creating the appearance streams.
|
||||
*/
|
||||
defaultUpdateAppearances(font: PDFFont): void;
|
||||
/**
|
||||
* Update the appearance streams for each of this dropdown's widgets using
|
||||
* the given appearance provider. If no `provider` is passed, the default
|
||||
* appearance provider for dropdowns will be used. For example:
|
||||
* ```js
|
||||
* const helvetica = await pdfDoc.embedFont(StandardFonts.Helvetica)
|
||||
* const dropdown = form.getDropdown('some.dropdown.field')
|
||||
* dropdown.updateAppearances(helvetica, (field, widget, font) => {
|
||||
* ...
|
||||
* return drawTextField(...)
|
||||
* })
|
||||
* ```
|
||||
* @param font The font to be used for creating the appearance streams.
|
||||
* @param provider Optionally, the appearance provider to be used for
|
||||
* generating the contents of the appearance streams.
|
||||
*/
|
||||
updateAppearances(font: PDFFont, provider?: AppearanceProviderFor<PDFDropdown>): void;
|
||||
private updateWidgetAppearance;
|
||||
}
|
||||
//# sourceMappingURL=PDFDropdown.d.ts.map
|
||||
1
node_modules/pdf-lib/es/api/form/PDFDropdown.d.ts.map
generated
vendored
Normal file
1
node_modules/pdf-lib/es/api/form/PDFDropdown.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"PDFDropdown.d.ts","sourceRoot":"","sources":["../../../src/api/form/PDFDropdown.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,uBAA4B;AAC9C,OAAO,OAAO,mBAAwB;AACtC,OAAO,OAAO,mBAAwB;AACtC,OAAO,QAAQ,EAAE,EACf,sBAAsB,EAEvB,mBAA8B;AAC/B,OAAO,EACL,qBAAqB,EAGtB,sBAAiC;AAIlC,OAAO,EAEL,MAAM,EAIN,eAAe,EAEhB,mBAAiB;AAGlB;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,OAAO,OAAO,WAAY,SAAQ,QAAQ;IAC/C;;;;;;;;;;OAUG;IACH,MAAM,CAAC,EAAE,iBAAkB,eAAe,OAAO,MAAM,OAAO,WAAW,iBAC/B;IAE1C,8DAA8D;IAC9D,QAAQ,CAAC,SAAS,EAAE,eAAe,CAAC;IAEpC,OAAO;IAcP;;;;;;;;;;OAUG;IACH,UAAU,IAAI,MAAM,EAAE;IAYtB;;;;;;;;;;;;;;;;OAgBG;IACH,WAAW,IAAI,MAAM,EAAE;IAWvB;;;;;;;;;;;;OAYG;IACH,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE;IAU5B;;;;;;;;;;;OAWG;IACH,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE;IAkBrC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA0CG;IACH,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,KAAK,UAAQ;IA+BhD;;;;;;;;;;;OAWG;IACH,KAAK;IAKL;;;;;;;;;;;;;;;;;;;OAmBG;IACH,WAAW,CAAC,QAAQ,EAAE,MAAM;IAM5B;;;;;;;;;;OAUG;IACH,UAAU,IAAI,OAAO;IAIrB;;;;;;;;;;;OAWG;IACH,aAAa;IAIb;;;;;;;;;;OAUG;IACH,cAAc;IAId;;;;;;;;;;OAUG;IACH,QAAQ,IAAI,OAAO;IAInB;;;;;;;;OAQG;IACH,aAAa;IAIb;;;;;;;;OAQG;IACH,cAAc;IAId;;;;;;;;;OASG;IACH,aAAa,IAAI,OAAO;IAIxB;;;;;;;OAOG;IACH,iBAAiB;IAIjB;;;;;;;OAOG;IACH,kBAAkB;IAIlB;;;;;;;;;;;OAWG;IACH,cAAc,IAAI,OAAO;IAIzB;;;;;;;OAOG;IACH,mBAAmB;IAInB;;;;;;;OAOG;IACH,oBAAoB;IAIpB;;;;;;;;;;;;;OAaG;IACH,eAAe,IAAI,OAAO;IAI1B;;;;;;;;OAQG;IACH,mBAAmB;IAInB;;;;;;;;OAQG;IACH,oBAAoB;IAIpB;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACH,SAAS,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,sBAAsB;IAsCzD;;;;;;;;OAQG;IACH,sBAAsB,IAAI,OAAO;IAcjC;;;;;;;;;OASG;IACH,wBAAwB,CAAC,IAAI,EAAE,OAAO;IAKtC;;;;;;;;;;;;;;;OAeG;IACH,iBAAiB,CACf,IAAI,EAAE,OAAO,EACb,QAAQ,CAAC,EAAE,qBAAqB,CAAC,WAAW,CAAC;IAoB/C,OAAO,CAAC,sBAAsB;CAS/B"}
|
||||
578
node_modules/pdf-lib/es/api/form/PDFDropdown.js
generated
vendored
Normal file
578
node_modules/pdf-lib/es/api/form/PDFDropdown.js
generated
vendored
Normal file
@@ -0,0 +1,578 @@
|
||||
import { __extends } from "tslib";
|
||||
import PDFPage from "../PDFPage";
|
||||
import PDFFont from "../PDFFont";
|
||||
import PDFField, { assertFieldAppearanceOptions, } from "./PDFField";
|
||||
import { normalizeAppearance, defaultDropdownAppearanceProvider, } from "./appearances";
|
||||
import { rgb } from "../colors";
|
||||
import { degrees } from "../rotations";
|
||||
import { PDFHexString, PDFStream, PDFAcroComboBox, AcroChoiceFlags, } from "../../core";
|
||||
import { assertIs, assertOrUndefined, assertPositive } from "../../utils";
|
||||
/**
|
||||
* Represents a dropdown field of a [[PDFForm]].
|
||||
*
|
||||
* [[PDFDropdown]] fields are interactive text boxes that display a single
|
||||
* element (the currently selected value). The purpose of a dropdown is to
|
||||
* enable users to select a single option from a set of possible options. Users
|
||||
* can click on a dropdown to view the full list of options it provides.
|
||||
* Clicking on an option in the list will cause it to be selected and displayed
|
||||
* in the dropdown's text box. Some dropdowns allow users to enter text
|
||||
* directly into the box from their keyboard, rather than only being allowed to
|
||||
* choose an option from the list (see [[PDFDropdown.isEditable]]).
|
||||
*/
|
||||
var PDFDropdown = /** @class */ (function (_super) {
|
||||
__extends(PDFDropdown, _super);
|
||||
function PDFDropdown(acroComboBox, ref, doc) {
|
||||
var _this = _super.call(this, acroComboBox, ref, doc) || this;
|
||||
assertIs(acroComboBox, 'acroComboBox', [
|
||||
[PDFAcroComboBox, 'PDFAcroComboBox'],
|
||||
]);
|
||||
_this.acroField = acroComboBox;
|
||||
return _this;
|
||||
}
|
||||
/**
|
||||
* Get the list of available options for this dropdown. These options will be
|
||||
* displayed to users who click on this dropdown in a PDF reader.
|
||||
* For example:
|
||||
* ```js
|
||||
* const dropdown = form.getDropdown('some.dropdown.field')
|
||||
* const options = dropdown.getOptions()
|
||||
* console.log('Dropdown options:', options)
|
||||
* ```
|
||||
* @returns The options for this dropdown.
|
||||
*/
|
||||
PDFDropdown.prototype.getOptions = function () {
|
||||
var rawOptions = this.acroField.getOptions();
|
||||
var options = new Array(rawOptions.length);
|
||||
for (var idx = 0, len = options.length; idx < len; idx++) {
|
||||
var _a = rawOptions[idx], display = _a.display, value = _a.value;
|
||||
options[idx] = (display !== null && display !== void 0 ? display : value).decodeText();
|
||||
}
|
||||
return options;
|
||||
};
|
||||
/**
|
||||
* Get the selected options for this dropdown. These are the values that were
|
||||
* selected by a human user via a PDF reader, or programatically via
|
||||
* software.
|
||||
* For example:
|
||||
* ```js
|
||||
* const dropdown = form.getDropdown('some.dropdown.field')
|
||||
* const selections = dropdown.getSelected()
|
||||
* console.log('Dropdown selections:', selections)
|
||||
* ```
|
||||
* > **NOTE:** Note that PDF readers only display one selected option when
|
||||
* > rendering dropdowns. However, the PDF specification does allow for
|
||||
* > multiple values to be selected in a dropdown. As such, the `pdf-lib`
|
||||
* > API supports this. However, in most cases the array returned by this
|
||||
* > method will contain only a single element (or no elements).
|
||||
* @returns The selected options in this dropdown.
|
||||
*/
|
||||
PDFDropdown.prototype.getSelected = function () {
|
||||
var values = this.acroField.getValues();
|
||||
var selected = new Array(values.length);
|
||||
for (var idx = 0, len = values.length; idx < len; idx++) {
|
||||
selected[idx] = values[idx].decodeText();
|
||||
}
|
||||
return selected;
|
||||
};
|
||||
/**
|
||||
* Set the list of options that are available for this dropdown. These are
|
||||
* the values that will be available for users to select when they view this
|
||||
* dropdown in a PDF reader. Note that preexisting options for this dropdown
|
||||
* will be removed. Only the values passed as `options` will be available to
|
||||
* select.
|
||||
* For example:
|
||||
* ```js
|
||||
* const dropdown = form.getDropdown('planets.dropdown')
|
||||
* dropdown.setOptions(['Earth', 'Mars', 'Pluto', 'Venus'])
|
||||
* ```
|
||||
* @param options The options that should be available in this dropdown.
|
||||
*/
|
||||
PDFDropdown.prototype.setOptions = function (options) {
|
||||
assertIs(options, 'options', [Array]);
|
||||
var optionObjects = new Array(options.length);
|
||||
for (var idx = 0, len = options.length; idx < len; idx++) {
|
||||
optionObjects[idx] = { value: PDFHexString.fromText(options[idx]) };
|
||||
}
|
||||
this.acroField.setOptions(optionObjects);
|
||||
};
|
||||
/**
|
||||
* Add to the list of options that are available for this dropdown. Users
|
||||
* will be able to select these values in a PDF reader. In addition to the
|
||||
* values passed as `options`, any preexisting options for this dropdown will
|
||||
* still be available for users to select.
|
||||
* For example:
|
||||
* ```js
|
||||
* const dropdown = form.getDropdown('rockets.dropdown')
|
||||
* dropdown.addOptions(['Saturn IV', 'Falcon Heavy'])
|
||||
* ```
|
||||
* @param options New options that should be available in this dropdown.
|
||||
*/
|
||||
PDFDropdown.prototype.addOptions = function (options) {
|
||||
assertIs(options, 'options', ['string', Array]);
|
||||
var optionsArr = Array.isArray(options) ? options : [options];
|
||||
var existingOptions = this.acroField.getOptions();
|
||||
var newOptions = new Array(optionsArr.length);
|
||||
for (var idx = 0, len = optionsArr.length; idx < len; idx++) {
|
||||
newOptions[idx] = { value: PDFHexString.fromText(optionsArr[idx]) };
|
||||
}
|
||||
this.acroField.setOptions(existingOptions.concat(newOptions));
|
||||
};
|
||||
/**
|
||||
* Select one or more values for this dropdown. This operation is analogous
|
||||
* to a human user opening the dropdown in a PDF reader and clicking on a
|
||||
* value to select it. This method will update the underlying state of the
|
||||
* dropdown to indicate which values have been selected. PDF libraries and
|
||||
* readers will be able to extract these values from the saved document and
|
||||
* determine which values were selected.
|
||||
*
|
||||
* For example:
|
||||
* ```js
|
||||
* const dropdown = form.getDropdown('best.superhero.dropdown')
|
||||
* dropdown.select('One Punch Man')
|
||||
* ```
|
||||
*
|
||||
* This method will mark this dropdown as dirty, causing its appearance
|
||||
* streams to be updated when either [[PDFDocument.save]] or
|
||||
* [[PDFForm.updateFieldAppearances]] is called. The updated streams will
|
||||
* display the selected option inside the widgets of this dropdown.
|
||||
*
|
||||
* **IMPORTANT:** The default font used to update appearance streams is
|
||||
* [[StandardFonts.Helvetica]]. Note that this is a WinAnsi font. This means
|
||||
* that encoding errors will be thrown if the selected option for this field
|
||||
* contains characters outside the WinAnsi character set (the latin alphabet).
|
||||
*
|
||||
* Embedding a custom font and passing it to
|
||||
* [[PDFForm.updateFieldAppearances]] or [[PDFDropdown.updateAppearances]]
|
||||
* allows you to generate appearance streams with characters outside the
|
||||
* latin alphabet (assuming the custom font supports them).
|
||||
*
|
||||
* Selecting an option that does not exist in this dropdown's option list
|
||||
* (see [[PDFDropdown.getOptions]]) will enable editing on this dropdown
|
||||
* (see [[PDFDropdown.enableEditing]]).
|
||||
*
|
||||
* > **NOTE:** PDF readers only display one selected option when rendering
|
||||
* > dropdowns. However, the PDF specification does allow for multiple values
|
||||
* > to be selected in a dropdown. As such, the `pdf-lib` API supports this.
|
||||
* > However, it is not recommended to select more than one value with this
|
||||
* > method, as only one will be visible. [[PDFOptionList]] fields are better
|
||||
* > suited for displaying multiple selected values.
|
||||
*
|
||||
* @param options The options to be selected.
|
||||
* @param merge Whether or not existing selections should be preserved.
|
||||
*/
|
||||
PDFDropdown.prototype.select = function (options, merge) {
|
||||
if (merge === void 0) { merge = false; }
|
||||
assertIs(options, 'options', ['string', Array]);
|
||||
assertIs(merge, 'merge', ['boolean']);
|
||||
var optionsArr = Array.isArray(options) ? options : [options];
|
||||
var validOptions = this.getOptions();
|
||||
var hasCustomOption = optionsArr.find(function (option) { return !validOptions.includes(option); });
|
||||
if (hasCustomOption)
|
||||
this.enableEditing();
|
||||
this.markAsDirty();
|
||||
if (optionsArr.length > 1 || (optionsArr.length === 1 && merge)) {
|
||||
this.enableMultiselect();
|
||||
}
|
||||
var values = new Array(optionsArr.length);
|
||||
for (var idx = 0, len = optionsArr.length; idx < len; idx++) {
|
||||
values[idx] = PDFHexString.fromText(optionsArr[idx]);
|
||||
}
|
||||
if (merge) {
|
||||
var existingValues = this.acroField.getValues();
|
||||
this.acroField.setValues(existingValues.concat(values));
|
||||
}
|
||||
else {
|
||||
this.acroField.setValues(values);
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Clear all selected values for this dropdown. This operation is equivalent
|
||||
* to selecting an empty list. This method will update the underlying state
|
||||
* of the dropdown to indicate that no values have been selected.
|
||||
* For example:
|
||||
* ```js
|
||||
* const dropdown = form.getDropdown('some.dropdown.field')
|
||||
* dropdown.clear()
|
||||
* ```
|
||||
* This method will mark this text field as dirty. See [[PDFDropdown.select]]
|
||||
* for more details about what this means.
|
||||
*/
|
||||
PDFDropdown.prototype.clear = function () {
|
||||
this.markAsDirty();
|
||||
this.acroField.setValues([]);
|
||||
};
|
||||
/**
|
||||
* Set the font size for this field. Larger font sizes will result in larger
|
||||
* text being displayed when PDF readers render this dropdown. Font sizes may
|
||||
* be integer or floating point numbers. Supplying a negative font size will
|
||||
* cause this method to throw an error.
|
||||
*
|
||||
* For example:
|
||||
* ```js
|
||||
* const dropdown = form.getDropdown('some.dropdown.field')
|
||||
* dropdown.setFontSize(4)
|
||||
* dropdown.setFontSize(15.7)
|
||||
* ```
|
||||
*
|
||||
* > This method depends upon the existence of a default appearance
|
||||
* > (`/DA`) string. If this field does not have a default appearance string,
|
||||
* > or that string does not contain a font size (via the `Tf` operator),
|
||||
* > then this method will throw an error.
|
||||
*
|
||||
* @param fontSize The font size to be used when rendering text in this field.
|
||||
*/
|
||||
PDFDropdown.prototype.setFontSize = function (fontSize) {
|
||||
assertPositive(fontSize, 'fontSize');
|
||||
this.acroField.setFontSize(fontSize);
|
||||
this.markAsDirty();
|
||||
};
|
||||
/**
|
||||
* Returns `true` if users are allowed to edit the selected value of this
|
||||
* dropdown directly and are not constrained by the list of available
|
||||
* options. See [[PDFDropdown.enableEditing]] and
|
||||
* [[PDFDropdown.disableEditing]]. For example:
|
||||
* ```js
|
||||
* const dropdown = form.getDropdown('some.dropdown.field')
|
||||
* if (dropdown.isEditable()) console.log('Editing is enabled')
|
||||
* ```
|
||||
* @returns Whether or not this dropdown is editable.
|
||||
*/
|
||||
PDFDropdown.prototype.isEditable = function () {
|
||||
return this.acroField.hasFlag(AcroChoiceFlags.Edit);
|
||||
};
|
||||
/**
|
||||
* Allow users to edit the selected value of this dropdown in PDF readers
|
||||
* with their keyboard. This means that the selected value of this dropdown
|
||||
* will not be constrained by the list of available options. However, if this
|
||||
* dropdown has any available options, users will still be allowed to select
|
||||
* from that list.
|
||||
* For example:
|
||||
* ```js
|
||||
* const dropdown = form.getDropdown('some.dropdown.field')
|
||||
* dropdown.enableEditing()
|
||||
* ```
|
||||
*/
|
||||
PDFDropdown.prototype.enableEditing = function () {
|
||||
this.acroField.setFlagTo(AcroChoiceFlags.Edit, true);
|
||||
};
|
||||
/**
|
||||
* Do not allow users to edit the selected value of this dropdown in PDF
|
||||
* readers with their keyboard. This will constrain the selected value of
|
||||
* this dropdown to the list of available options. Users will only be able
|
||||
* to select an option from that list.
|
||||
* For example:
|
||||
* ```js
|
||||
* const dropdown = form.getDropdown('some.dropdown.field')
|
||||
* dropdown.disableEditing()
|
||||
* ```
|
||||
*/
|
||||
PDFDropdown.prototype.disableEditing = function () {
|
||||
this.acroField.setFlagTo(AcroChoiceFlags.Edit, false);
|
||||
};
|
||||
/**
|
||||
* Returns `true` if the option list of this dropdown is always displayed
|
||||
* in alphabetical order, irrespective of the order in which the options
|
||||
* were added to the dropdown. See [[PDFDropdown.enableSorting]] and
|
||||
* [[PDFDropdown.disableSorting]]. For example:
|
||||
* ```js
|
||||
* const dropdown = form.getDropdown('some.dropdown.field')
|
||||
* if (dropdown.isSorted()) console.log('Sorting is enabled')
|
||||
* ```
|
||||
* @returns Whether or not this dropdown's options are sorted.
|
||||
*/
|
||||
PDFDropdown.prototype.isSorted = function () {
|
||||
return this.acroField.hasFlag(AcroChoiceFlags.Sort);
|
||||
};
|
||||
/**
|
||||
* Always display the option list of this dropdown in alphabetical order,
|
||||
* irrespective of the order in which the options were added to this dropdown.
|
||||
* For example:
|
||||
* ```js
|
||||
* const dropdown = form.getDropdown('some.dropdown.field')
|
||||
* dropdown.enableSorting()
|
||||
* ```
|
||||
*/
|
||||
PDFDropdown.prototype.enableSorting = function () {
|
||||
this.acroField.setFlagTo(AcroChoiceFlags.Sort, true);
|
||||
};
|
||||
/**
|
||||
* Do not always display the option list of this dropdown in alphabetical
|
||||
* order. Instead, display the options in whichever order they were added
|
||||
* to the list. For example:
|
||||
* ```js
|
||||
* const dropdown = form.getDropdown('some.dropdown.field')
|
||||
* dropdown.disableSorting()
|
||||
* ```
|
||||
*/
|
||||
PDFDropdown.prototype.disableSorting = function () {
|
||||
this.acroField.setFlagTo(AcroChoiceFlags.Sort, false);
|
||||
};
|
||||
/**
|
||||
* Returns `true` if multiple options can be selected from this dropdown's
|
||||
* option list. See [[PDFDropdown.enableMultiselect]] and
|
||||
* [[PDFDropdown.disableMultiselect]]. For example:
|
||||
* ```js
|
||||
* const dropdown = form.getDropdown('some.dropdown.field')
|
||||
* if (dropdown.isMultiselect()) console.log('Multiselect is enabled')
|
||||
* ```
|
||||
* @returns Whether or not multiple options can be selected.
|
||||
*/
|
||||
PDFDropdown.prototype.isMultiselect = function () {
|
||||
return this.acroField.hasFlag(AcroChoiceFlags.MultiSelect);
|
||||
};
|
||||
/**
|
||||
* Allow users to select more than one option from this dropdown's option
|
||||
* list. For example:
|
||||
* ```js
|
||||
* const dropdown = form.getDropdown('some.dropdown.field')
|
||||
* dropdown.enableMultiselect()
|
||||
* ```
|
||||
*/
|
||||
PDFDropdown.prototype.enableMultiselect = function () {
|
||||
this.acroField.setFlagTo(AcroChoiceFlags.MultiSelect, true);
|
||||
};
|
||||
/**
|
||||
* Do not allow users to select more than one option from this dropdown's
|
||||
* option list. For example:
|
||||
* ```js
|
||||
* const dropdown = form.getDropdown('some.dropdown.field')
|
||||
* dropdown.disableMultiselect()
|
||||
* ```
|
||||
*/
|
||||
PDFDropdown.prototype.disableMultiselect = function () {
|
||||
this.acroField.setFlagTo(AcroChoiceFlags.MultiSelect, false);
|
||||
};
|
||||
/**
|
||||
* Returns `true` if the selected option should be spell checked by PDF
|
||||
* readers. Spell checking will only be performed if this dropdown allows
|
||||
* editing (see [[PDFDropdown.isEditable]]). See
|
||||
* [[PDFDropdown.enableSpellChecking]] and
|
||||
* [[PDFDropdown.disableSpellChecking]]. For example:
|
||||
* ```js
|
||||
* const dropdown = form.getDropdown('some.dropdown.field')
|
||||
* if (dropdown.isSpellChecked()) console.log('Spell checking is enabled')
|
||||
* ```
|
||||
* @returns Whether or not this dropdown can be spell checked.
|
||||
*/
|
||||
PDFDropdown.prototype.isSpellChecked = function () {
|
||||
return !this.acroField.hasFlag(AcroChoiceFlags.DoNotSpellCheck);
|
||||
};
|
||||
/**
|
||||
* Allow PDF readers to spell check the selected option of this dropdown.
|
||||
* For example:
|
||||
* ```js
|
||||
* const dropdown = form.getDropdown('some.dropdown.field')
|
||||
* dropdown.enableSpellChecking()
|
||||
* ```
|
||||
*/
|
||||
PDFDropdown.prototype.enableSpellChecking = function () {
|
||||
this.acroField.setFlagTo(AcroChoiceFlags.DoNotSpellCheck, false);
|
||||
};
|
||||
/**
|
||||
* Do not allow PDF readers to spell check the selected option of this
|
||||
* dropdown. For example:
|
||||
* ```js
|
||||
* const dropdown = form.getDropdown('some.dropdown.field')
|
||||
* dropdown.disableSpellChecking()
|
||||
* ```
|
||||
*/
|
||||
PDFDropdown.prototype.disableSpellChecking = function () {
|
||||
this.acroField.setFlagTo(AcroChoiceFlags.DoNotSpellCheck, true);
|
||||
};
|
||||
/**
|
||||
* Returns `true` if the option selected by a user is stored, or "committed",
|
||||
* when the user clicks the option. The alternative is that the user's
|
||||
* selection is stored when the user leaves this dropdown field (by clicking
|
||||
* outside of it - on another field, for example). See
|
||||
* [[PDFDropdown.enableSelectOnClick]] and
|
||||
* [[PDFDropdown.disableSelectOnClick]]. For example:
|
||||
* ```js
|
||||
* const dropdown = form.getDropdown('some.dropdown.field')
|
||||
* if (dropdown.isSelectOnClick()) console.log('Select on click is enabled')
|
||||
* ```
|
||||
* @returns Whether or not options are selected immediately after they are
|
||||
* clicked.
|
||||
*/
|
||||
PDFDropdown.prototype.isSelectOnClick = function () {
|
||||
return this.acroField.hasFlag(AcroChoiceFlags.CommitOnSelChange);
|
||||
};
|
||||
/**
|
||||
* Store the option selected by a user immediately after the user clicks the
|
||||
* option. Do not wait for the user to leave this dropdown field (by clicking
|
||||
* outside of it - on another field, for example). For example:
|
||||
* ```js
|
||||
* const dropdown = form.getDropdown('some.dropdown.field')
|
||||
* dropdown.enableSelectOnClick()
|
||||
* ```
|
||||
*/
|
||||
PDFDropdown.prototype.enableSelectOnClick = function () {
|
||||
this.acroField.setFlagTo(AcroChoiceFlags.CommitOnSelChange, true);
|
||||
};
|
||||
/**
|
||||
* Wait to store the option selected by a user until they leave this dropdown
|
||||
* field (by clicking outside of it - on another field, for example).
|
||||
* For example:
|
||||
* ```js
|
||||
* const dropdown = form.getDropdown('some.dropdown.field')
|
||||
* dropdown.disableSelectOnClick()
|
||||
* ```
|
||||
*/
|
||||
PDFDropdown.prototype.disableSelectOnClick = function () {
|
||||
this.acroField.setFlagTo(AcroChoiceFlags.CommitOnSelChange, false);
|
||||
};
|
||||
/**
|
||||
* Show this dropdown on the specified page. For example:
|
||||
* ```js
|
||||
* const ubuntuFont = await pdfDoc.embedFont(ubuntuFontBytes)
|
||||
* const page = pdfDoc.addPage()
|
||||
*
|
||||
* const form = pdfDoc.getForm()
|
||||
* const dropdown = form.createDropdown('best.gundam')
|
||||
* dropdown.setOptions(['Exia', 'Dynames'])
|
||||
* dropdown.select('Exia')
|
||||
*
|
||||
* dropdown.addToPage(page, {
|
||||
* x: 50,
|
||||
* y: 75,
|
||||
* width: 200,
|
||||
* height: 100,
|
||||
* textColor: rgb(1, 0, 0),
|
||||
* backgroundColor: rgb(0, 1, 0),
|
||||
* borderColor: rgb(0, 0, 1),
|
||||
* borderWidth: 2,
|
||||
* rotate: degrees(90),
|
||||
* font: ubuntuFont,
|
||||
* })
|
||||
* ```
|
||||
* This will create a new widget for this dropdown field.
|
||||
* @param page The page to which this dropdown widget should be added.
|
||||
* @param options The options to be used when adding this dropdown widget.
|
||||
*/
|
||||
PDFDropdown.prototype.addToPage = function (page, options) {
|
||||
var _a, _b, _c, _d, _e, _f, _g;
|
||||
assertIs(page, 'page', [[PDFPage, 'PDFPage']]);
|
||||
assertFieldAppearanceOptions(options);
|
||||
if (!options)
|
||||
options = {};
|
||||
if (!('textColor' in options))
|
||||
options.textColor = rgb(0, 0, 0);
|
||||
if (!('backgroundColor' in options))
|
||||
options.backgroundColor = rgb(1, 1, 1);
|
||||
if (!('borderColor' in options))
|
||||
options.borderColor = rgb(0, 0, 0);
|
||||
if (!('borderWidth' in options))
|
||||
options.borderWidth = 1;
|
||||
// Create a widget for this dropdown
|
||||
var widget = this.createWidget({
|
||||
x: (_a = options.x) !== null && _a !== void 0 ? _a : 0,
|
||||
y: (_b = options.y) !== null && _b !== void 0 ? _b : 0,
|
||||
width: (_c = options.width) !== null && _c !== void 0 ? _c : 200,
|
||||
height: (_d = options.height) !== null && _d !== void 0 ? _d : 50,
|
||||
textColor: options.textColor,
|
||||
backgroundColor: options.backgroundColor,
|
||||
borderColor: options.borderColor,
|
||||
borderWidth: (_e = options.borderWidth) !== null && _e !== void 0 ? _e : 0,
|
||||
rotate: (_f = options.rotate) !== null && _f !== void 0 ? _f : degrees(0),
|
||||
hidden: options.hidden,
|
||||
page: page.ref,
|
||||
});
|
||||
var widgetRef = this.doc.context.register(widget.dict);
|
||||
// Add widget to this field
|
||||
this.acroField.addWidget(widgetRef);
|
||||
// Set appearance streams for widget
|
||||
var font = (_g = options.font) !== null && _g !== void 0 ? _g : this.doc.getForm().getDefaultFont();
|
||||
this.updateWidgetAppearance(widget, font);
|
||||
// Add widget to the given page
|
||||
page.node.addAnnot(widgetRef);
|
||||
};
|
||||
/**
|
||||
* Returns `true` if this dropdown has been marked as dirty, or if any of
|
||||
* this dropdown's widgets do not have an appearance stream. For example:
|
||||
* ```js
|
||||
* const dropdown = form.getDropdown('some.dropdown.field')
|
||||
* if (dropdown.needsAppearancesUpdate()) console.log('Needs update')
|
||||
* ```
|
||||
* @returns Whether or not this dropdown needs an appearance update.
|
||||
*/
|
||||
PDFDropdown.prototype.needsAppearancesUpdate = function () {
|
||||
var _a;
|
||||
if (this.isDirty())
|
||||
return true;
|
||||
var widgets = this.acroField.getWidgets();
|
||||
for (var idx = 0, len = widgets.length; idx < len; idx++) {
|
||||
var widget = widgets[idx];
|
||||
var hasAppearances = ((_a = widget.getAppearances()) === null || _a === void 0 ? void 0 : _a.normal) instanceof PDFStream;
|
||||
if (!hasAppearances)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
/**
|
||||
* Update the appearance streams for each of this dropdown's widgets using
|
||||
* the default appearance provider for dropdowns. For example:
|
||||
* ```js
|
||||
* const helvetica = await pdfDoc.embedFont(StandardFonts.Helvetica)
|
||||
* const dropdown = form.getDropdown('some.dropdown.field')
|
||||
* dropdown.defaultUpdateAppearances(helvetica)
|
||||
* ```
|
||||
* @param font The font to be used for creating the appearance streams.
|
||||
*/
|
||||
PDFDropdown.prototype.defaultUpdateAppearances = function (font) {
|
||||
assertIs(font, 'font', [[PDFFont, 'PDFFont']]);
|
||||
this.updateAppearances(font);
|
||||
};
|
||||
/**
|
||||
* Update the appearance streams for each of this dropdown's widgets using
|
||||
* the given appearance provider. If no `provider` is passed, the default
|
||||
* appearance provider for dropdowns will be used. For example:
|
||||
* ```js
|
||||
* const helvetica = await pdfDoc.embedFont(StandardFonts.Helvetica)
|
||||
* const dropdown = form.getDropdown('some.dropdown.field')
|
||||
* dropdown.updateAppearances(helvetica, (field, widget, font) => {
|
||||
* ...
|
||||
* return drawTextField(...)
|
||||
* })
|
||||
* ```
|
||||
* @param font The font to be used for creating the appearance streams.
|
||||
* @param provider Optionally, the appearance provider to be used for
|
||||
* generating the contents of the appearance streams.
|
||||
*/
|
||||
PDFDropdown.prototype.updateAppearances = function (font, provider) {
|
||||
assertIs(font, 'font', [[PDFFont, 'PDFFont']]);
|
||||
assertOrUndefined(provider, 'provider', [Function]);
|
||||
var widgets = this.acroField.getWidgets();
|
||||
for (var idx = 0, len = widgets.length; idx < len; idx++) {
|
||||
var widget = widgets[idx];
|
||||
this.updateWidgetAppearance(widget, font, provider);
|
||||
}
|
||||
this.markAsClean();
|
||||
};
|
||||
// getOption(index: number): string {}
|
||||
// getSelectedIndices(): number[] {}
|
||||
// removeOptions(option: string | string[]) {}
|
||||
// removeIndices(option: number[]) {}
|
||||
// deselect(options: string | string[]) {}
|
||||
// deselectIndices(optionIndices: number[]) {}
|
||||
PDFDropdown.prototype.updateWidgetAppearance = function (widget, font, provider) {
|
||||
var apProvider = provider !== null && provider !== void 0 ? provider : defaultDropdownAppearanceProvider;
|
||||
var appearances = normalizeAppearance(apProvider(this, widget, font));
|
||||
this.updateWidgetAppearanceWithFont(widget, font, appearances);
|
||||
};
|
||||
/**
|
||||
* > **NOTE:** You probably don't want to call this method directly. Instead,
|
||||
* > consider using the [[PDFForm.getDropdown]] method, which will create an
|
||||
* > instance of [[PDFDropdown]] for you.
|
||||
*
|
||||
* Create an instance of [[PDFDropdown]] from an existing acroComboBox and ref
|
||||
*
|
||||
* @param acroComboBox The underlying `PDFAcroComboBox` for this dropdown.
|
||||
* @param ref The unique reference for this dropdown.
|
||||
* @param doc The document to which this dropdown will belong.
|
||||
*/
|
||||
PDFDropdown.of = function (acroComboBox, ref, doc) {
|
||||
return new PDFDropdown(acroComboBox, ref, doc);
|
||||
};
|
||||
return PDFDropdown;
|
||||
}(PDFField));
|
||||
export default PDFDropdown;
|
||||
//# sourceMappingURL=PDFDropdown.js.map
|
||||
1
node_modules/pdf-lib/es/api/form/PDFDropdown.js.map
generated
vendored
Normal file
1
node_modules/pdf-lib/es/api/form/PDFDropdown.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
204
node_modules/pdf-lib/es/api/form/PDFField.d.ts
generated
vendored
Normal file
204
node_modules/pdf-lib/es/api/form/PDFField.d.ts
generated
vendored
Normal file
@@ -0,0 +1,204 @@
|
||||
import PDFDocument from "../PDFDocument";
|
||||
import PDFFont from "../PDFFont";
|
||||
import { AppearanceMapping } from "./appearances";
|
||||
import { Color } from "../colors";
|
||||
import { Rotation } from "../rotations";
|
||||
import { PDFRef, PDFWidgetAnnotation, PDFOperator, PDFName, PDFDict, PDFAcroTerminal } from "../../core";
|
||||
import { ImageAlignment } from '../image';
|
||||
import PDFImage from '../PDFImage';
|
||||
export interface FieldAppearanceOptions {
|
||||
x?: number;
|
||||
y?: number;
|
||||
width?: number;
|
||||
height?: number;
|
||||
textColor?: Color;
|
||||
backgroundColor?: Color;
|
||||
borderColor?: Color;
|
||||
borderWidth?: number;
|
||||
rotate?: Rotation;
|
||||
font?: PDFFont;
|
||||
hidden?: boolean;
|
||||
}
|
||||
export declare const assertFieldAppearanceOptions: (options?: FieldAppearanceOptions | undefined) => void;
|
||||
/**
|
||||
* Represents a field of a [[PDFForm]].
|
||||
*
|
||||
* This class is effectively abstract. All fields in a [[PDFForm]] will
|
||||
* actually be an instance of a subclass of this class.
|
||||
*
|
||||
* Note that each field in a PDF is represented by a single field object.
|
||||
* However, a given field object may be rendered at multiple locations within
|
||||
* the document (across one or more pages). The rendering of a field is
|
||||
* controlled by its widgets. Each widget causes its field to be displayed at a
|
||||
* particular location in the document.
|
||||
*
|
||||
* Most of the time each field in a PDF has only a single widget, and thus is
|
||||
* only rendered once. However, if a field is rendered multiple times, it will
|
||||
* have multiple widgets - one for each location it is rendered.
|
||||
*
|
||||
* This abstraction of field objects and widgets is defined in the PDF
|
||||
* specification and dictates how PDF files store fields and where they are
|
||||
* to be rendered.
|
||||
*/
|
||||
export default class PDFField {
|
||||
/** The low-level PDFAcroTerminal wrapped by this field. */
|
||||
readonly acroField: PDFAcroTerminal;
|
||||
/** The unique reference assigned to this field within the document. */
|
||||
readonly ref: PDFRef;
|
||||
/** The document to which this field belongs. */
|
||||
readonly doc: PDFDocument;
|
||||
protected constructor(acroField: PDFAcroTerminal, ref: PDFRef, doc: PDFDocument);
|
||||
/**
|
||||
* Get the fully qualified name of this field. For example:
|
||||
* ```js
|
||||
* const fields = form.getFields()
|
||||
* fields.forEach(field => {
|
||||
* const name = field.getName()
|
||||
* console.log('Field name:', name)
|
||||
* })
|
||||
* ```
|
||||
* Note that PDF fields are structured as a tree. Each field is the
|
||||
* descendent of a series of ancestor nodes all the way up to the form node,
|
||||
* which is always the root of the tree. Each node in the tree (except for
|
||||
* the form node) has a partial name. Partial names can be composed of any
|
||||
* unicode characters except a period (`.`). The fully qualified name of a
|
||||
* field is composed of the partial names of all its ancestors joined
|
||||
* with periods. This means that splitting the fully qualified name on
|
||||
* periods and taking the last element of the resulting array will give you
|
||||
* the partial name of a specific field.
|
||||
* @returns The fully qualified name of this field.
|
||||
*/
|
||||
getName(): string;
|
||||
/**
|
||||
* Returns `true` if this field is read only. This means that PDF readers
|
||||
* will not allow users to interact with the field or change its value. See
|
||||
* [[PDFField.enableReadOnly]] and [[PDFField.disableReadOnly]].
|
||||
* For example:
|
||||
* ```js
|
||||
* const field = form.getField('some.field')
|
||||
* if (field.isReadOnly()) console.log('Read only is enabled')
|
||||
* ```
|
||||
* @returns Whether or not this is a read only field.
|
||||
*/
|
||||
isReadOnly(): boolean;
|
||||
/**
|
||||
* Prevent PDF readers from allowing users to interact with this field or
|
||||
* change its value. The field will not respond to mouse or keyboard input.
|
||||
* For example:
|
||||
* ```js
|
||||
* const field = form.getField('some.field')
|
||||
* field.enableReadOnly()
|
||||
* ```
|
||||
* Useful for fields whose values are computed, imported from a database, or
|
||||
* prefilled by software before being displayed to the user.
|
||||
*/
|
||||
enableReadOnly(): void;
|
||||
/**
|
||||
* Allow users to interact with this field and change its value in PDF
|
||||
* readers via mouse and keyboard input. For example:
|
||||
* ```js
|
||||
* const field = form.getField('some.field')
|
||||
* field.disableReadOnly()
|
||||
* ```
|
||||
*/
|
||||
disableReadOnly(): void;
|
||||
/**
|
||||
* Returns `true` if this field must have a value when the form is submitted.
|
||||
* See [[PDFField.enableRequired]] and [[PDFField.disableRequired]].
|
||||
* For example:
|
||||
* ```js
|
||||
* const field = form.getField('some.field')
|
||||
* if (field.isRequired()) console.log('Field is required')
|
||||
* ```
|
||||
* @returns Whether or not this field is required.
|
||||
*/
|
||||
isRequired(): boolean;
|
||||
/**
|
||||
* Require this field to have a value when the form is submitted.
|
||||
* For example:
|
||||
* ```js
|
||||
* const field = form.getField('some.field')
|
||||
* field.enableRequired()
|
||||
* ```
|
||||
*/
|
||||
enableRequired(): void;
|
||||
/**
|
||||
* Do not require this field to have a value when the form is submitted.
|
||||
* For example:
|
||||
* ```js
|
||||
* const field = form.getField('some.field')
|
||||
* field.disableRequired()
|
||||
* ```
|
||||
*/
|
||||
disableRequired(): void;
|
||||
/**
|
||||
* Returns `true` if this field's value should be exported when the form is
|
||||
* submitted. See [[PDFField.enableExporting]] and
|
||||
* [[PDFField.disableExporting]].
|
||||
* For example:
|
||||
* ```js
|
||||
* const field = form.getField('some.field')
|
||||
* if (field.isExported()) console.log('Exporting is enabled')
|
||||
* ```
|
||||
* @returns Whether or not this field's value should be exported.
|
||||
*/
|
||||
isExported(): boolean;
|
||||
/**
|
||||
* Indicate that this field's value should be exported when the form is
|
||||
* submitted in a PDF reader. For example:
|
||||
* ```js
|
||||
* const field = form.getField('some.field')
|
||||
* field.enableExporting()
|
||||
* ```
|
||||
*/
|
||||
enableExporting(): void;
|
||||
/**
|
||||
* Indicate that this field's value should **not** be exported when the form
|
||||
* is submitted in a PDF reader. For example:
|
||||
* ```js
|
||||
* const field = form.getField('some.field')
|
||||
* field.disableExporting()
|
||||
* ```
|
||||
*/
|
||||
disableExporting(): void;
|
||||
/** @ignore */
|
||||
needsAppearancesUpdate(): boolean;
|
||||
/** @ignore */
|
||||
defaultUpdateAppearances(_font: PDFFont): void;
|
||||
protected markAsDirty(): void;
|
||||
protected markAsClean(): void;
|
||||
protected isDirty(): boolean;
|
||||
protected createWidget(options: {
|
||||
x: number;
|
||||
y: number;
|
||||
width: number;
|
||||
height: number;
|
||||
textColor?: Color;
|
||||
backgroundColor?: Color;
|
||||
borderColor?: Color;
|
||||
borderWidth: number;
|
||||
rotate: Rotation;
|
||||
caption?: string;
|
||||
hidden?: boolean;
|
||||
page?: PDFRef;
|
||||
}): PDFWidgetAnnotation;
|
||||
protected updateWidgetAppearanceWithFont(widget: PDFWidgetAnnotation, font: PDFFont, { normal, rollover, down }: AppearanceMapping<PDFOperator[]>): void;
|
||||
protected updateOnOffWidgetAppearance(widget: PDFWidgetAnnotation, onValue: PDFName, { normal, rollover, down, }: AppearanceMapping<{
|
||||
on: PDFOperator[];
|
||||
off: PDFOperator[];
|
||||
}>): void;
|
||||
protected updateWidgetAppearances(widget: PDFWidgetAnnotation, { normal, rollover, down }: AppearanceMapping<PDFRef | PDFDict>): void;
|
||||
private createAppearanceStream;
|
||||
/**
|
||||
* Create a FormXObject of the supplied image and add it to context.
|
||||
* The FormXObject size is calculated based on the widget (including
|
||||
* the alignment).
|
||||
* @param widget The widget that should display the image.
|
||||
* @param alignment The alignment of the image.
|
||||
* @param image The image that should be displayed.
|
||||
* @returns The ref for the FormXObject that was added to the context.
|
||||
*/
|
||||
protected createImageAppearanceStream(widget: PDFWidgetAnnotation, image: PDFImage, alignment: ImageAlignment): PDFRef;
|
||||
private createAppearanceDict;
|
||||
}
|
||||
//# sourceMappingURL=PDFField.d.ts.map
|
||||
1
node_modules/pdf-lib/es/api/form/PDFField.d.ts.map
generated
vendored
Normal file
1
node_modules/pdf-lib/es/api/form/PDFField.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"PDFField.d.ts","sourceRoot":"","sources":["../../../src/api/form/PDFField.ts"],"names":[],"mappings":"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"}
|
||||
381
node_modules/pdf-lib/es/api/form/PDFField.js
generated
vendored
Normal file
381
node_modules/pdf-lib/es/api/form/PDFField.js
generated
vendored
Normal file
@@ -0,0 +1,381 @@
|
||||
import { __assign, __spreadArrays } from "tslib";
|
||||
import PDFDocument from "../PDFDocument";
|
||||
import { colorToComponents, setFillingColor } from "../colors";
|
||||
import { toDegrees, rotateRectangle, reduceRotation, adjustDimsForRotation, degrees, } from "../rotations";
|
||||
import { PDFRef, PDFWidgetAnnotation, PDFName, MethodNotImplementedError, AcroFieldFlags, PDFAcroTerminal, AnnotationFlags, } from "../../core";
|
||||
import { assertIs, assertMultiple, assertOrUndefined } from "../../utils";
|
||||
import { ImageAlignment } from '../image';
|
||||
import { drawImage, rotateInPlace } from '../operations';
|
||||
export var assertFieldAppearanceOptions = function (options) {
|
||||
assertOrUndefined(options === null || options === void 0 ? void 0 : options.x, 'options.x', ['number']);
|
||||
assertOrUndefined(options === null || options === void 0 ? void 0 : options.y, 'options.y', ['number']);
|
||||
assertOrUndefined(options === null || options === void 0 ? void 0 : options.width, 'options.width', ['number']);
|
||||
assertOrUndefined(options === null || options === void 0 ? void 0 : options.height, 'options.height', ['number']);
|
||||
assertOrUndefined(options === null || options === void 0 ? void 0 : options.textColor, 'options.textColor', [
|
||||
[Object, 'Color'],
|
||||
]);
|
||||
assertOrUndefined(options === null || options === void 0 ? void 0 : options.backgroundColor, 'options.backgroundColor', [
|
||||
[Object, 'Color'],
|
||||
]);
|
||||
assertOrUndefined(options === null || options === void 0 ? void 0 : options.borderColor, 'options.borderColor', [
|
||||
[Object, 'Color'],
|
||||
]);
|
||||
assertOrUndefined(options === null || options === void 0 ? void 0 : options.borderWidth, 'options.borderWidth', ['number']);
|
||||
assertOrUndefined(options === null || options === void 0 ? void 0 : options.rotate, 'options.rotate', [[Object, 'Rotation']]);
|
||||
};
|
||||
/**
|
||||
* Represents a field of a [[PDFForm]].
|
||||
*
|
||||
* This class is effectively abstract. All fields in a [[PDFForm]] will
|
||||
* actually be an instance of a subclass of this class.
|
||||
*
|
||||
* Note that each field in a PDF is represented by a single field object.
|
||||
* However, a given field object may be rendered at multiple locations within
|
||||
* the document (across one or more pages). The rendering of a field is
|
||||
* controlled by its widgets. Each widget causes its field to be displayed at a
|
||||
* particular location in the document.
|
||||
*
|
||||
* Most of the time each field in a PDF has only a single widget, and thus is
|
||||
* only rendered once. However, if a field is rendered multiple times, it will
|
||||
* have multiple widgets - one for each location it is rendered.
|
||||
*
|
||||
* This abstraction of field objects and widgets is defined in the PDF
|
||||
* specification and dictates how PDF files store fields and where they are
|
||||
* to be rendered.
|
||||
*/
|
||||
var PDFField = /** @class */ (function () {
|
||||
function PDFField(acroField, ref, doc) {
|
||||
assertIs(acroField, 'acroField', [[PDFAcroTerminal, 'PDFAcroTerminal']]);
|
||||
assertIs(ref, 'ref', [[PDFRef, 'PDFRef']]);
|
||||
assertIs(doc, 'doc', [[PDFDocument, 'PDFDocument']]);
|
||||
this.acroField = acroField;
|
||||
this.ref = ref;
|
||||
this.doc = doc;
|
||||
}
|
||||
/**
|
||||
* Get the fully qualified name of this field. For example:
|
||||
* ```js
|
||||
* const fields = form.getFields()
|
||||
* fields.forEach(field => {
|
||||
* const name = field.getName()
|
||||
* console.log('Field name:', name)
|
||||
* })
|
||||
* ```
|
||||
* Note that PDF fields are structured as a tree. Each field is the
|
||||
* descendent of a series of ancestor nodes all the way up to the form node,
|
||||
* which is always the root of the tree. Each node in the tree (except for
|
||||
* the form node) has a partial name. Partial names can be composed of any
|
||||
* unicode characters except a period (`.`). The fully qualified name of a
|
||||
* field is composed of the partial names of all its ancestors joined
|
||||
* with periods. This means that splitting the fully qualified name on
|
||||
* periods and taking the last element of the resulting array will give you
|
||||
* the partial name of a specific field.
|
||||
* @returns The fully qualified name of this field.
|
||||
*/
|
||||
PDFField.prototype.getName = function () {
|
||||
var _a;
|
||||
return (_a = this.acroField.getFullyQualifiedName()) !== null && _a !== void 0 ? _a : '';
|
||||
};
|
||||
/**
|
||||
* Returns `true` if this field is read only. This means that PDF readers
|
||||
* will not allow users to interact with the field or change its value. See
|
||||
* [[PDFField.enableReadOnly]] and [[PDFField.disableReadOnly]].
|
||||
* For example:
|
||||
* ```js
|
||||
* const field = form.getField('some.field')
|
||||
* if (field.isReadOnly()) console.log('Read only is enabled')
|
||||
* ```
|
||||
* @returns Whether or not this is a read only field.
|
||||
*/
|
||||
PDFField.prototype.isReadOnly = function () {
|
||||
return this.acroField.hasFlag(AcroFieldFlags.ReadOnly);
|
||||
};
|
||||
/**
|
||||
* Prevent PDF readers from allowing users to interact with this field or
|
||||
* change its value. The field will not respond to mouse or keyboard input.
|
||||
* For example:
|
||||
* ```js
|
||||
* const field = form.getField('some.field')
|
||||
* field.enableReadOnly()
|
||||
* ```
|
||||
* Useful for fields whose values are computed, imported from a database, or
|
||||
* prefilled by software before being displayed to the user.
|
||||
*/
|
||||
PDFField.prototype.enableReadOnly = function () {
|
||||
this.acroField.setFlagTo(AcroFieldFlags.ReadOnly, true);
|
||||
};
|
||||
/**
|
||||
* Allow users to interact with this field and change its value in PDF
|
||||
* readers via mouse and keyboard input. For example:
|
||||
* ```js
|
||||
* const field = form.getField('some.field')
|
||||
* field.disableReadOnly()
|
||||
* ```
|
||||
*/
|
||||
PDFField.prototype.disableReadOnly = function () {
|
||||
this.acroField.setFlagTo(AcroFieldFlags.ReadOnly, false);
|
||||
};
|
||||
/**
|
||||
* Returns `true` if this field must have a value when the form is submitted.
|
||||
* See [[PDFField.enableRequired]] and [[PDFField.disableRequired]].
|
||||
* For example:
|
||||
* ```js
|
||||
* const field = form.getField('some.field')
|
||||
* if (field.isRequired()) console.log('Field is required')
|
||||
* ```
|
||||
* @returns Whether or not this field is required.
|
||||
*/
|
||||
PDFField.prototype.isRequired = function () {
|
||||
return this.acroField.hasFlag(AcroFieldFlags.Required);
|
||||
};
|
||||
/**
|
||||
* Require this field to have a value when the form is submitted.
|
||||
* For example:
|
||||
* ```js
|
||||
* const field = form.getField('some.field')
|
||||
* field.enableRequired()
|
||||
* ```
|
||||
*/
|
||||
PDFField.prototype.enableRequired = function () {
|
||||
this.acroField.setFlagTo(AcroFieldFlags.Required, true);
|
||||
};
|
||||
/**
|
||||
* Do not require this field to have a value when the form is submitted.
|
||||
* For example:
|
||||
* ```js
|
||||
* const field = form.getField('some.field')
|
||||
* field.disableRequired()
|
||||
* ```
|
||||
*/
|
||||
PDFField.prototype.disableRequired = function () {
|
||||
this.acroField.setFlagTo(AcroFieldFlags.Required, false);
|
||||
};
|
||||
/**
|
||||
* Returns `true` if this field's value should be exported when the form is
|
||||
* submitted. See [[PDFField.enableExporting]] and
|
||||
* [[PDFField.disableExporting]].
|
||||
* For example:
|
||||
* ```js
|
||||
* const field = form.getField('some.field')
|
||||
* if (field.isExported()) console.log('Exporting is enabled')
|
||||
* ```
|
||||
* @returns Whether or not this field's value should be exported.
|
||||
*/
|
||||
PDFField.prototype.isExported = function () {
|
||||
return !this.acroField.hasFlag(AcroFieldFlags.NoExport);
|
||||
};
|
||||
/**
|
||||
* Indicate that this field's value should be exported when the form is
|
||||
* submitted in a PDF reader. For example:
|
||||
* ```js
|
||||
* const field = form.getField('some.field')
|
||||
* field.enableExporting()
|
||||
* ```
|
||||
*/
|
||||
PDFField.prototype.enableExporting = function () {
|
||||
this.acroField.setFlagTo(AcroFieldFlags.NoExport, false);
|
||||
};
|
||||
/**
|
||||
* Indicate that this field's value should **not** be exported when the form
|
||||
* is submitted in a PDF reader. For example:
|
||||
* ```js
|
||||
* const field = form.getField('some.field')
|
||||
* field.disableExporting()
|
||||
* ```
|
||||
*/
|
||||
PDFField.prototype.disableExporting = function () {
|
||||
this.acroField.setFlagTo(AcroFieldFlags.NoExport, true);
|
||||
};
|
||||
/** @ignore */
|
||||
PDFField.prototype.needsAppearancesUpdate = function () {
|
||||
throw new MethodNotImplementedError(this.constructor.name, 'needsAppearancesUpdate');
|
||||
};
|
||||
/** @ignore */
|
||||
PDFField.prototype.defaultUpdateAppearances = function (_font) {
|
||||
throw new MethodNotImplementedError(this.constructor.name, 'defaultUpdateAppearances');
|
||||
};
|
||||
PDFField.prototype.markAsDirty = function () {
|
||||
this.doc.getForm().markFieldAsDirty(this.ref);
|
||||
};
|
||||
PDFField.prototype.markAsClean = function () {
|
||||
this.doc.getForm().markFieldAsClean(this.ref);
|
||||
};
|
||||
PDFField.prototype.isDirty = function () {
|
||||
return this.doc.getForm().fieldIsDirty(this.ref);
|
||||
};
|
||||
PDFField.prototype.createWidget = function (options) {
|
||||
var _a;
|
||||
var textColor = options.textColor;
|
||||
var backgroundColor = options.backgroundColor;
|
||||
var borderColor = options.borderColor;
|
||||
var borderWidth = options.borderWidth;
|
||||
var degreesAngle = toDegrees(options.rotate);
|
||||
var caption = options.caption;
|
||||
var x = options.x;
|
||||
var y = options.y;
|
||||
var width = options.width + borderWidth;
|
||||
var height = options.height + borderWidth;
|
||||
var hidden = Boolean(options.hidden);
|
||||
var pageRef = options.page;
|
||||
assertMultiple(degreesAngle, 'degreesAngle', 90);
|
||||
// Create a widget for this field
|
||||
var widget = PDFWidgetAnnotation.create(this.doc.context, this.ref);
|
||||
// Set widget properties
|
||||
var rect = rotateRectangle({ x: x, y: y, width: width, height: height }, borderWidth, degreesAngle);
|
||||
widget.setRectangle(rect);
|
||||
if (pageRef)
|
||||
widget.setP(pageRef);
|
||||
var ac = widget.getOrCreateAppearanceCharacteristics();
|
||||
if (backgroundColor) {
|
||||
ac.setBackgroundColor(colorToComponents(backgroundColor));
|
||||
}
|
||||
ac.setRotation(degreesAngle);
|
||||
if (caption)
|
||||
ac.setCaptions({ normal: caption });
|
||||
if (borderColor)
|
||||
ac.setBorderColor(colorToComponents(borderColor));
|
||||
var bs = widget.getOrCreateBorderStyle();
|
||||
if (borderWidth !== undefined)
|
||||
bs.setWidth(borderWidth);
|
||||
widget.setFlagTo(AnnotationFlags.Print, true);
|
||||
widget.setFlagTo(AnnotationFlags.Hidden, hidden);
|
||||
widget.setFlagTo(AnnotationFlags.Invisible, false);
|
||||
// Set acrofield properties
|
||||
if (textColor) {
|
||||
var da = (_a = this.acroField.getDefaultAppearance()) !== null && _a !== void 0 ? _a : '';
|
||||
var newDa = da + '\n' + setFillingColor(textColor).toString();
|
||||
this.acroField.setDefaultAppearance(newDa);
|
||||
}
|
||||
return widget;
|
||||
};
|
||||
PDFField.prototype.updateWidgetAppearanceWithFont = function (widget, font, _a) {
|
||||
var normal = _a.normal, rollover = _a.rollover, down = _a.down;
|
||||
this.updateWidgetAppearances(widget, {
|
||||
normal: this.createAppearanceStream(widget, normal, font),
|
||||
rollover: rollover && this.createAppearanceStream(widget, rollover, font),
|
||||
down: down && this.createAppearanceStream(widget, down, font),
|
||||
});
|
||||
};
|
||||
PDFField.prototype.updateOnOffWidgetAppearance = function (widget, onValue, _a) {
|
||||
var normal = _a.normal, rollover = _a.rollover, down = _a.down;
|
||||
this.updateWidgetAppearances(widget, {
|
||||
normal: this.createAppearanceDict(widget, normal, onValue),
|
||||
rollover: rollover && this.createAppearanceDict(widget, rollover, onValue),
|
||||
down: down && this.createAppearanceDict(widget, down, onValue),
|
||||
});
|
||||
};
|
||||
PDFField.prototype.updateWidgetAppearances = function (widget, _a) {
|
||||
var normal = _a.normal, rollover = _a.rollover, down = _a.down;
|
||||
widget.setNormalAppearance(normal);
|
||||
if (rollover) {
|
||||
widget.setRolloverAppearance(rollover);
|
||||
}
|
||||
else {
|
||||
widget.removeRolloverAppearance();
|
||||
}
|
||||
if (down) {
|
||||
widget.setDownAppearance(down);
|
||||
}
|
||||
else {
|
||||
widget.removeDownAppearance();
|
||||
}
|
||||
};
|
||||
// // TODO: Do we need to do this...?
|
||||
// private foo(font: PDFFont, dict: PDFDict) {
|
||||
// if (!dict.lookup(PDFName.of('DR'))) {
|
||||
// dict.set(PDFName.of('DR'), dict.context.obj({}));
|
||||
// }
|
||||
// const DR = dict.lookup(PDFName.of('DR'), PDFDict);
|
||||
// if (!DR.lookup(PDFName.of('Font'))) {
|
||||
// DR.set(PDFName.of('Font'), dict.context.obj({}));
|
||||
// }
|
||||
// const Font = DR.lookup(PDFName.of('Font'), PDFDict);
|
||||
// Font.set(PDFName.of(font.name), font.ref);
|
||||
// }
|
||||
PDFField.prototype.createAppearanceStream = function (widget, appearance, font) {
|
||||
var _a;
|
||||
var context = this.acroField.dict.context;
|
||||
var _b = widget.getRectangle(), width = _b.width, height = _b.height;
|
||||
// TODO: Do we need to do this...?
|
||||
// if (font) {
|
||||
// this.foo(font, widget.dict);
|
||||
// this.foo(font, this.doc.getForm().acroForm.dict);
|
||||
// }
|
||||
// END TODO
|
||||
var Resources = font && { Font: (_a = {}, _a[font.name] = font.ref, _a) };
|
||||
var stream = context.formXObject(appearance, {
|
||||
Resources: Resources,
|
||||
BBox: context.obj([0, 0, width, height]),
|
||||
Matrix: context.obj([1, 0, 0, 1, 0, 0]),
|
||||
});
|
||||
var streamRef = context.register(stream);
|
||||
return streamRef;
|
||||
};
|
||||
/**
|
||||
* Create a FormXObject of the supplied image and add it to context.
|
||||
* The FormXObject size is calculated based on the widget (including
|
||||
* the alignment).
|
||||
* @param widget The widget that should display the image.
|
||||
* @param alignment The alignment of the image.
|
||||
* @param image The image that should be displayed.
|
||||
* @returns The ref for the FormXObject that was added to the context.
|
||||
*/
|
||||
PDFField.prototype.createImageAppearanceStream = function (widget, image, alignment) {
|
||||
// NOTE: This implementation doesn't handle image borders.
|
||||
// NOTE: Acrobat seems to resize the image (maybe even skewing its aspect
|
||||
// ratio) to fit perfectly within the widget's rectangle. This method
|
||||
// does not currently do that. Should there be an option for that?
|
||||
var _a;
|
||||
var _b;
|
||||
var context = this.acroField.dict.context;
|
||||
var rectangle = widget.getRectangle();
|
||||
var ap = widget.getAppearanceCharacteristics();
|
||||
var bs = widget.getBorderStyle();
|
||||
var borderWidth = (_b = bs === null || bs === void 0 ? void 0 : bs.getWidth()) !== null && _b !== void 0 ? _b : 0;
|
||||
var rotation = reduceRotation(ap === null || ap === void 0 ? void 0 : ap.getRotation());
|
||||
var rotate = rotateInPlace(__assign(__assign({}, rectangle), { rotation: rotation }));
|
||||
var adj = adjustDimsForRotation(rectangle, rotation);
|
||||
var imageDims = image.scaleToFit(adj.width - borderWidth * 2, adj.height - borderWidth * 2);
|
||||
// Support borders on images and maybe other properties
|
||||
var options = {
|
||||
x: borderWidth,
|
||||
y: borderWidth,
|
||||
width: imageDims.width,
|
||||
height: imageDims.height,
|
||||
//
|
||||
rotate: degrees(0),
|
||||
xSkew: degrees(0),
|
||||
ySkew: degrees(0),
|
||||
};
|
||||
if (alignment === ImageAlignment.Center) {
|
||||
options.x += (adj.width - borderWidth * 2) / 2 - imageDims.width / 2;
|
||||
options.y += (adj.height - borderWidth * 2) / 2 - imageDims.height / 2;
|
||||
}
|
||||
else if (alignment === ImageAlignment.Right) {
|
||||
options.x = adj.width - borderWidth - imageDims.width;
|
||||
options.y = adj.height - borderWidth - imageDims.height;
|
||||
}
|
||||
var imageName = this.doc.context.addRandomSuffix('Image', 10);
|
||||
var appearance = __spreadArrays(rotate, drawImage(imageName, options));
|
||||
////////////
|
||||
var Resources = { XObject: (_a = {}, _a[imageName] = image.ref, _a) };
|
||||
var stream = context.formXObject(appearance, {
|
||||
Resources: Resources,
|
||||
BBox: context.obj([0, 0, rectangle.width, rectangle.height]),
|
||||
Matrix: context.obj([1, 0, 0, 1, 0, 0]),
|
||||
});
|
||||
return context.register(stream);
|
||||
};
|
||||
PDFField.prototype.createAppearanceDict = function (widget, appearance, onValue) {
|
||||
var context = this.acroField.dict.context;
|
||||
var onStreamRef = this.createAppearanceStream(widget, appearance.on);
|
||||
var offStreamRef = this.createAppearanceStream(widget, appearance.off);
|
||||
var appearanceDict = context.obj({});
|
||||
appearanceDict.set(onValue, onStreamRef);
|
||||
appearanceDict.set(PDFName.of('Off'), offStreamRef);
|
||||
return appearanceDict;
|
||||
};
|
||||
return PDFField;
|
||||
}());
|
||||
export default PDFField;
|
||||
//# sourceMappingURL=PDFField.js.map
|
||||
1
node_modules/pdf-lib/es/api/form/PDFField.js.map
generated
vendored
Normal file
1
node_modules/pdf-lib/es/api/form/PDFField.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
412
node_modules/pdf-lib/es/api/form/PDFForm.d.ts
generated
vendored
Normal file
412
node_modules/pdf-lib/es/api/form/PDFForm.d.ts
generated
vendored
Normal file
@@ -0,0 +1,412 @@
|
||||
import PDFDocument from "../PDFDocument";
|
||||
import PDFField from "./PDFField";
|
||||
import PDFButton from "./PDFButton";
|
||||
import PDFCheckBox from "./PDFCheckBox";
|
||||
import PDFDropdown from "./PDFDropdown";
|
||||
import PDFOptionList from "./PDFOptionList";
|
||||
import PDFRadioGroup from "./PDFRadioGroup";
|
||||
import PDFSignature from "./PDFSignature";
|
||||
import PDFTextField from "./PDFTextField";
|
||||
import PDFFont from "../PDFFont";
|
||||
import { PDFAcroForm, PDFRef } from "../../core";
|
||||
export interface FlattenOptions {
|
||||
updateFieldAppearances: boolean;
|
||||
}
|
||||
/**
|
||||
* Represents the interactive form of a [[PDFDocument]].
|
||||
*
|
||||
* Interactive forms (sometimes called _AcroForms_) are collections of fields
|
||||
* designed to gather information from a user. A PDF document may contains any
|
||||
* number of fields that appear on various pages, all of which make up a single,
|
||||
* global interactive form spanning the entire document. This means that
|
||||
* instances of [[PDFDocument]] shall contain at most one [[PDFForm]].
|
||||
*
|
||||
* The fields of an interactive form are represented by [[PDFField]] instances.
|
||||
*/
|
||||
export default class PDFForm {
|
||||
/**
|
||||
* > **NOTE:** You probably don't want to call this method directly. Instead,
|
||||
* > consider using the [[PDFDocument.getForm]] method, which will create an
|
||||
* > instance of [[PDFForm]] for you.
|
||||
*
|
||||
* Create an instance of [[PDFForm]] from an existing acroForm and embedder
|
||||
*
|
||||
* @param acroForm The underlying `PDFAcroForm` for this form.
|
||||
* @param doc The document to which the form will belong.
|
||||
*/
|
||||
static of: (acroForm: PDFAcroForm, doc: PDFDocument) => PDFForm;
|
||||
/** The low-level PDFAcroForm wrapped by this form. */
|
||||
readonly acroForm: PDFAcroForm;
|
||||
/** The document to which this form belongs. */
|
||||
readonly doc: PDFDocument;
|
||||
private readonly dirtyFields;
|
||||
private readonly defaultFontCache;
|
||||
private constructor();
|
||||
/**
|
||||
* Returns `true` if this [[PDFForm]] has XFA data. Most PDFs with form
|
||||
* fields do not use XFA as it is not widely supported by PDF readers.
|
||||
*
|
||||
* > `pdf-lib` does not support creation, modification, or reading of XFA
|
||||
* > fields.
|
||||
*
|
||||
* For example:
|
||||
* ```js
|
||||
* const form = pdfDoc.getForm()
|
||||
* if (form.hasXFA()) console.log('PDF has XFA data')
|
||||
* ```
|
||||
* @returns Whether or not this form has XFA data.
|
||||
*/
|
||||
hasXFA(): boolean;
|
||||
/**
|
||||
* Disconnect the XFA data from this [[PDFForm]] (if any exists). This will
|
||||
* force readers to fallback to standard fields if the [[PDFDocument]]
|
||||
* contains any. For example:
|
||||
*
|
||||
* For example:
|
||||
* ```js
|
||||
* const form = pdfDoc.getForm()
|
||||
* form.deleteXFA()
|
||||
* ```
|
||||
*/
|
||||
deleteXFA(): void;
|
||||
/**
|
||||
* Get all fields contained in this [[PDFForm]]. For example:
|
||||
* ```js
|
||||
* const form = pdfDoc.getForm()
|
||||
* const fields = form.getFields()
|
||||
* fields.forEach(field => {
|
||||
* const type = field.constructor.name
|
||||
* const name = field.getName()
|
||||
* console.log(`${type}: ${name}`)
|
||||
* })
|
||||
* ```
|
||||
* @returns An array of all fields in this form.
|
||||
*/
|
||||
getFields(): PDFField[];
|
||||
/**
|
||||
* Get the field in this [[PDFForm]] with the given name. For example:
|
||||
* ```js
|
||||
* const form = pdfDoc.getForm()
|
||||
* const field = form.getFieldMaybe('Page1.Foo.Bar[0]')
|
||||
* if (field) console.log('Field exists!')
|
||||
* ```
|
||||
* @param name A fully qualified field name.
|
||||
* @returns The field with the specified name, if one exists.
|
||||
*/
|
||||
getFieldMaybe(name: string): PDFField | undefined;
|
||||
/**
|
||||
* Get the field in this [[PDFForm]] with the given name. For example:
|
||||
* ```js
|
||||
* const form = pdfDoc.getForm()
|
||||
* const field = form.getField('Page1.Foo.Bar[0]')
|
||||
* ```
|
||||
* If no field exists with the provided name, an error will be thrown.
|
||||
* @param name A fully qualified field name.
|
||||
* @returns The field with the specified name.
|
||||
*/
|
||||
getField(name: string): PDFField;
|
||||
/**
|
||||
* Get the button field in this [[PDFForm]] with the given name. For example:
|
||||
* ```js
|
||||
* const form = pdfDoc.getForm()
|
||||
* const button = form.getButton('Page1.Foo.Button[0]')
|
||||
* ```
|
||||
* An error will be thrown if no field exists with the provided name, or if
|
||||
* the field exists but is not a button.
|
||||
* @param name A fully qualified button name.
|
||||
* @returns The button with the specified name.
|
||||
*/
|
||||
getButton(name: string): PDFButton;
|
||||
/**
|
||||
* Get the check box field in this [[PDFForm]] with the given name.
|
||||
* For example:
|
||||
* ```js
|
||||
* const form = pdfDoc.getForm()
|
||||
* const checkBox = form.getCheckBox('Page1.Foo.CheckBox[0]')
|
||||
* checkBox.check()
|
||||
* ```
|
||||
* An error will be thrown if no field exists with the provided name, or if
|
||||
* the field exists but is not a check box.
|
||||
* @param name A fully qualified check box name.
|
||||
* @returns The check box with the specified name.
|
||||
*/
|
||||
getCheckBox(name: string): PDFCheckBox;
|
||||
/**
|
||||
* Get the dropdown field in this [[PDFForm]] with the given name.
|
||||
* For example:
|
||||
* ```js
|
||||
* const form = pdfDoc.getForm()
|
||||
* const dropdown = form.getDropdown('Page1.Foo.Dropdown[0]')
|
||||
* const options = dropdown.getOptions()
|
||||
* dropdown.select(options[0])
|
||||
* ```
|
||||
* An error will be thrown if no field exists with the provided name, or if
|
||||
* the field exists but is not a dropdown.
|
||||
* @param name A fully qualified dropdown name.
|
||||
* @returns The dropdown with the specified name.
|
||||
*/
|
||||
getDropdown(name: string): PDFDropdown;
|
||||
/**
|
||||
* Get the option list field in this [[PDFForm]] with the given name.
|
||||
* For example:
|
||||
* ```js
|
||||
* const form = pdfDoc.getForm()
|
||||
* const optionList = form.getOptionList('Page1.Foo.OptionList[0]')
|
||||
* const options = optionList.getOptions()
|
||||
* optionList.select(options[0])
|
||||
* ```
|
||||
* An error will be thrown if no field exists with the provided name, or if
|
||||
* the field exists but is not an option list.
|
||||
* @param name A fully qualified option list name.
|
||||
* @returns The option list with the specified name.
|
||||
*/
|
||||
getOptionList(name: string): PDFOptionList;
|
||||
/**
|
||||
* Get the radio group field in this [[PDFForm]] with the given name.
|
||||
* For example:
|
||||
* ```js
|
||||
* const form = pdfDoc.getForm()
|
||||
* const radioGroup = form.getRadioGroup('Page1.Foo.RadioGroup[0]')
|
||||
* const options = radioGroup.getOptions()
|
||||
* radioGroup.select(options[0])
|
||||
* ```
|
||||
* An error will be thrown if no field exists with the provided name, or if
|
||||
* the field exists but is not a radio group.
|
||||
* @param name A fully qualified radio group name.
|
||||
* @returns The radio group with the specified name.
|
||||
*/
|
||||
getRadioGroup(name: string): PDFRadioGroup;
|
||||
/**
|
||||
* Get the signature field in this [[PDFForm]] with the given name.
|
||||
* For example:
|
||||
* ```js
|
||||
* const form = pdfDoc.getForm()
|
||||
* const signature = form.getSignature('Page1.Foo.Signature[0]')
|
||||
* ```
|
||||
* An error will be thrown if no field exists with the provided name, or if
|
||||
* the field exists but is not a signature.
|
||||
* @param name A fully qualified signature name.
|
||||
* @returns The signature with the specified name.
|
||||
*/
|
||||
getSignature(name: string): PDFSignature;
|
||||
/**
|
||||
* Get the text field in this [[PDFForm]] with the given name.
|
||||
* For example:
|
||||
* ```js
|
||||
* const form = pdfDoc.getForm()
|
||||
* const textField = form.getTextField('Page1.Foo.TextField[0]')
|
||||
* textField.setText('Are you designed to act or to be acted upon?')
|
||||
* ```
|
||||
* An error will be thrown if no field exists with the provided name, or if
|
||||
* the field exists but is not a text field.
|
||||
* @param name A fully qualified text field name.
|
||||
* @returns The text field with the specified name.
|
||||
*/
|
||||
getTextField(name: string): PDFTextField;
|
||||
/**
|
||||
* Create a new button field in this [[PDFForm]] with the given name.
|
||||
* For example:
|
||||
* ```js
|
||||
* const font = await pdfDoc.embedFont(StandardFonts.Helvetica)
|
||||
* const page = pdfDoc.addPage()
|
||||
*
|
||||
* const form = pdfDoc.getForm()
|
||||
* const button = form.createButton('cool.new.button')
|
||||
*
|
||||
* button.addToPage('Do Stuff', font, page)
|
||||
* ```
|
||||
* An error will be thrown if a field already exists with the provided name.
|
||||
* @param name The fully qualified name for the new button.
|
||||
* @returns The new button field.
|
||||
*/
|
||||
createButton(name: string): PDFButton;
|
||||
/**
|
||||
* Create a new check box field in this [[PDFForm]] with the given name.
|
||||
* For example:
|
||||
* ```js
|
||||
* const font = await pdfDoc.embedFont(StandardFonts.Helvetica)
|
||||
* const page = pdfDoc.addPage()
|
||||
*
|
||||
* const form = pdfDoc.getForm()
|
||||
* const checkBox = form.createCheckBox('cool.new.checkBox')
|
||||
*
|
||||
* checkBox.addToPage(page)
|
||||
* ```
|
||||
* An error will be thrown if a field already exists with the provided name.
|
||||
* @param name The fully qualified name for the new check box.
|
||||
* @returns The new check box field.
|
||||
*/
|
||||
createCheckBox(name: string): PDFCheckBox;
|
||||
/**
|
||||
* Create a new dropdown field in this [[PDFForm]] with the given name.
|
||||
* For example:
|
||||
* ```js
|
||||
* const font = await pdfDoc.embedFont(StandardFonts.Helvetica)
|
||||
* const page = pdfDoc.addPage()
|
||||
*
|
||||
* const form = pdfDoc.getForm()
|
||||
* const dropdown = form.createDropdown('cool.new.dropdown')
|
||||
*
|
||||
* dropdown.addToPage(font, page)
|
||||
* ```
|
||||
* An error will be thrown if a field already exists with the provided name.
|
||||
* @param name The fully qualified name for the new dropdown.
|
||||
* @returns The new dropdown field.
|
||||
*/
|
||||
createDropdown(name: string): PDFDropdown;
|
||||
/**
|
||||
* Create a new option list field in this [[PDFForm]] with the given name.
|
||||
* For example:
|
||||
* ```js
|
||||
* const font = await pdfDoc.embedFont(StandardFonts.Helvetica)
|
||||
* const page = pdfDoc.addPage()
|
||||
*
|
||||
* const form = pdfDoc.getForm()
|
||||
* const optionList = form.createOptionList('cool.new.optionList')
|
||||
*
|
||||
* optionList.addToPage(font, page)
|
||||
* ```
|
||||
* An error will be thrown if a field already exists with the provided name.
|
||||
* @param name The fully qualified name for the new option list.
|
||||
* @returns The new option list field.
|
||||
*/
|
||||
createOptionList(name: string): PDFOptionList;
|
||||
/**
|
||||
* Create a new radio group field in this [[PDFForm]] with the given name.
|
||||
* For example:
|
||||
* ```js
|
||||
* const font = await pdfDoc.embedFont(StandardFonts.Helvetica)
|
||||
* const page = pdfDoc.addPage()
|
||||
*
|
||||
* const form = pdfDoc.getForm()
|
||||
* const radioGroup = form.createRadioGroup('cool.new.radioGroup')
|
||||
*
|
||||
* radioGroup.addOptionToPage('is-dog', page, { y: 0 })
|
||||
* radioGroup.addOptionToPage('is-cat', page, { y: 75 })
|
||||
* ```
|
||||
* An error will be thrown if a field already exists with the provided name.
|
||||
* @param name The fully qualified name for the new radio group.
|
||||
* @returns The new radio group field.
|
||||
*/
|
||||
createRadioGroup(name: string): PDFRadioGroup;
|
||||
/**
|
||||
* Create a new text field in this [[PDFForm]] with the given name.
|
||||
* For example:
|
||||
* ```js
|
||||
* const font = await pdfDoc.embedFont(StandardFonts.Helvetica)
|
||||
* const page = pdfDoc.addPage()
|
||||
*
|
||||
* const form = pdfDoc.getForm()
|
||||
* const textField = form.createTextField('cool.new.textField')
|
||||
*
|
||||
* textField.addToPage(font, page)
|
||||
* ```
|
||||
* An error will be thrown if a field already exists with the provided name.
|
||||
* @param name The fully qualified name for the new radio group.
|
||||
* @returns The new radio group field.
|
||||
*/
|
||||
createTextField(name: string): PDFTextField;
|
||||
/**
|
||||
* Flatten all fields in this [[PDFForm]].
|
||||
*
|
||||
* Flattening a form field will take the current appearance for each of that
|
||||
* field's widgets and make them part of their page's content stream. All form
|
||||
* fields and annotations associated are then removed. Note that once a form
|
||||
* has been flattened its fields can no longer be accessed or edited.
|
||||
*
|
||||
* This operation is often used after filling form fields to ensure a
|
||||
* consistent appearance across different PDF readers and/or printers.
|
||||
* Another common use case is to copy a template document with form fields
|
||||
* into another document. In this scenario you would load the template
|
||||
* document, fill its fields, flatten it, and then copy its pages into the
|
||||
* recipient document - the filled fields will be copied over.
|
||||
*
|
||||
* For example:
|
||||
* ```js
|
||||
* const form = pdfDoc.getForm();
|
||||
* form.flatten();
|
||||
* ```
|
||||
*/
|
||||
flatten(options?: FlattenOptions): void;
|
||||
/**
|
||||
* Remove a field from this [[PDFForm]].
|
||||
*
|
||||
* For example:
|
||||
* ```js
|
||||
* const form = pdfDoc.getForm();
|
||||
* const ageField = form.getFields().find(x => x.getName() === 'Age');
|
||||
* form.removeField(ageField);
|
||||
* ```
|
||||
*/
|
||||
removeField(field: PDFField): void;
|
||||
/**
|
||||
* Update the appearance streams for all widgets of all fields in this
|
||||
* [[PDFForm]]. Appearance streams will only be created for a widget if it
|
||||
* does not have any existing appearance streams, or the field's value has
|
||||
* changed (e.g. by calling [[PDFTextField.setText]] or
|
||||
* [[PDFDropdown.select]]).
|
||||
*
|
||||
* For example:
|
||||
* ```js
|
||||
* const courier = await pdfDoc.embedFont(StandardFonts.Courier)
|
||||
* const form = pdfDoc.getForm()
|
||||
* form.updateFieldAppearances(courier)
|
||||
* ```
|
||||
*
|
||||
* **IMPORTANT:** The default value for the `font` parameter is
|
||||
* [[StandardFonts.Helvetica]]. Note that this is a WinAnsi font. This means
|
||||
* that encoding errors will be thrown if any fields contain text with
|
||||
* characters outside the WinAnsi character set (the latin alphabet).
|
||||
*
|
||||
* Embedding a custom font and passing that as the `font`
|
||||
* parameter allows you to generate appearance streams with non WinAnsi
|
||||
* characters (assuming your custom font supports them).
|
||||
*
|
||||
* > **NOTE:** The [[PDFDocument.save]] method will call this method to
|
||||
* > update appearances automatically if a form was accessed via the
|
||||
* > [[PDFDocument.getForm]] method prior to saving.
|
||||
*
|
||||
* @param font Optionally, the font to use when creating new appearances.
|
||||
*/
|
||||
updateFieldAppearances(font?: PDFFont): void;
|
||||
/**
|
||||
* Mark a field as dirty. This will cause its appearance streams to be
|
||||
* updated by [[PDFForm.updateFieldAppearances]].
|
||||
* ```js
|
||||
* const form = pdfDoc.getForm()
|
||||
* const field = form.getField('foo.bar')
|
||||
* form.markFieldAsDirty(field.ref)
|
||||
* ```
|
||||
* @param fieldRef The reference to the field that should be marked.
|
||||
*/
|
||||
markFieldAsDirty(fieldRef: PDFRef): void;
|
||||
/**
|
||||
* Mark a field as dirty. This will cause its appearance streams to not be
|
||||
* updated by [[PDFForm.updateFieldAppearances]].
|
||||
* ```js
|
||||
* const form = pdfDoc.getForm()
|
||||
* const field = form.getField('foo.bar')
|
||||
* form.markFieldAsClean(field.ref)
|
||||
* ```
|
||||
* @param fieldRef The reference to the field that should be marked.
|
||||
*/
|
||||
markFieldAsClean(fieldRef: PDFRef): void;
|
||||
/**
|
||||
* Returns `true` is the specified field has been marked as dirty.
|
||||
* ```js
|
||||
* const form = pdfDoc.getForm()
|
||||
* const field = form.getField('foo.bar')
|
||||
* if (form.fieldIsDirty(field.ref)) console.log('Field is dirty')
|
||||
* ```
|
||||
* @param fieldRef The reference to the field that should be checked.
|
||||
* @returns Whether or not the specified field is dirty.
|
||||
*/
|
||||
fieldIsDirty(fieldRef: PDFRef): boolean;
|
||||
getDefaultFont(): PDFFont;
|
||||
private findWidgetPage;
|
||||
private findWidgetAppearanceRef;
|
||||
private findOrCreateNonTerminals;
|
||||
private findNonTerminal;
|
||||
private embedDefaultFont;
|
||||
}
|
||||
//# sourceMappingURL=PDFForm.d.ts.map
|
||||
1
node_modules/pdf-lib/es/api/form/PDFForm.d.ts.map
generated
vendored
Normal file
1
node_modules/pdf-lib/es/api/form/PDFForm.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"PDFForm.d.ts","sourceRoot":"","sources":["../../../src/api/form/PDFForm.ts"],"names":[],"mappings":"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"}
|
||||
724
node_modules/pdf-lib/es/api/form/PDFForm.js
generated
vendored
Normal file
724
node_modules/pdf-lib/es/api/form/PDFForm.js
generated
vendored
Normal file
@@ -0,0 +1,724 @@
|
||||
import { __assign, __spreadArrays } from "tslib";
|
||||
import PDFDocument from "../PDFDocument";
|
||||
import PDFButton from "./PDFButton";
|
||||
import PDFCheckBox from "./PDFCheckBox";
|
||||
import PDFDropdown from "./PDFDropdown";
|
||||
import PDFOptionList from "./PDFOptionList";
|
||||
import PDFRadioGroup from "./PDFRadioGroup";
|
||||
import PDFSignature from "./PDFSignature";
|
||||
import PDFTextField from "./PDFTextField";
|
||||
import { NoSuchFieldError, UnexpectedFieldTypeError, FieldAlreadyExistsError, InvalidFieldNamePartError, } from "../errors";
|
||||
import PDFFont from "../PDFFont";
|
||||
import { StandardFonts } from "../StandardFonts";
|
||||
import { rotateInPlace } from "../operations";
|
||||
import { drawObject, popGraphicsState, pushGraphicsState, translate, } from "../operators";
|
||||
import { PDFAcroForm, PDFAcroCheckBox, PDFAcroComboBox, PDFAcroListBox, PDFAcroRadioButton, PDFAcroSignature, PDFAcroText, PDFAcroPushButton, PDFAcroNonTerminal, PDFDict, PDFRef, createPDFAcroFields, PDFName, } from "../../core";
|
||||
import { assertIs, Cache, assertOrUndefined } from "../../utils";
|
||||
/**
|
||||
* Represents the interactive form of a [[PDFDocument]].
|
||||
*
|
||||
* Interactive forms (sometimes called _AcroForms_) are collections of fields
|
||||
* designed to gather information from a user. A PDF document may contains any
|
||||
* number of fields that appear on various pages, all of which make up a single,
|
||||
* global interactive form spanning the entire document. This means that
|
||||
* instances of [[PDFDocument]] shall contain at most one [[PDFForm]].
|
||||
*
|
||||
* The fields of an interactive form are represented by [[PDFField]] instances.
|
||||
*/
|
||||
var PDFForm = /** @class */ (function () {
|
||||
function PDFForm(acroForm, doc) {
|
||||
var _this = this;
|
||||
this.embedDefaultFont = function () {
|
||||
return _this.doc.embedStandardFont(StandardFonts.Helvetica);
|
||||
};
|
||||
assertIs(acroForm, 'acroForm', [[PDFAcroForm, 'PDFAcroForm']]);
|
||||
assertIs(doc, 'doc', [[PDFDocument, 'PDFDocument']]);
|
||||
this.acroForm = acroForm;
|
||||
this.doc = doc;
|
||||
this.dirtyFields = new Set();
|
||||
this.defaultFontCache = Cache.populatedBy(this.embedDefaultFont);
|
||||
}
|
||||
/**
|
||||
* Returns `true` if this [[PDFForm]] has XFA data. Most PDFs with form
|
||||
* fields do not use XFA as it is not widely supported by PDF readers.
|
||||
*
|
||||
* > `pdf-lib` does not support creation, modification, or reading of XFA
|
||||
* > fields.
|
||||
*
|
||||
* For example:
|
||||
* ```js
|
||||
* const form = pdfDoc.getForm()
|
||||
* if (form.hasXFA()) console.log('PDF has XFA data')
|
||||
* ```
|
||||
* @returns Whether or not this form has XFA data.
|
||||
*/
|
||||
PDFForm.prototype.hasXFA = function () {
|
||||
return this.acroForm.dict.has(PDFName.of('XFA'));
|
||||
};
|
||||
/**
|
||||
* Disconnect the XFA data from this [[PDFForm]] (if any exists). This will
|
||||
* force readers to fallback to standard fields if the [[PDFDocument]]
|
||||
* contains any. For example:
|
||||
*
|
||||
* For example:
|
||||
* ```js
|
||||
* const form = pdfDoc.getForm()
|
||||
* form.deleteXFA()
|
||||
* ```
|
||||
*/
|
||||
PDFForm.prototype.deleteXFA = function () {
|
||||
this.acroForm.dict.delete(PDFName.of('XFA'));
|
||||
};
|
||||
/**
|
||||
* Get all fields contained in this [[PDFForm]]. For example:
|
||||
* ```js
|
||||
* const form = pdfDoc.getForm()
|
||||
* const fields = form.getFields()
|
||||
* fields.forEach(field => {
|
||||
* const type = field.constructor.name
|
||||
* const name = field.getName()
|
||||
* console.log(`${type}: ${name}`)
|
||||
* })
|
||||
* ```
|
||||
* @returns An array of all fields in this form.
|
||||
*/
|
||||
PDFForm.prototype.getFields = function () {
|
||||
var allFields = this.acroForm.getAllFields();
|
||||
var fields = [];
|
||||
for (var idx = 0, len = allFields.length; idx < len; idx++) {
|
||||
var _a = allFields[idx], acroField = _a[0], ref = _a[1];
|
||||
var field = convertToPDFField(acroField, ref, this.doc);
|
||||
if (field)
|
||||
fields.push(field);
|
||||
}
|
||||
return fields;
|
||||
};
|
||||
/**
|
||||
* Get the field in this [[PDFForm]] with the given name. For example:
|
||||
* ```js
|
||||
* const form = pdfDoc.getForm()
|
||||
* const field = form.getFieldMaybe('Page1.Foo.Bar[0]')
|
||||
* if (field) console.log('Field exists!')
|
||||
* ```
|
||||
* @param name A fully qualified field name.
|
||||
* @returns The field with the specified name, if one exists.
|
||||
*/
|
||||
PDFForm.prototype.getFieldMaybe = function (name) {
|
||||
assertIs(name, 'name', ['string']);
|
||||
var fields = this.getFields();
|
||||
for (var idx = 0, len = fields.length; idx < len; idx++) {
|
||||
var field = fields[idx];
|
||||
if (field.getName() === name)
|
||||
return field;
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
/**
|
||||
* Get the field in this [[PDFForm]] with the given name. For example:
|
||||
* ```js
|
||||
* const form = pdfDoc.getForm()
|
||||
* const field = form.getField('Page1.Foo.Bar[0]')
|
||||
* ```
|
||||
* If no field exists with the provided name, an error will be thrown.
|
||||
* @param name A fully qualified field name.
|
||||
* @returns The field with the specified name.
|
||||
*/
|
||||
PDFForm.prototype.getField = function (name) {
|
||||
assertIs(name, 'name', ['string']);
|
||||
var field = this.getFieldMaybe(name);
|
||||
if (field)
|
||||
return field;
|
||||
throw new NoSuchFieldError(name);
|
||||
};
|
||||
/**
|
||||
* Get the button field in this [[PDFForm]] with the given name. For example:
|
||||
* ```js
|
||||
* const form = pdfDoc.getForm()
|
||||
* const button = form.getButton('Page1.Foo.Button[0]')
|
||||
* ```
|
||||
* An error will be thrown if no field exists with the provided name, or if
|
||||
* the field exists but is not a button.
|
||||
* @param name A fully qualified button name.
|
||||
* @returns The button with the specified name.
|
||||
*/
|
||||
PDFForm.prototype.getButton = function (name) {
|
||||
assertIs(name, 'name', ['string']);
|
||||
var field = this.getField(name);
|
||||
if (field instanceof PDFButton)
|
||||
return field;
|
||||
throw new UnexpectedFieldTypeError(name, PDFButton, field);
|
||||
};
|
||||
/**
|
||||
* Get the check box field in this [[PDFForm]] with the given name.
|
||||
* For example:
|
||||
* ```js
|
||||
* const form = pdfDoc.getForm()
|
||||
* const checkBox = form.getCheckBox('Page1.Foo.CheckBox[0]')
|
||||
* checkBox.check()
|
||||
* ```
|
||||
* An error will be thrown if no field exists with the provided name, or if
|
||||
* the field exists but is not a check box.
|
||||
* @param name A fully qualified check box name.
|
||||
* @returns The check box with the specified name.
|
||||
*/
|
||||
PDFForm.prototype.getCheckBox = function (name) {
|
||||
assertIs(name, 'name', ['string']);
|
||||
var field = this.getField(name);
|
||||
if (field instanceof PDFCheckBox)
|
||||
return field;
|
||||
throw new UnexpectedFieldTypeError(name, PDFCheckBox, field);
|
||||
};
|
||||
/**
|
||||
* Get the dropdown field in this [[PDFForm]] with the given name.
|
||||
* For example:
|
||||
* ```js
|
||||
* const form = pdfDoc.getForm()
|
||||
* const dropdown = form.getDropdown('Page1.Foo.Dropdown[0]')
|
||||
* const options = dropdown.getOptions()
|
||||
* dropdown.select(options[0])
|
||||
* ```
|
||||
* An error will be thrown if no field exists with the provided name, or if
|
||||
* the field exists but is not a dropdown.
|
||||
* @param name A fully qualified dropdown name.
|
||||
* @returns The dropdown with the specified name.
|
||||
*/
|
||||
PDFForm.prototype.getDropdown = function (name) {
|
||||
assertIs(name, 'name', ['string']);
|
||||
var field = this.getField(name);
|
||||
if (field instanceof PDFDropdown)
|
||||
return field;
|
||||
throw new UnexpectedFieldTypeError(name, PDFDropdown, field);
|
||||
};
|
||||
/**
|
||||
* Get the option list field in this [[PDFForm]] with the given name.
|
||||
* For example:
|
||||
* ```js
|
||||
* const form = pdfDoc.getForm()
|
||||
* const optionList = form.getOptionList('Page1.Foo.OptionList[0]')
|
||||
* const options = optionList.getOptions()
|
||||
* optionList.select(options[0])
|
||||
* ```
|
||||
* An error will be thrown if no field exists with the provided name, or if
|
||||
* the field exists but is not an option list.
|
||||
* @param name A fully qualified option list name.
|
||||
* @returns The option list with the specified name.
|
||||
*/
|
||||
PDFForm.prototype.getOptionList = function (name) {
|
||||
assertIs(name, 'name', ['string']);
|
||||
var field = this.getField(name);
|
||||
if (field instanceof PDFOptionList)
|
||||
return field;
|
||||
throw new UnexpectedFieldTypeError(name, PDFOptionList, field);
|
||||
};
|
||||
/**
|
||||
* Get the radio group field in this [[PDFForm]] with the given name.
|
||||
* For example:
|
||||
* ```js
|
||||
* const form = pdfDoc.getForm()
|
||||
* const radioGroup = form.getRadioGroup('Page1.Foo.RadioGroup[0]')
|
||||
* const options = radioGroup.getOptions()
|
||||
* radioGroup.select(options[0])
|
||||
* ```
|
||||
* An error will be thrown if no field exists with the provided name, or if
|
||||
* the field exists but is not a radio group.
|
||||
* @param name A fully qualified radio group name.
|
||||
* @returns The radio group with the specified name.
|
||||
*/
|
||||
PDFForm.prototype.getRadioGroup = function (name) {
|
||||
assertIs(name, 'name', ['string']);
|
||||
var field = this.getField(name);
|
||||
if (field instanceof PDFRadioGroup)
|
||||
return field;
|
||||
throw new UnexpectedFieldTypeError(name, PDFRadioGroup, field);
|
||||
};
|
||||
/**
|
||||
* Get the signature field in this [[PDFForm]] with the given name.
|
||||
* For example:
|
||||
* ```js
|
||||
* const form = pdfDoc.getForm()
|
||||
* const signature = form.getSignature('Page1.Foo.Signature[0]')
|
||||
* ```
|
||||
* An error will be thrown if no field exists with the provided name, or if
|
||||
* the field exists but is not a signature.
|
||||
* @param name A fully qualified signature name.
|
||||
* @returns The signature with the specified name.
|
||||
*/
|
||||
PDFForm.prototype.getSignature = function (name) {
|
||||
assertIs(name, 'name', ['string']);
|
||||
var field = this.getField(name);
|
||||
if (field instanceof PDFSignature)
|
||||
return field;
|
||||
throw new UnexpectedFieldTypeError(name, PDFSignature, field);
|
||||
};
|
||||
/**
|
||||
* Get the text field in this [[PDFForm]] with the given name.
|
||||
* For example:
|
||||
* ```js
|
||||
* const form = pdfDoc.getForm()
|
||||
* const textField = form.getTextField('Page1.Foo.TextField[0]')
|
||||
* textField.setText('Are you designed to act or to be acted upon?')
|
||||
* ```
|
||||
* An error will be thrown if no field exists with the provided name, or if
|
||||
* the field exists but is not a text field.
|
||||
* @param name A fully qualified text field name.
|
||||
* @returns The text field with the specified name.
|
||||
*/
|
||||
PDFForm.prototype.getTextField = function (name) {
|
||||
assertIs(name, 'name', ['string']);
|
||||
var field = this.getField(name);
|
||||
if (field instanceof PDFTextField)
|
||||
return field;
|
||||
throw new UnexpectedFieldTypeError(name, PDFTextField, field);
|
||||
};
|
||||
/**
|
||||
* Create a new button field in this [[PDFForm]] with the given name.
|
||||
* For example:
|
||||
* ```js
|
||||
* const font = await pdfDoc.embedFont(StandardFonts.Helvetica)
|
||||
* const page = pdfDoc.addPage()
|
||||
*
|
||||
* const form = pdfDoc.getForm()
|
||||
* const button = form.createButton('cool.new.button')
|
||||
*
|
||||
* button.addToPage('Do Stuff', font, page)
|
||||
* ```
|
||||
* An error will be thrown if a field already exists with the provided name.
|
||||
* @param name The fully qualified name for the new button.
|
||||
* @returns The new button field.
|
||||
*/
|
||||
PDFForm.prototype.createButton = function (name) {
|
||||
assertIs(name, 'name', ['string']);
|
||||
var nameParts = splitFieldName(name);
|
||||
var parent = this.findOrCreateNonTerminals(nameParts.nonTerminal);
|
||||
var button = PDFAcroPushButton.create(this.doc.context);
|
||||
button.setPartialName(nameParts.terminal);
|
||||
addFieldToParent(parent, [button, button.ref], nameParts.terminal);
|
||||
return PDFButton.of(button, button.ref, this.doc);
|
||||
};
|
||||
/**
|
||||
* Create a new check box field in this [[PDFForm]] with the given name.
|
||||
* For example:
|
||||
* ```js
|
||||
* const font = await pdfDoc.embedFont(StandardFonts.Helvetica)
|
||||
* const page = pdfDoc.addPage()
|
||||
*
|
||||
* const form = pdfDoc.getForm()
|
||||
* const checkBox = form.createCheckBox('cool.new.checkBox')
|
||||
*
|
||||
* checkBox.addToPage(page)
|
||||
* ```
|
||||
* An error will be thrown if a field already exists with the provided name.
|
||||
* @param name The fully qualified name for the new check box.
|
||||
* @returns The new check box field.
|
||||
*/
|
||||
PDFForm.prototype.createCheckBox = function (name) {
|
||||
assertIs(name, 'name', ['string']);
|
||||
var nameParts = splitFieldName(name);
|
||||
var parent = this.findOrCreateNonTerminals(nameParts.nonTerminal);
|
||||
var checkBox = PDFAcroCheckBox.create(this.doc.context);
|
||||
checkBox.setPartialName(nameParts.terminal);
|
||||
addFieldToParent(parent, [checkBox, checkBox.ref], nameParts.terminal);
|
||||
return PDFCheckBox.of(checkBox, checkBox.ref, this.doc);
|
||||
};
|
||||
/**
|
||||
* Create a new dropdown field in this [[PDFForm]] with the given name.
|
||||
* For example:
|
||||
* ```js
|
||||
* const font = await pdfDoc.embedFont(StandardFonts.Helvetica)
|
||||
* const page = pdfDoc.addPage()
|
||||
*
|
||||
* const form = pdfDoc.getForm()
|
||||
* const dropdown = form.createDropdown('cool.new.dropdown')
|
||||
*
|
||||
* dropdown.addToPage(font, page)
|
||||
* ```
|
||||
* An error will be thrown if a field already exists with the provided name.
|
||||
* @param name The fully qualified name for the new dropdown.
|
||||
* @returns The new dropdown field.
|
||||
*/
|
||||
PDFForm.prototype.createDropdown = function (name) {
|
||||
assertIs(name, 'name', ['string']);
|
||||
var nameParts = splitFieldName(name);
|
||||
var parent = this.findOrCreateNonTerminals(nameParts.nonTerminal);
|
||||
var comboBox = PDFAcroComboBox.create(this.doc.context);
|
||||
comboBox.setPartialName(nameParts.terminal);
|
||||
addFieldToParent(parent, [comboBox, comboBox.ref], nameParts.terminal);
|
||||
return PDFDropdown.of(comboBox, comboBox.ref, this.doc);
|
||||
};
|
||||
/**
|
||||
* Create a new option list field in this [[PDFForm]] with the given name.
|
||||
* For example:
|
||||
* ```js
|
||||
* const font = await pdfDoc.embedFont(StandardFonts.Helvetica)
|
||||
* const page = pdfDoc.addPage()
|
||||
*
|
||||
* const form = pdfDoc.getForm()
|
||||
* const optionList = form.createOptionList('cool.new.optionList')
|
||||
*
|
||||
* optionList.addToPage(font, page)
|
||||
* ```
|
||||
* An error will be thrown if a field already exists with the provided name.
|
||||
* @param name The fully qualified name for the new option list.
|
||||
* @returns The new option list field.
|
||||
*/
|
||||
PDFForm.prototype.createOptionList = function (name) {
|
||||
assertIs(name, 'name', ['string']);
|
||||
var nameParts = splitFieldName(name);
|
||||
var parent = this.findOrCreateNonTerminals(nameParts.nonTerminal);
|
||||
var listBox = PDFAcroListBox.create(this.doc.context);
|
||||
listBox.setPartialName(nameParts.terminal);
|
||||
addFieldToParent(parent, [listBox, listBox.ref], nameParts.terminal);
|
||||
return PDFOptionList.of(listBox, listBox.ref, this.doc);
|
||||
};
|
||||
/**
|
||||
* Create a new radio group field in this [[PDFForm]] with the given name.
|
||||
* For example:
|
||||
* ```js
|
||||
* const font = await pdfDoc.embedFont(StandardFonts.Helvetica)
|
||||
* const page = pdfDoc.addPage()
|
||||
*
|
||||
* const form = pdfDoc.getForm()
|
||||
* const radioGroup = form.createRadioGroup('cool.new.radioGroup')
|
||||
*
|
||||
* radioGroup.addOptionToPage('is-dog', page, { y: 0 })
|
||||
* radioGroup.addOptionToPage('is-cat', page, { y: 75 })
|
||||
* ```
|
||||
* An error will be thrown if a field already exists with the provided name.
|
||||
* @param name The fully qualified name for the new radio group.
|
||||
* @returns The new radio group field.
|
||||
*/
|
||||
PDFForm.prototype.createRadioGroup = function (name) {
|
||||
assertIs(name, 'name', ['string']);
|
||||
var nameParts = splitFieldName(name);
|
||||
var parent = this.findOrCreateNonTerminals(nameParts.nonTerminal);
|
||||
var radioButton = PDFAcroRadioButton.create(this.doc.context);
|
||||
radioButton.setPartialName(nameParts.terminal);
|
||||
addFieldToParent(parent, [radioButton, radioButton.ref], nameParts.terminal);
|
||||
return PDFRadioGroup.of(radioButton, radioButton.ref, this.doc);
|
||||
};
|
||||
/**
|
||||
* Create a new text field in this [[PDFForm]] with the given name.
|
||||
* For example:
|
||||
* ```js
|
||||
* const font = await pdfDoc.embedFont(StandardFonts.Helvetica)
|
||||
* const page = pdfDoc.addPage()
|
||||
*
|
||||
* const form = pdfDoc.getForm()
|
||||
* const textField = form.createTextField('cool.new.textField')
|
||||
*
|
||||
* textField.addToPage(font, page)
|
||||
* ```
|
||||
* An error will be thrown if a field already exists with the provided name.
|
||||
* @param name The fully qualified name for the new radio group.
|
||||
* @returns The new radio group field.
|
||||
*/
|
||||
PDFForm.prototype.createTextField = function (name) {
|
||||
assertIs(name, 'name', ['string']);
|
||||
var nameParts = splitFieldName(name);
|
||||
var parent = this.findOrCreateNonTerminals(nameParts.nonTerminal);
|
||||
var text = PDFAcroText.create(this.doc.context);
|
||||
text.setPartialName(nameParts.terminal);
|
||||
addFieldToParent(parent, [text, text.ref], nameParts.terminal);
|
||||
return PDFTextField.of(text, text.ref, this.doc);
|
||||
};
|
||||
/**
|
||||
* Flatten all fields in this [[PDFForm]].
|
||||
*
|
||||
* Flattening a form field will take the current appearance for each of that
|
||||
* field's widgets and make them part of their page's content stream. All form
|
||||
* fields and annotations associated are then removed. Note that once a form
|
||||
* has been flattened its fields can no longer be accessed or edited.
|
||||
*
|
||||
* This operation is often used after filling form fields to ensure a
|
||||
* consistent appearance across different PDF readers and/or printers.
|
||||
* Another common use case is to copy a template document with form fields
|
||||
* into another document. In this scenario you would load the template
|
||||
* document, fill its fields, flatten it, and then copy its pages into the
|
||||
* recipient document - the filled fields will be copied over.
|
||||
*
|
||||
* For example:
|
||||
* ```js
|
||||
* const form = pdfDoc.getForm();
|
||||
* form.flatten();
|
||||
* ```
|
||||
*/
|
||||
PDFForm.prototype.flatten = function (options) {
|
||||
if (options === void 0) { options = { updateFieldAppearances: true }; }
|
||||
if (options.updateFieldAppearances) {
|
||||
this.updateFieldAppearances();
|
||||
}
|
||||
var fields = this.getFields();
|
||||
for (var i = 0, lenFields = fields.length; i < lenFields; i++) {
|
||||
var field = fields[i];
|
||||
var widgets = field.acroField.getWidgets();
|
||||
for (var j = 0, lenWidgets = widgets.length; j < lenWidgets; j++) {
|
||||
var widget = widgets[j];
|
||||
var page = this.findWidgetPage(widget);
|
||||
var widgetRef = this.findWidgetAppearanceRef(field, widget);
|
||||
var xObjectKey = page.node.newXObject('FlatWidget', widgetRef);
|
||||
var rectangle = widget.getRectangle();
|
||||
var operators = __spreadArrays([
|
||||
pushGraphicsState(),
|
||||
translate(rectangle.x, rectangle.y)
|
||||
], rotateInPlace(__assign(__assign({}, rectangle), { rotation: 0 })), [
|
||||
drawObject(xObjectKey),
|
||||
popGraphicsState(),
|
||||
]).filter(Boolean);
|
||||
page.pushOperators.apply(page, operators);
|
||||
}
|
||||
this.removeField(field);
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Remove a field from this [[PDFForm]].
|
||||
*
|
||||
* For example:
|
||||
* ```js
|
||||
* const form = pdfDoc.getForm();
|
||||
* const ageField = form.getFields().find(x => x.getName() === 'Age');
|
||||
* form.removeField(ageField);
|
||||
* ```
|
||||
*/
|
||||
PDFForm.prototype.removeField = function (field) {
|
||||
var widgets = field.acroField.getWidgets();
|
||||
var pages = new Set();
|
||||
for (var i = 0, len = widgets.length; i < len; i++) {
|
||||
var widget = widgets[i];
|
||||
var widgetRef = this.findWidgetAppearanceRef(field, widget);
|
||||
var page = this.findWidgetPage(widget);
|
||||
pages.add(page);
|
||||
page.node.removeAnnot(widgetRef);
|
||||
}
|
||||
pages.forEach(function (page) { return page.node.removeAnnot(field.ref); });
|
||||
this.acroForm.removeField(field.acroField);
|
||||
var fieldKids = field.acroField.normalizedEntries().Kids;
|
||||
var kidsCount = fieldKids.size();
|
||||
for (var childIndex = 0; childIndex < kidsCount; childIndex++) {
|
||||
var child = fieldKids.get(childIndex);
|
||||
if (child instanceof PDFRef) {
|
||||
this.doc.context.delete(child);
|
||||
}
|
||||
}
|
||||
this.doc.context.delete(field.ref);
|
||||
};
|
||||
/**
|
||||
* Update the appearance streams for all widgets of all fields in this
|
||||
* [[PDFForm]]. Appearance streams will only be created for a widget if it
|
||||
* does not have any existing appearance streams, or the field's value has
|
||||
* changed (e.g. by calling [[PDFTextField.setText]] or
|
||||
* [[PDFDropdown.select]]).
|
||||
*
|
||||
* For example:
|
||||
* ```js
|
||||
* const courier = await pdfDoc.embedFont(StandardFonts.Courier)
|
||||
* const form = pdfDoc.getForm()
|
||||
* form.updateFieldAppearances(courier)
|
||||
* ```
|
||||
*
|
||||
* **IMPORTANT:** The default value for the `font` parameter is
|
||||
* [[StandardFonts.Helvetica]]. Note that this is a WinAnsi font. This means
|
||||
* that encoding errors will be thrown if any fields contain text with
|
||||
* characters outside the WinAnsi character set (the latin alphabet).
|
||||
*
|
||||
* Embedding a custom font and passing that as the `font`
|
||||
* parameter allows you to generate appearance streams with non WinAnsi
|
||||
* characters (assuming your custom font supports them).
|
||||
*
|
||||
* > **NOTE:** The [[PDFDocument.save]] method will call this method to
|
||||
* > update appearances automatically if a form was accessed via the
|
||||
* > [[PDFDocument.getForm]] method prior to saving.
|
||||
*
|
||||
* @param font Optionally, the font to use when creating new appearances.
|
||||
*/
|
||||
PDFForm.prototype.updateFieldAppearances = function (font) {
|
||||
assertOrUndefined(font, 'font', [[PDFFont, 'PDFFont']]);
|
||||
font = font !== null && font !== void 0 ? font : this.getDefaultFont();
|
||||
var fields = this.getFields();
|
||||
for (var idx = 0, len = fields.length; idx < len; idx++) {
|
||||
var field = fields[idx];
|
||||
if (field.needsAppearancesUpdate()) {
|
||||
field.defaultUpdateAppearances(font);
|
||||
}
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Mark a field as dirty. This will cause its appearance streams to be
|
||||
* updated by [[PDFForm.updateFieldAppearances]].
|
||||
* ```js
|
||||
* const form = pdfDoc.getForm()
|
||||
* const field = form.getField('foo.bar')
|
||||
* form.markFieldAsDirty(field.ref)
|
||||
* ```
|
||||
* @param fieldRef The reference to the field that should be marked.
|
||||
*/
|
||||
PDFForm.prototype.markFieldAsDirty = function (fieldRef) {
|
||||
assertOrUndefined(fieldRef, 'fieldRef', [[PDFRef, 'PDFRef']]);
|
||||
this.dirtyFields.add(fieldRef);
|
||||
};
|
||||
/**
|
||||
* Mark a field as dirty. This will cause its appearance streams to not be
|
||||
* updated by [[PDFForm.updateFieldAppearances]].
|
||||
* ```js
|
||||
* const form = pdfDoc.getForm()
|
||||
* const field = form.getField('foo.bar')
|
||||
* form.markFieldAsClean(field.ref)
|
||||
* ```
|
||||
* @param fieldRef The reference to the field that should be marked.
|
||||
*/
|
||||
PDFForm.prototype.markFieldAsClean = function (fieldRef) {
|
||||
assertOrUndefined(fieldRef, 'fieldRef', [[PDFRef, 'PDFRef']]);
|
||||
this.dirtyFields.delete(fieldRef);
|
||||
};
|
||||
/**
|
||||
* Returns `true` is the specified field has been marked as dirty.
|
||||
* ```js
|
||||
* const form = pdfDoc.getForm()
|
||||
* const field = form.getField('foo.bar')
|
||||
* if (form.fieldIsDirty(field.ref)) console.log('Field is dirty')
|
||||
* ```
|
||||
* @param fieldRef The reference to the field that should be checked.
|
||||
* @returns Whether or not the specified field is dirty.
|
||||
*/
|
||||
PDFForm.prototype.fieldIsDirty = function (fieldRef) {
|
||||
assertOrUndefined(fieldRef, 'fieldRef', [[PDFRef, 'PDFRef']]);
|
||||
return this.dirtyFields.has(fieldRef);
|
||||
};
|
||||
PDFForm.prototype.getDefaultFont = function () {
|
||||
return this.defaultFontCache.access();
|
||||
};
|
||||
PDFForm.prototype.findWidgetPage = function (widget) {
|
||||
var pageRef = widget.P();
|
||||
var page = this.doc.getPages().find(function (x) { return x.ref === pageRef; });
|
||||
if (page === undefined) {
|
||||
var widgetRef = this.doc.context.getObjectRef(widget.dict);
|
||||
if (widgetRef === undefined) {
|
||||
throw new Error('Could not find PDFRef for PDFObject');
|
||||
}
|
||||
page = this.doc.findPageForAnnotationRef(widgetRef);
|
||||
if (page === undefined) {
|
||||
throw new Error("Could not find page for PDFRef " + widgetRef);
|
||||
}
|
||||
}
|
||||
return page;
|
||||
};
|
||||
PDFForm.prototype.findWidgetAppearanceRef = function (field, widget) {
|
||||
var _a;
|
||||
var refOrDict = widget.getNormalAppearance();
|
||||
if (refOrDict instanceof PDFDict &&
|
||||
(field instanceof PDFCheckBox || field instanceof PDFRadioGroup)) {
|
||||
var value = field.acroField.getValue();
|
||||
var ref = (_a = refOrDict.get(value)) !== null && _a !== void 0 ? _a : refOrDict.get(PDFName.of('Off'));
|
||||
if (ref instanceof PDFRef) {
|
||||
refOrDict = ref;
|
||||
}
|
||||
}
|
||||
if (!(refOrDict instanceof PDFRef)) {
|
||||
var name_1 = field.getName();
|
||||
throw new Error("Failed to extract appearance ref for: " + name_1);
|
||||
}
|
||||
return refOrDict;
|
||||
};
|
||||
PDFForm.prototype.findOrCreateNonTerminals = function (partialNames) {
|
||||
var nonTerminal = [
|
||||
this.acroForm,
|
||||
];
|
||||
for (var idx = 0, len = partialNames.length; idx < len; idx++) {
|
||||
var namePart = partialNames[idx];
|
||||
if (!namePart)
|
||||
throw new InvalidFieldNamePartError(namePart);
|
||||
var parent_1 = nonTerminal[0], parentRef = nonTerminal[1];
|
||||
var res = this.findNonTerminal(namePart, parent_1);
|
||||
if (res) {
|
||||
nonTerminal = res;
|
||||
}
|
||||
else {
|
||||
var node = PDFAcroNonTerminal.create(this.doc.context);
|
||||
node.setPartialName(namePart);
|
||||
node.setParent(parentRef);
|
||||
var nodeRef = this.doc.context.register(node.dict);
|
||||
parent_1.addField(nodeRef);
|
||||
nonTerminal = [node, nodeRef];
|
||||
}
|
||||
}
|
||||
return nonTerminal;
|
||||
};
|
||||
PDFForm.prototype.findNonTerminal = function (partialName, parent) {
|
||||
var fields = parent instanceof PDFAcroForm
|
||||
? this.acroForm.getFields()
|
||||
: createPDFAcroFields(parent.Kids());
|
||||
for (var idx = 0, len = fields.length; idx < len; idx++) {
|
||||
var _a = fields[idx], field = _a[0], ref = _a[1];
|
||||
if (field.getPartialName() === partialName) {
|
||||
if (field instanceof PDFAcroNonTerminal)
|
||||
return [field, ref];
|
||||
throw new FieldAlreadyExistsError(partialName);
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
/**
|
||||
* > **NOTE:** You probably don't want to call this method directly. Instead,
|
||||
* > consider using the [[PDFDocument.getForm]] method, which will create an
|
||||
* > instance of [[PDFForm]] for you.
|
||||
*
|
||||
* Create an instance of [[PDFForm]] from an existing acroForm and embedder
|
||||
*
|
||||
* @param acroForm The underlying `PDFAcroForm` for this form.
|
||||
* @param doc The document to which the form will belong.
|
||||
*/
|
||||
PDFForm.of = function (acroForm, doc) {
|
||||
return new PDFForm(acroForm, doc);
|
||||
};
|
||||
return PDFForm;
|
||||
}());
|
||||
export default PDFForm;
|
||||
var convertToPDFField = function (field, ref, doc) {
|
||||
if (field instanceof PDFAcroPushButton)
|
||||
return PDFButton.of(field, ref, doc);
|
||||
if (field instanceof PDFAcroCheckBox)
|
||||
return PDFCheckBox.of(field, ref, doc);
|
||||
if (field instanceof PDFAcroComboBox)
|
||||
return PDFDropdown.of(field, ref, doc);
|
||||
if (field instanceof PDFAcroListBox)
|
||||
return PDFOptionList.of(field, ref, doc);
|
||||
if (field instanceof PDFAcroText)
|
||||
return PDFTextField.of(field, ref, doc);
|
||||
if (field instanceof PDFAcroRadioButton) {
|
||||
return PDFRadioGroup.of(field, ref, doc);
|
||||
}
|
||||
if (field instanceof PDFAcroSignature) {
|
||||
return PDFSignature.of(field, ref, doc);
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
var splitFieldName = function (fullyQualifiedName) {
|
||||
if (fullyQualifiedName.length === 0) {
|
||||
throw new Error('PDF field names must not be empty strings');
|
||||
}
|
||||
var parts = fullyQualifiedName.split('.');
|
||||
for (var idx = 0, len = parts.length; idx < len; idx++) {
|
||||
if (parts[idx] === '') {
|
||||
throw new Error("Periods in PDF field names must be separated by at least one character: \"" + fullyQualifiedName + "\"");
|
||||
}
|
||||
}
|
||||
if (parts.length === 1)
|
||||
return { nonTerminal: [], terminal: parts[0] };
|
||||
return {
|
||||
nonTerminal: parts.slice(0, parts.length - 1),
|
||||
terminal: parts[parts.length - 1],
|
||||
};
|
||||
};
|
||||
var addFieldToParent = function (_a, _b, partialName) {
|
||||
var parent = _a[0], parentRef = _a[1];
|
||||
var field = _b[0], fieldRef = _b[1];
|
||||
var entries = parent.normalizedEntries();
|
||||
var fields = createPDFAcroFields('Kids' in entries ? entries.Kids : entries.Fields);
|
||||
for (var idx = 0, len = fields.length; idx < len; idx++) {
|
||||
if (fields[idx][0].getPartialName() === partialName) {
|
||||
throw new FieldAlreadyExistsError(partialName);
|
||||
}
|
||||
}
|
||||
parent.addField(fieldRef);
|
||||
field.setParent(parentRef);
|
||||
};
|
||||
//# sourceMappingURL=PDFForm.js.map
|
||||
1
node_modules/pdf-lib/es/api/form/PDFForm.js.map
generated
vendored
Normal file
1
node_modules/pdf-lib/es/api/form/PDFForm.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
336
node_modules/pdf-lib/es/api/form/PDFOptionList.d.ts
generated
vendored
Normal file
336
node_modules/pdf-lib/es/api/form/PDFOptionList.d.ts
generated
vendored
Normal file
@@ -0,0 +1,336 @@
|
||||
import PDFDocument from "../PDFDocument";
|
||||
import PDFPage from "../PDFPage";
|
||||
import PDFFont from "../PDFFont";
|
||||
import PDFField, { FieldAppearanceOptions } from "./PDFField";
|
||||
import { AppearanceProviderFor } from "./appearances";
|
||||
import { PDFRef, PDFAcroListBox } from "../../core";
|
||||
/**
|
||||
* Represents an option list field of a [[PDFForm]].
|
||||
*
|
||||
* [[PDFOptionList]] fields are interactive lists of options. The purpose of an
|
||||
* option list is to enable users to select one or more options from a set of
|
||||
* possible options. Users are able to see the full set of options without
|
||||
* first having to click on the field (though scrolling may be necessary).
|
||||
* Clicking an option in the list will cause it to be selected and displayed
|
||||
* with a highlighted background. Some option lists allow users to select
|
||||
* more than one option (see [[PDFOptionList.isMultiselect]]).
|
||||
*/
|
||||
export default class PDFOptionList extends PDFField {
|
||||
/**
|
||||
* > **NOTE:** You probably don't want to call this method directly. Instead,
|
||||
* > consider using the [[PDFForm.getOptionList]] method, which will create
|
||||
* > an instance of [[PDFOptionList]] for you.
|
||||
*
|
||||
* Create an instance of [[PDFOptionList]] from an existing acroListBox and
|
||||
* ref
|
||||
*
|
||||
* @param acroComboBox The underlying `PDFAcroListBox` for this option list.
|
||||
* @param ref The unique reference for this option list.
|
||||
* @param doc The document to which this option list will belong.
|
||||
*/
|
||||
static of: (acroListBox: PDFAcroListBox, ref: PDFRef, doc: PDFDocument) => PDFOptionList;
|
||||
/** The low-level PDFAcroListBox wrapped by this option list. */
|
||||
readonly acroField: PDFAcroListBox;
|
||||
private constructor();
|
||||
/**
|
||||
* Get the list of available options for this option list. These options will
|
||||
* be displayed to users who view this option list in a PDF reader.
|
||||
* For example:
|
||||
* ```js
|
||||
* const optionList = form.getOptionList('some.optionList.field')
|
||||
* const options = optionList.getOptions()
|
||||
* console.log('Option List options:', options)
|
||||
* ```
|
||||
* @returns The options for this option list.
|
||||
*/
|
||||
getOptions(): string[];
|
||||
/**
|
||||
* Get the selected options for this option list. These are the values that
|
||||
* were selected by a human user via a PDF reader, or programatically via
|
||||
* software.
|
||||
* For example:
|
||||
* ```js
|
||||
* const optionList = form.getOptionList('some.optionList.field')
|
||||
* const selections = optionList.getSelected()
|
||||
* console.log('Option List selections:', selections)
|
||||
* ```
|
||||
* @returns The selected options for this option list.
|
||||
*/
|
||||
getSelected(): string[];
|
||||
/**
|
||||
* Set the list of options that are available for this option list. These are
|
||||
* the values that will be available for users to select when they view this
|
||||
* option list in a PDF reader. Note that preexisting options for this
|
||||
* option list will be removed. Only the values passed as `options` will be
|
||||
* available to select.
|
||||
*
|
||||
* For example:
|
||||
* ```js
|
||||
* const optionList = form.getOptionList('planets.optionList')
|
||||
* optionList.setOptions(['Earth', 'Mars', 'Pluto', 'Venus'])
|
||||
* ```
|
||||
*
|
||||
* This method will mark this option list as dirty, causing its appearance
|
||||
* streams to be updated when either [[PDFDocument.save]] or
|
||||
* [[PDFForm.updateFieldAppearances]] is called. The updated streams will
|
||||
* display the options this field contains inside the widgets of this text
|
||||
* field (with selected options highlighted).
|
||||
*
|
||||
* **IMPORTANT:** The default font used to update appearance streams is
|
||||
* [[StandardFonts.Helvetica]]. Note that this is a WinAnsi font. This means
|
||||
* that encoding errors will be thrown if this field contains any options
|
||||
* with characters outside the WinAnsi character set (the latin alphabet).
|
||||
*
|
||||
* Embedding a custom font and passing it to
|
||||
* [[PDFForm.updateFieldAppearances]] or [[PDFOptionList.updateAppearances]]
|
||||
* allows you to generate appearance streams with characters outside the
|
||||
* latin alphabet (assuming the custom font supports them).
|
||||
*
|
||||
* @param options The options that should be available in this option list.
|
||||
*/
|
||||
setOptions(options: string[]): void;
|
||||
/**
|
||||
* Add to the list of options that are available for this option list. Users
|
||||
* will be able to select these values in a PDF reader. In addition to the
|
||||
* values passed as `options`, any preexisting options for this option list
|
||||
* will still be available for users to select.
|
||||
* For example:
|
||||
* ```js
|
||||
* const optionList = form.getOptionList('rockets.optionList')
|
||||
* optionList.addOptions(['Saturn IV', 'Falcon Heavy'])
|
||||
* ```
|
||||
* This method will mark this option list as dirty. See
|
||||
* [[PDFOptionList.setOptions]] for more details about what this means.
|
||||
* @param options New options that should be available in this option list.
|
||||
*/
|
||||
addOptions(options: string | string[]): void;
|
||||
/**
|
||||
* Select one or more values for this option list. This operation is analogous
|
||||
* to a human user opening the option list in a PDF reader and clicking on one
|
||||
* or more values to select them. This method will update the underlying state
|
||||
* of the option list to indicate which values have been selected. PDF
|
||||
* libraries and readers will be able to extract these values from the saved
|
||||
* document and determine which values were selected.
|
||||
* For example:
|
||||
* ```js
|
||||
* const optionList = form.getOptionList('best.superheroes.optionList')
|
||||
* optionList.select(['One Punch Man', 'Iron Man'])
|
||||
* ```
|
||||
* This method will mark this option list as dirty. See
|
||||
* [[PDFOptionList.setOptions]] for more details about what this means.
|
||||
* @param options The options to be selected.
|
||||
* @param merge Whether or not existing selections should be preserved.
|
||||
*/
|
||||
select(options: string | string[], merge?: boolean): void;
|
||||
/**
|
||||
* Clear all selected values for this option list. This operation is
|
||||
* equivalent to selecting an empty list. This method will update the
|
||||
* underlying state of the option list to indicate that no values have been
|
||||
* selected.
|
||||
* For example:
|
||||
* ```js
|
||||
* const optionList = form.getOptionList('some.optionList.field')
|
||||
* optionList.clear()
|
||||
* ```
|
||||
* This method will mark this option list as dirty. See
|
||||
* [[PDFOptionList.setOptions]] for more details about what this means.
|
||||
*/
|
||||
clear(): void;
|
||||
/**
|
||||
* Set the font size for the text in this field. There needs to be a
|
||||
* default appearance string (DA) set with a font value specified
|
||||
* for this to work. For example:
|
||||
* ```js
|
||||
* const optionList = form.getOptionList('some.optionList.field')
|
||||
* optionList.setFontSize(4);
|
||||
* ```
|
||||
* @param fontSize The font size to set the font to.
|
||||
*/
|
||||
/**
|
||||
* Set the font size for this field. Larger font sizes will result in larger
|
||||
* text being displayed when PDF readers render this option list. Font sizes
|
||||
* may be integer or floating point numbers. Supplying a negative font size
|
||||
* will cause this method to throw an error.
|
||||
*
|
||||
* For example:
|
||||
* ```js
|
||||
* const optionList = form.getOptionList('some.optionList.field')
|
||||
* optionList.setFontSize(4)
|
||||
* optionList.setFontSize(15.7)
|
||||
* ```
|
||||
*
|
||||
* > This method depends upon the existence of a default appearance
|
||||
* > (`/DA`) string. If this field does not have a default appearance string,
|
||||
* > or that string does not contain a font size (via the `Tf` operator),
|
||||
* > then this method will throw an error.
|
||||
*
|
||||
* @param fontSize The font size to be used when rendering text in this field.
|
||||
*/
|
||||
setFontSize(fontSize: number): void;
|
||||
/**
|
||||
* Returns `true` if the options of this option list are always displayed
|
||||
* in alphabetical order, irrespective of the order in which the options
|
||||
* were added to the option list. See [[PDFOptionList.enableSorting]] and
|
||||
* [[PDFOptionList.disableSorting]]. For example:
|
||||
* ```js
|
||||
* const optionList = form.getOptionList('some.optionList.field')
|
||||
* if (optionList.isSorted()) console.log('Sorting is enabled')
|
||||
* ```
|
||||
* @returns Whether or not this option list is sorted.
|
||||
*/
|
||||
isSorted(): boolean;
|
||||
/**
|
||||
* Always display the options of this option list in alphabetical order,
|
||||
* irrespective of the order in which the options were added to this option
|
||||
* list.
|
||||
* For example:
|
||||
* ```js
|
||||
* const optionList = form.getOptionList('some.optionList.field')
|
||||
* optionList.enableSorting()
|
||||
* ```
|
||||
*/
|
||||
enableSorting(): void;
|
||||
/**
|
||||
* Do not always display the options of this option list in alphabetical
|
||||
* order. Instead, display the options in whichever order they were added
|
||||
* to this option list. For example:
|
||||
* ```js
|
||||
* const optionList = form.getOptionList('some.optionList.field')
|
||||
* optionList.disableSorting()
|
||||
* ```
|
||||
*/
|
||||
disableSorting(): void;
|
||||
/**
|
||||
* Returns `true` if multiple options can be selected from this option list.
|
||||
* See [[PDFOptionList.enableMultiselect]] and
|
||||
* [[PDFOptionList.disableMultiselect]]. For example:
|
||||
* ```js
|
||||
* const optionList = form.getOptionList('some.optionList.field')
|
||||
* if (optionList.isMultiselect()) console.log('Multiselect is enabled')
|
||||
* ```
|
||||
* @returns Whether or not multiple options can be selected.
|
||||
*/
|
||||
isMultiselect(): boolean;
|
||||
/**
|
||||
* Allow users to select more than one option from this option list.
|
||||
* For example:
|
||||
* ```js
|
||||
* const optionList = form.getOptionList('some.optionList.field')
|
||||
* optionList.enableMultiselect()
|
||||
* ```
|
||||
*/
|
||||
enableMultiselect(): void;
|
||||
/**
|
||||
* Do not allow users to select more than one option from this option list.
|
||||
* For example:
|
||||
* ```js
|
||||
* const optionList = form.getOptionList('some.optionList.field')
|
||||
* optionList.disableMultiselect()
|
||||
* ```
|
||||
*/
|
||||
disableMultiselect(): void;
|
||||
/**
|
||||
* Returns `true` if the option selected by a user is stored, or "committed",
|
||||
* when the user clicks the option. The alternative is that the user's
|
||||
* selection is stored when the user leaves this option list field (by
|
||||
* clicking outside of it - on another field, for example). See
|
||||
* [[PDFOptionList.enableSelectOnClick]] and
|
||||
* [[PDFOptionList.disableSelectOnClick]]. For example:
|
||||
* ```js
|
||||
* const optionList = form.getOptionList('some.optionList.field')
|
||||
* if (optionList.isSelectOnClick()) console.log('Select on click is enabled')
|
||||
* ```
|
||||
* @returns Whether or not options are selected immediately after they are
|
||||
* clicked.
|
||||
*/
|
||||
isSelectOnClick(): boolean;
|
||||
/**
|
||||
* Store the option selected by a user immediately after the user clicks the
|
||||
* option. Do not wait for the user to leave this option list field (by
|
||||
* clicking outside of it - on another field, for example). For example:
|
||||
* ```js
|
||||
* const optionList = form.getOptionList('some.optionList.field')
|
||||
* optionList.enableSelectOnClick()
|
||||
* ```
|
||||
*/
|
||||
enableSelectOnClick(): void;
|
||||
/**
|
||||
* Wait to store the option selected by a user until they leave this option
|
||||
* list field (by clicking outside of it - on another field, for example).
|
||||
* For example:
|
||||
* ```js
|
||||
* const optionList = form.getOptionList('some.optionList.field')
|
||||
* optionList.disableSelectOnClick()
|
||||
* ```
|
||||
*/
|
||||
disableSelectOnClick(): void;
|
||||
/**
|
||||
* Show this option list on the specified page. For example:
|
||||
* ```js
|
||||
* const ubuntuFont = await pdfDoc.embedFont(ubuntuFontBytes)
|
||||
* const page = pdfDoc.addPage()
|
||||
*
|
||||
* const form = pdfDoc.getForm()
|
||||
* const optionList = form.createOptionList('best.gundams')
|
||||
* optionList.setOptions(['Exia', 'Dynames', 'Kyrios', 'Virtue'])
|
||||
* optionList.select(['Exia', 'Virtue'])
|
||||
*
|
||||
* optionList.addToPage(page, {
|
||||
* x: 50,
|
||||
* y: 75,
|
||||
* width: 200,
|
||||
* height: 100,
|
||||
* textColor: rgb(1, 0, 0),
|
||||
* backgroundColor: rgb(0, 1, 0),
|
||||
* borderColor: rgb(0, 0, 1),
|
||||
* borderWidth: 2,
|
||||
* rotate: degrees(90),
|
||||
* font: ubuntuFont,
|
||||
* })
|
||||
* ```
|
||||
* This will create a new widget for this option list field.
|
||||
* @param page The page to which this option list widget should be added.
|
||||
* @param options The options to be used when adding this option list widget.
|
||||
*/
|
||||
addToPage(page: PDFPage, options?: FieldAppearanceOptions): void;
|
||||
/**
|
||||
* Returns `true` if this option list has been marked as dirty, or if any of
|
||||
* this option list's widgets do not have an appearance stream. For example:
|
||||
* ```js
|
||||
* const optionList = form.getOptionList('some.optionList.field')
|
||||
* if (optionList.needsAppearancesUpdate()) console.log('Needs update')
|
||||
* ```
|
||||
* @returns Whether or not this option list needs an appearance update.
|
||||
*/
|
||||
needsAppearancesUpdate(): boolean;
|
||||
/**
|
||||
* Update the appearance streams for each of this option list's widgets using
|
||||
* the default appearance provider for option lists. For example:
|
||||
* ```js
|
||||
* const helvetica = await pdfDoc.embedFont(StandardFonts.Helvetica)
|
||||
* const optionList = form.getOptionList('some.optionList.field')
|
||||
* optionList.defaultUpdateAppearances(helvetica)
|
||||
* ```
|
||||
* @param font The font to be used for creating the appearance streams.
|
||||
*/
|
||||
defaultUpdateAppearances(font: PDFFont): void;
|
||||
/**
|
||||
* Update the appearance streams for each of this option list's widgets using
|
||||
* the given appearance provider. If no `provider` is passed, the default
|
||||
* appearance provider for option lists will be used. For example:
|
||||
* ```js
|
||||
* const helvetica = await pdfDoc.embedFont(StandardFonts.Helvetica)
|
||||
* const optionList = form.getOptionList('some.optionList.field')
|
||||
* optionList.updateAppearances(helvetica, (field, widget, font) => {
|
||||
* ...
|
||||
* return drawOptionList(...)
|
||||
* })
|
||||
* ```
|
||||
* @param font The font to be used for creating the appearance streams.
|
||||
* @param provider Optionally, the appearance provider to be used for
|
||||
* generating the contents of the appearance streams.
|
||||
*/
|
||||
updateAppearances(font: PDFFont, provider?: AppearanceProviderFor<PDFOptionList>): void;
|
||||
private updateWidgetAppearance;
|
||||
}
|
||||
//# sourceMappingURL=PDFOptionList.d.ts.map
|
||||
1
node_modules/pdf-lib/es/api/form/PDFOptionList.d.ts.map
generated
vendored
Normal file
1
node_modules/pdf-lib/es/api/form/PDFOptionList.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"PDFOptionList.d.ts","sourceRoot":"","sources":["../../../src/api/form/PDFOptionList.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,uBAA4B;AAC9C,OAAO,OAAO,mBAAwB;AACtC,OAAO,OAAO,mBAAwB;AACtC,OAAO,QAAQ,EAAE,EACf,sBAAsB,EAEvB,mBAA8B;AAC/B,OAAO,EACL,qBAAqB,EAGtB,sBAAiC;AAIlC,OAAO,EACL,MAAM,EAIN,cAAc,EAGf,mBAAiB;AAQlB;;;;;;;;;;GAUG;AACH,MAAM,CAAC,OAAO,OAAO,aAAc,SAAQ,QAAQ;IACjD;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,EAAE,gBAAiB,cAAc,OAAO,MAAM,OAAO,WAAW,mBAC5B;IAE3C,gEAAgE;IAChE,QAAQ,CAAC,SAAS,EAAE,cAAc,CAAC;IAEnC,OAAO;IAYP;;;;;;;;;;OAUG;IACH,UAAU,IAAI,MAAM,EAAE;IAYtB;;;;;;;;;;;OAWG;IACH,WAAW,IAAI,MAAM,EAAE;IAWvB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACH,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE;IAW5B;;;;;;;;;;;;;OAaG;IACH,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE;IAoBrC;;;;;;;;;;;;;;;;OAgBG;IACH,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,KAAK,UAAQ;IA4BhD;;;;;;;;;;;;OAYG;IACH,KAAK;IAKL;;;;;;;;;OASG;IAEH;;;;;;;;;;;;;;;;;;;OAmBG;IACH,WAAW,CAAC,QAAQ,EAAE,MAAM;IAM5B;;;;;;;;;;OAUG;IACH,QAAQ,IAAI,OAAO;IAInB;;;;;;;;;OASG;IACH,aAAa;IAIb;;;;;;;;OAQG;IACH,cAAc;IAId;;;;;;;;;OASG;IACH,aAAa,IAAI,OAAO;IAIxB;;;;;;;OAOG;IACH,iBAAiB;IAIjB;;;;;;;OAOG;IACH,kBAAkB;IAIlB;;;;;;;;;;;;;OAaG;IACH,eAAe,IAAI,OAAO;IAI1B;;;;;;;;OAQG;IACH,mBAAmB;IAInB;;;;;;;;OAQG;IACH,oBAAoB;IAIpB;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACH,SAAS,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,sBAAsB;IAsCzD;;;;;;;;OAQG;IACH,sBAAsB,IAAI,OAAO;IAcjC;;;;;;;;;OASG;IACH,wBAAwB,CAAC,IAAI,EAAE,OAAO;IAKtC;;;;;;;;;;;;;;;OAeG;IACH,iBAAiB,CACf,IAAI,EAAE,OAAO,EACb,QAAQ,CAAC,EAAE,qBAAqB,CAAC,aAAa,CAAC;IAoBjD,OAAO,CAAC,sBAAsB;CAS/B"}
|
||||
497
node_modules/pdf-lib/es/api/form/PDFOptionList.js
generated
vendored
Normal file
497
node_modules/pdf-lib/es/api/form/PDFOptionList.js
generated
vendored
Normal file
@@ -0,0 +1,497 @@
|
||||
import { __extends } from "tslib";
|
||||
import PDFPage from "../PDFPage";
|
||||
import PDFFont from "../PDFFont";
|
||||
import PDFField, { assertFieldAppearanceOptions, } from "./PDFField";
|
||||
import { normalizeAppearance, defaultOptionListAppearanceProvider, } from "./appearances";
|
||||
import { rgb } from "../colors";
|
||||
import { degrees } from "../rotations";
|
||||
import { PDFHexString, PDFStream, PDFAcroListBox, AcroChoiceFlags, } from "../../core";
|
||||
import { assertIs, assertIsSubset, assertOrUndefined, assertPositive, } from "../../utils";
|
||||
/**
|
||||
* Represents an option list field of a [[PDFForm]].
|
||||
*
|
||||
* [[PDFOptionList]] fields are interactive lists of options. The purpose of an
|
||||
* option list is to enable users to select one or more options from a set of
|
||||
* possible options. Users are able to see the full set of options without
|
||||
* first having to click on the field (though scrolling may be necessary).
|
||||
* Clicking an option in the list will cause it to be selected and displayed
|
||||
* with a highlighted background. Some option lists allow users to select
|
||||
* more than one option (see [[PDFOptionList.isMultiselect]]).
|
||||
*/
|
||||
var PDFOptionList = /** @class */ (function (_super) {
|
||||
__extends(PDFOptionList, _super);
|
||||
function PDFOptionList(acroListBox, ref, doc) {
|
||||
var _this = _super.call(this, acroListBox, ref, doc) || this;
|
||||
assertIs(acroListBox, 'acroListBox', [[PDFAcroListBox, 'PDFAcroListBox']]);
|
||||
_this.acroField = acroListBox;
|
||||
return _this;
|
||||
}
|
||||
/**
|
||||
* Get the list of available options for this option list. These options will
|
||||
* be displayed to users who view this option list in a PDF reader.
|
||||
* For example:
|
||||
* ```js
|
||||
* const optionList = form.getOptionList('some.optionList.field')
|
||||
* const options = optionList.getOptions()
|
||||
* console.log('Option List options:', options)
|
||||
* ```
|
||||
* @returns The options for this option list.
|
||||
*/
|
||||
PDFOptionList.prototype.getOptions = function () {
|
||||
var rawOptions = this.acroField.getOptions();
|
||||
var options = new Array(rawOptions.length);
|
||||
for (var idx = 0, len = options.length; idx < len; idx++) {
|
||||
var _a = rawOptions[idx], display = _a.display, value = _a.value;
|
||||
options[idx] = (display !== null && display !== void 0 ? display : value).decodeText();
|
||||
}
|
||||
return options;
|
||||
};
|
||||
/**
|
||||
* Get the selected options for this option list. These are the values that
|
||||
* were selected by a human user via a PDF reader, or programatically via
|
||||
* software.
|
||||
* For example:
|
||||
* ```js
|
||||
* const optionList = form.getOptionList('some.optionList.field')
|
||||
* const selections = optionList.getSelected()
|
||||
* console.log('Option List selections:', selections)
|
||||
* ```
|
||||
* @returns The selected options for this option list.
|
||||
*/
|
||||
PDFOptionList.prototype.getSelected = function () {
|
||||
var values = this.acroField.getValues();
|
||||
var selected = new Array(values.length);
|
||||
for (var idx = 0, len = values.length; idx < len; idx++) {
|
||||
selected[idx] = values[idx].decodeText();
|
||||
}
|
||||
return selected;
|
||||
};
|
||||
/**
|
||||
* Set the list of options that are available for this option list. These are
|
||||
* the values that will be available for users to select when they view this
|
||||
* option list in a PDF reader. Note that preexisting options for this
|
||||
* option list will be removed. Only the values passed as `options` will be
|
||||
* available to select.
|
||||
*
|
||||
* For example:
|
||||
* ```js
|
||||
* const optionList = form.getOptionList('planets.optionList')
|
||||
* optionList.setOptions(['Earth', 'Mars', 'Pluto', 'Venus'])
|
||||
* ```
|
||||
*
|
||||
* This method will mark this option list as dirty, causing its appearance
|
||||
* streams to be updated when either [[PDFDocument.save]] or
|
||||
* [[PDFForm.updateFieldAppearances]] is called. The updated streams will
|
||||
* display the options this field contains inside the widgets of this text
|
||||
* field (with selected options highlighted).
|
||||
*
|
||||
* **IMPORTANT:** The default font used to update appearance streams is
|
||||
* [[StandardFonts.Helvetica]]. Note that this is a WinAnsi font. This means
|
||||
* that encoding errors will be thrown if this field contains any options
|
||||
* with characters outside the WinAnsi character set (the latin alphabet).
|
||||
*
|
||||
* Embedding a custom font and passing it to
|
||||
* [[PDFForm.updateFieldAppearances]] or [[PDFOptionList.updateAppearances]]
|
||||
* allows you to generate appearance streams with characters outside the
|
||||
* latin alphabet (assuming the custom font supports them).
|
||||
*
|
||||
* @param options The options that should be available in this option list.
|
||||
*/
|
||||
PDFOptionList.prototype.setOptions = function (options) {
|
||||
assertIs(options, 'options', [Array]);
|
||||
this.markAsDirty();
|
||||
var optionObjects = new Array(options.length);
|
||||
for (var idx = 0, len = options.length; idx < len; idx++) {
|
||||
optionObjects[idx] = { value: PDFHexString.fromText(options[idx]) };
|
||||
}
|
||||
this.acroField.setOptions(optionObjects);
|
||||
};
|
||||
/**
|
||||
* Add to the list of options that are available for this option list. Users
|
||||
* will be able to select these values in a PDF reader. In addition to the
|
||||
* values passed as `options`, any preexisting options for this option list
|
||||
* will still be available for users to select.
|
||||
* For example:
|
||||
* ```js
|
||||
* const optionList = form.getOptionList('rockets.optionList')
|
||||
* optionList.addOptions(['Saturn IV', 'Falcon Heavy'])
|
||||
* ```
|
||||
* This method will mark this option list as dirty. See
|
||||
* [[PDFOptionList.setOptions]] for more details about what this means.
|
||||
* @param options New options that should be available in this option list.
|
||||
*/
|
||||
PDFOptionList.prototype.addOptions = function (options) {
|
||||
assertIs(options, 'options', ['string', Array]);
|
||||
this.markAsDirty();
|
||||
var optionsArr = Array.isArray(options) ? options : [options];
|
||||
var existingOptions = this.acroField.getOptions();
|
||||
var newOptions = new Array(optionsArr.length);
|
||||
for (var idx = 0, len = optionsArr.length; idx < len; idx++) {
|
||||
newOptions[idx] = { value: PDFHexString.fromText(optionsArr[idx]) };
|
||||
}
|
||||
this.acroField.setOptions(existingOptions.concat(newOptions));
|
||||
};
|
||||
/**
|
||||
* Select one or more values for this option list. This operation is analogous
|
||||
* to a human user opening the option list in a PDF reader and clicking on one
|
||||
* or more values to select them. This method will update the underlying state
|
||||
* of the option list to indicate which values have been selected. PDF
|
||||
* libraries and readers will be able to extract these values from the saved
|
||||
* document and determine which values were selected.
|
||||
* For example:
|
||||
* ```js
|
||||
* const optionList = form.getOptionList('best.superheroes.optionList')
|
||||
* optionList.select(['One Punch Man', 'Iron Man'])
|
||||
* ```
|
||||
* This method will mark this option list as dirty. See
|
||||
* [[PDFOptionList.setOptions]] for more details about what this means.
|
||||
* @param options The options to be selected.
|
||||
* @param merge Whether or not existing selections should be preserved.
|
||||
*/
|
||||
PDFOptionList.prototype.select = function (options, merge) {
|
||||
if (merge === void 0) { merge = false; }
|
||||
assertIs(options, 'options', ['string', Array]);
|
||||
assertIs(merge, 'merge', ['boolean']);
|
||||
var optionsArr = Array.isArray(options) ? options : [options];
|
||||
var validOptions = this.getOptions();
|
||||
assertIsSubset(optionsArr, 'option', validOptions);
|
||||
this.markAsDirty();
|
||||
if (optionsArr.length > 1 || (optionsArr.length === 1 && merge)) {
|
||||
this.enableMultiselect();
|
||||
}
|
||||
var values = new Array(optionsArr.length);
|
||||
for (var idx = 0, len = optionsArr.length; idx < len; idx++) {
|
||||
values[idx] = PDFHexString.fromText(optionsArr[idx]);
|
||||
}
|
||||
if (merge) {
|
||||
var existingValues = this.acroField.getValues();
|
||||
this.acroField.setValues(existingValues.concat(values));
|
||||
}
|
||||
else {
|
||||
this.acroField.setValues(values);
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Clear all selected values for this option list. This operation is
|
||||
* equivalent to selecting an empty list. This method will update the
|
||||
* underlying state of the option list to indicate that no values have been
|
||||
* selected.
|
||||
* For example:
|
||||
* ```js
|
||||
* const optionList = form.getOptionList('some.optionList.field')
|
||||
* optionList.clear()
|
||||
* ```
|
||||
* This method will mark this option list as dirty. See
|
||||
* [[PDFOptionList.setOptions]] for more details about what this means.
|
||||
*/
|
||||
PDFOptionList.prototype.clear = function () {
|
||||
this.markAsDirty();
|
||||
this.acroField.setValues([]);
|
||||
};
|
||||
/**
|
||||
* Set the font size for the text in this field. There needs to be a
|
||||
* default appearance string (DA) set with a font value specified
|
||||
* for this to work. For example:
|
||||
* ```js
|
||||
* const optionList = form.getOptionList('some.optionList.field')
|
||||
* optionList.setFontSize(4);
|
||||
* ```
|
||||
* @param fontSize The font size to set the font to.
|
||||
*/
|
||||
/**
|
||||
* Set the font size for this field. Larger font sizes will result in larger
|
||||
* text being displayed when PDF readers render this option list. Font sizes
|
||||
* may be integer or floating point numbers. Supplying a negative font size
|
||||
* will cause this method to throw an error.
|
||||
*
|
||||
* For example:
|
||||
* ```js
|
||||
* const optionList = form.getOptionList('some.optionList.field')
|
||||
* optionList.setFontSize(4)
|
||||
* optionList.setFontSize(15.7)
|
||||
* ```
|
||||
*
|
||||
* > This method depends upon the existence of a default appearance
|
||||
* > (`/DA`) string. If this field does not have a default appearance string,
|
||||
* > or that string does not contain a font size (via the `Tf` operator),
|
||||
* > then this method will throw an error.
|
||||
*
|
||||
* @param fontSize The font size to be used when rendering text in this field.
|
||||
*/
|
||||
PDFOptionList.prototype.setFontSize = function (fontSize) {
|
||||
assertPositive(fontSize, 'fontSize');
|
||||
this.acroField.setFontSize(fontSize);
|
||||
this.markAsDirty();
|
||||
};
|
||||
/**
|
||||
* Returns `true` if the options of this option list are always displayed
|
||||
* in alphabetical order, irrespective of the order in which the options
|
||||
* were added to the option list. See [[PDFOptionList.enableSorting]] and
|
||||
* [[PDFOptionList.disableSorting]]. For example:
|
||||
* ```js
|
||||
* const optionList = form.getOptionList('some.optionList.field')
|
||||
* if (optionList.isSorted()) console.log('Sorting is enabled')
|
||||
* ```
|
||||
* @returns Whether or not this option list is sorted.
|
||||
*/
|
||||
PDFOptionList.prototype.isSorted = function () {
|
||||
return this.acroField.hasFlag(AcroChoiceFlags.Sort);
|
||||
};
|
||||
/**
|
||||
* Always display the options of this option list in alphabetical order,
|
||||
* irrespective of the order in which the options were added to this option
|
||||
* list.
|
||||
* For example:
|
||||
* ```js
|
||||
* const optionList = form.getOptionList('some.optionList.field')
|
||||
* optionList.enableSorting()
|
||||
* ```
|
||||
*/
|
||||
PDFOptionList.prototype.enableSorting = function () {
|
||||
this.acroField.setFlagTo(AcroChoiceFlags.Sort, true);
|
||||
};
|
||||
/**
|
||||
* Do not always display the options of this option list in alphabetical
|
||||
* order. Instead, display the options in whichever order they were added
|
||||
* to this option list. For example:
|
||||
* ```js
|
||||
* const optionList = form.getOptionList('some.optionList.field')
|
||||
* optionList.disableSorting()
|
||||
* ```
|
||||
*/
|
||||
PDFOptionList.prototype.disableSorting = function () {
|
||||
this.acroField.setFlagTo(AcroChoiceFlags.Sort, false);
|
||||
};
|
||||
/**
|
||||
* Returns `true` if multiple options can be selected from this option list.
|
||||
* See [[PDFOptionList.enableMultiselect]] and
|
||||
* [[PDFOptionList.disableMultiselect]]. For example:
|
||||
* ```js
|
||||
* const optionList = form.getOptionList('some.optionList.field')
|
||||
* if (optionList.isMultiselect()) console.log('Multiselect is enabled')
|
||||
* ```
|
||||
* @returns Whether or not multiple options can be selected.
|
||||
*/
|
||||
PDFOptionList.prototype.isMultiselect = function () {
|
||||
return this.acroField.hasFlag(AcroChoiceFlags.MultiSelect);
|
||||
};
|
||||
/**
|
||||
* Allow users to select more than one option from this option list.
|
||||
* For example:
|
||||
* ```js
|
||||
* const optionList = form.getOptionList('some.optionList.field')
|
||||
* optionList.enableMultiselect()
|
||||
* ```
|
||||
*/
|
||||
PDFOptionList.prototype.enableMultiselect = function () {
|
||||
this.acroField.setFlagTo(AcroChoiceFlags.MultiSelect, true);
|
||||
};
|
||||
/**
|
||||
* Do not allow users to select more than one option from this option list.
|
||||
* For example:
|
||||
* ```js
|
||||
* const optionList = form.getOptionList('some.optionList.field')
|
||||
* optionList.disableMultiselect()
|
||||
* ```
|
||||
*/
|
||||
PDFOptionList.prototype.disableMultiselect = function () {
|
||||
this.acroField.setFlagTo(AcroChoiceFlags.MultiSelect, false);
|
||||
};
|
||||
/**
|
||||
* Returns `true` if the option selected by a user is stored, or "committed",
|
||||
* when the user clicks the option. The alternative is that the user's
|
||||
* selection is stored when the user leaves this option list field (by
|
||||
* clicking outside of it - on another field, for example). See
|
||||
* [[PDFOptionList.enableSelectOnClick]] and
|
||||
* [[PDFOptionList.disableSelectOnClick]]. For example:
|
||||
* ```js
|
||||
* const optionList = form.getOptionList('some.optionList.field')
|
||||
* if (optionList.isSelectOnClick()) console.log('Select on click is enabled')
|
||||
* ```
|
||||
* @returns Whether or not options are selected immediately after they are
|
||||
* clicked.
|
||||
*/
|
||||
PDFOptionList.prototype.isSelectOnClick = function () {
|
||||
return this.acroField.hasFlag(AcroChoiceFlags.CommitOnSelChange);
|
||||
};
|
||||
/**
|
||||
* Store the option selected by a user immediately after the user clicks the
|
||||
* option. Do not wait for the user to leave this option list field (by
|
||||
* clicking outside of it - on another field, for example). For example:
|
||||
* ```js
|
||||
* const optionList = form.getOptionList('some.optionList.field')
|
||||
* optionList.enableSelectOnClick()
|
||||
* ```
|
||||
*/
|
||||
PDFOptionList.prototype.enableSelectOnClick = function () {
|
||||
this.acroField.setFlagTo(AcroChoiceFlags.CommitOnSelChange, true);
|
||||
};
|
||||
/**
|
||||
* Wait to store the option selected by a user until they leave this option
|
||||
* list field (by clicking outside of it - on another field, for example).
|
||||
* For example:
|
||||
* ```js
|
||||
* const optionList = form.getOptionList('some.optionList.field')
|
||||
* optionList.disableSelectOnClick()
|
||||
* ```
|
||||
*/
|
||||
PDFOptionList.prototype.disableSelectOnClick = function () {
|
||||
this.acroField.setFlagTo(AcroChoiceFlags.CommitOnSelChange, false);
|
||||
};
|
||||
/**
|
||||
* Show this option list on the specified page. For example:
|
||||
* ```js
|
||||
* const ubuntuFont = await pdfDoc.embedFont(ubuntuFontBytes)
|
||||
* const page = pdfDoc.addPage()
|
||||
*
|
||||
* const form = pdfDoc.getForm()
|
||||
* const optionList = form.createOptionList('best.gundams')
|
||||
* optionList.setOptions(['Exia', 'Dynames', 'Kyrios', 'Virtue'])
|
||||
* optionList.select(['Exia', 'Virtue'])
|
||||
*
|
||||
* optionList.addToPage(page, {
|
||||
* x: 50,
|
||||
* y: 75,
|
||||
* width: 200,
|
||||
* height: 100,
|
||||
* textColor: rgb(1, 0, 0),
|
||||
* backgroundColor: rgb(0, 1, 0),
|
||||
* borderColor: rgb(0, 0, 1),
|
||||
* borderWidth: 2,
|
||||
* rotate: degrees(90),
|
||||
* font: ubuntuFont,
|
||||
* })
|
||||
* ```
|
||||
* This will create a new widget for this option list field.
|
||||
* @param page The page to which this option list widget should be added.
|
||||
* @param options The options to be used when adding this option list widget.
|
||||
*/
|
||||
PDFOptionList.prototype.addToPage = function (page, options) {
|
||||
var _a, _b, _c, _d, _e, _f, _g;
|
||||
assertIs(page, 'page', [[PDFPage, 'PDFPage']]);
|
||||
assertFieldAppearanceOptions(options);
|
||||
if (!options)
|
||||
options = {};
|
||||
if (!('textColor' in options))
|
||||
options.textColor = rgb(0, 0, 0);
|
||||
if (!('backgroundColor' in options))
|
||||
options.backgroundColor = rgb(1, 1, 1);
|
||||
if (!('borderColor' in options))
|
||||
options.borderColor = rgb(0, 0, 0);
|
||||
if (!('borderWidth' in options))
|
||||
options.borderWidth = 1;
|
||||
// Create a widget for this option list
|
||||
var widget = this.createWidget({
|
||||
x: (_a = options.x) !== null && _a !== void 0 ? _a : 0,
|
||||
y: (_b = options.y) !== null && _b !== void 0 ? _b : 0,
|
||||
width: (_c = options.width) !== null && _c !== void 0 ? _c : 200,
|
||||
height: (_d = options.height) !== null && _d !== void 0 ? _d : 100,
|
||||
textColor: options.textColor,
|
||||
backgroundColor: options.backgroundColor,
|
||||
borderColor: options.borderColor,
|
||||
borderWidth: (_e = options.borderWidth) !== null && _e !== void 0 ? _e : 0,
|
||||
rotate: (_f = options.rotate) !== null && _f !== void 0 ? _f : degrees(0),
|
||||
hidden: options.hidden,
|
||||
page: page.ref,
|
||||
});
|
||||
var widgetRef = this.doc.context.register(widget.dict);
|
||||
// Add widget to this field
|
||||
this.acroField.addWidget(widgetRef);
|
||||
// Set appearance streams for widget
|
||||
var font = (_g = options.font) !== null && _g !== void 0 ? _g : this.doc.getForm().getDefaultFont();
|
||||
this.updateWidgetAppearance(widget, font);
|
||||
// Add widget to the given page
|
||||
page.node.addAnnot(widgetRef);
|
||||
};
|
||||
/**
|
||||
* Returns `true` if this option list has been marked as dirty, or if any of
|
||||
* this option list's widgets do not have an appearance stream. For example:
|
||||
* ```js
|
||||
* const optionList = form.getOptionList('some.optionList.field')
|
||||
* if (optionList.needsAppearancesUpdate()) console.log('Needs update')
|
||||
* ```
|
||||
* @returns Whether or not this option list needs an appearance update.
|
||||
*/
|
||||
PDFOptionList.prototype.needsAppearancesUpdate = function () {
|
||||
var _a;
|
||||
if (this.isDirty())
|
||||
return true;
|
||||
var widgets = this.acroField.getWidgets();
|
||||
for (var idx = 0, len = widgets.length; idx < len; idx++) {
|
||||
var widget = widgets[idx];
|
||||
var hasAppearances = ((_a = widget.getAppearances()) === null || _a === void 0 ? void 0 : _a.normal) instanceof PDFStream;
|
||||
if (!hasAppearances)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
/**
|
||||
* Update the appearance streams for each of this option list's widgets using
|
||||
* the default appearance provider for option lists. For example:
|
||||
* ```js
|
||||
* const helvetica = await pdfDoc.embedFont(StandardFonts.Helvetica)
|
||||
* const optionList = form.getOptionList('some.optionList.field')
|
||||
* optionList.defaultUpdateAppearances(helvetica)
|
||||
* ```
|
||||
* @param font The font to be used for creating the appearance streams.
|
||||
*/
|
||||
PDFOptionList.prototype.defaultUpdateAppearances = function (font) {
|
||||
assertIs(font, 'font', [[PDFFont, 'PDFFont']]);
|
||||
this.updateAppearances(font);
|
||||
};
|
||||
/**
|
||||
* Update the appearance streams for each of this option list's widgets using
|
||||
* the given appearance provider. If no `provider` is passed, the default
|
||||
* appearance provider for option lists will be used. For example:
|
||||
* ```js
|
||||
* const helvetica = await pdfDoc.embedFont(StandardFonts.Helvetica)
|
||||
* const optionList = form.getOptionList('some.optionList.field')
|
||||
* optionList.updateAppearances(helvetica, (field, widget, font) => {
|
||||
* ...
|
||||
* return drawOptionList(...)
|
||||
* })
|
||||
* ```
|
||||
* @param font The font to be used for creating the appearance streams.
|
||||
* @param provider Optionally, the appearance provider to be used for
|
||||
* generating the contents of the appearance streams.
|
||||
*/
|
||||
PDFOptionList.prototype.updateAppearances = function (font, provider) {
|
||||
assertIs(font, 'font', [[PDFFont, 'PDFFont']]);
|
||||
assertOrUndefined(provider, 'provider', [Function]);
|
||||
var widgets = this.acroField.getWidgets();
|
||||
for (var idx = 0, len = widgets.length; idx < len; idx++) {
|
||||
var widget = widgets[idx];
|
||||
this.updateWidgetAppearance(widget, font, provider);
|
||||
}
|
||||
this.markAsClean();
|
||||
};
|
||||
// getOption(index: number): string {}
|
||||
// getSelectedIndices(): number[] {}
|
||||
// removeOptions(option: string | string[]) {}
|
||||
// removeIndices(option: number[]) {}
|
||||
// deselect(options: string | string[]) {}
|
||||
// deselectIndices(optionIndices: number[]) {}
|
||||
PDFOptionList.prototype.updateWidgetAppearance = function (widget, font, provider) {
|
||||
var apProvider = provider !== null && provider !== void 0 ? provider : defaultOptionListAppearanceProvider;
|
||||
var appearances = normalizeAppearance(apProvider(this, widget, font));
|
||||
this.updateWidgetAppearanceWithFont(widget, font, appearances);
|
||||
};
|
||||
/**
|
||||
* > **NOTE:** You probably don't want to call this method directly. Instead,
|
||||
* > consider using the [[PDFForm.getOptionList]] method, which will create
|
||||
* > an instance of [[PDFOptionList]] for you.
|
||||
*
|
||||
* Create an instance of [[PDFOptionList]] from an existing acroListBox and
|
||||
* ref
|
||||
*
|
||||
* @param acroComboBox The underlying `PDFAcroListBox` for this option list.
|
||||
* @param ref The unique reference for this option list.
|
||||
* @param doc The document to which this option list will belong.
|
||||
*/
|
||||
PDFOptionList.of = function (acroListBox, ref, doc) {
|
||||
return new PDFOptionList(acroListBox, ref, doc);
|
||||
};
|
||||
return PDFOptionList;
|
||||
}(PDFField));
|
||||
export default PDFOptionList;
|
||||
//# sourceMappingURL=PDFOptionList.js.map
|
||||
1
node_modules/pdf-lib/es/api/form/PDFOptionList.js.map
generated
vendored
Normal file
1
node_modules/pdf-lib/es/api/form/PDFOptionList.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
253
node_modules/pdf-lib/es/api/form/PDFRadioGroup.d.ts
generated
vendored
Normal file
253
node_modules/pdf-lib/es/api/form/PDFRadioGroup.d.ts
generated
vendored
Normal file
@@ -0,0 +1,253 @@
|
||||
import PDFDocument from "../PDFDocument";
|
||||
import PDFPage from "../PDFPage";
|
||||
import PDFField, { FieldAppearanceOptions } from "./PDFField";
|
||||
import { AppearanceProviderFor } from "./appearances";
|
||||
import { PDFRef, PDFAcroRadioButton } from "../../core";
|
||||
/**
|
||||
* Represents a radio group field of a [[PDFForm]].
|
||||
*
|
||||
* [[PDFRadioGroup]] fields are collections of radio buttons. The purpose of a
|
||||
* radio group is to enable users to select one option from a set of mutually
|
||||
* exclusive choices. Each choice in a radio group is represented by a radio
|
||||
* button. Radio buttons each have two states: `on` and `off`. At most one
|
||||
* radio button in a group may be in the `on` state at any time. Users can
|
||||
* click on a radio button to select it (and thereby automatically deselect any
|
||||
* other radio button that might have already been selected). Some radio
|
||||
* groups allow users to toggle a selected radio button `off` by clicking on
|
||||
* it (see [[PDFRadioGroup.isOffToggleable]]).
|
||||
*
|
||||
* Note that some radio groups allow multiple radio buttons to be in the `on`
|
||||
* state at the same type **if** they represent the same underlying value (see
|
||||
* [[PDFRadioGroup.isMutuallyExclusive]]).
|
||||
*/
|
||||
export default class PDFRadioGroup extends PDFField {
|
||||
/**
|
||||
* > **NOTE:** You probably don't want to call this method directly. Instead,
|
||||
* > consider using the [[PDFForm.getOptionList]] method, which will create an
|
||||
* > instance of [[PDFOptionList]] for you.
|
||||
*
|
||||
* Create an instance of [[PDFOptionList]] from an existing acroRadioButton
|
||||
* and ref
|
||||
*
|
||||
* @param acroRadioButton The underlying `PDFAcroRadioButton` for this
|
||||
* radio group.
|
||||
* @param ref The unique reference for this radio group.
|
||||
* @param doc The document to which this radio group will belong.
|
||||
*/
|
||||
static of: (acroRadioButton: PDFAcroRadioButton, ref: PDFRef, doc: PDFDocument) => PDFRadioGroup;
|
||||
/** The low-level PDFAcroRadioButton wrapped by this radio group. */
|
||||
readonly acroField: PDFAcroRadioButton;
|
||||
private constructor();
|
||||
/**
|
||||
* Get the list of available options for this radio group. Each option is
|
||||
* represented by a radio button. These radio buttons are displayed at
|
||||
* various locations in the document, potentially on different pages (though
|
||||
* typically they are stacked horizontally or vertically on the same page).
|
||||
* For example:
|
||||
* ```js
|
||||
* const radioGroup = form.getRadioGroup('some.radioGroup.field')
|
||||
* const options = radioGroup.getOptions()
|
||||
* console.log('Radio Group options:', options)
|
||||
* ```
|
||||
* @returns The options for this radio group.
|
||||
*/
|
||||
getOptions(): string[];
|
||||
/**
|
||||
* Get the selected option for this radio group. The selected option is
|
||||
* represented by the radio button in this group that is turned on. At most
|
||||
* one radio button in a group can be selected. If no buttons in this group
|
||||
* are selected, `undefined` is returned.
|
||||
* For example:
|
||||
* ```js
|
||||
* const radioGroup = form.getRadioGroup('some.radioGroup.field')
|
||||
* const selected = radioGroup.getSelected()
|
||||
* console.log('Selected radio button:', selected)
|
||||
* ```
|
||||
* @returns The selected option for this radio group.
|
||||
*/
|
||||
getSelected(): string | undefined;
|
||||
/**
|
||||
* Select an option for this radio group. This operation is analogous to a
|
||||
* human user clicking one of the radio buttons in this group via a PDF
|
||||
* reader to toggle it on. This method will update the underlying state of
|
||||
* the radio group to indicate which option has been selected. PDF libraries
|
||||
* and readers will be able to extract this value from the saved document and
|
||||
* determine which option was selected.
|
||||
*
|
||||
* For example:
|
||||
* ```js
|
||||
* const radioGroup = form.getRadioGroup('best.superhero.radioGroup')
|
||||
* radioGroup.select('One Punch Man')
|
||||
* ```
|
||||
*
|
||||
* This method will mark this radio group as dirty, causing its appearance
|
||||
* streams to be updated when either [[PDFDocument.save]] or
|
||||
* [[PDFForm.updateFieldAppearances]] is called. The updated appearance
|
||||
* streams will display a dot inside the widget of this check box field
|
||||
* that represents the selected option.
|
||||
*
|
||||
* @param option The option to be selected.
|
||||
*/
|
||||
select(option: string): void;
|
||||
/**
|
||||
* Clear any selected option for this dropdown. This will result in all
|
||||
* radio buttons in this group being toggled off. This method will update
|
||||
* the underlying state of the dropdown to indicate that no radio buttons
|
||||
* have been selected.
|
||||
* For example:
|
||||
* ```js
|
||||
* const radioGroup = form.getRadioGroup('some.radioGroup.field')
|
||||
* radioGroup.clear()
|
||||
* ```
|
||||
* This method will mark this radio group as dirty. See
|
||||
* [[PDFRadioGroup.select]] for more details about what this means.
|
||||
*/
|
||||
clear(): void;
|
||||
/**
|
||||
* Returns `true` if users can click on radio buttons in this group to toggle
|
||||
* them off. The alternative is that once a user clicks on a radio button
|
||||
* to select it, the only way to deselect it is by selecting on another radio
|
||||
* button in the group. See [[PDFRadioGroup.enableOffToggling]] and
|
||||
* [[PDFRadioGroup.disableOffToggling]]. For example:
|
||||
* ```js
|
||||
* const radioGroup = form.getRadioGroup('some.radioGroup.field')
|
||||
* if (radioGroup.isOffToggleable()) console.log('Off toggling is enabled')
|
||||
* ```
|
||||
*/
|
||||
isOffToggleable(): boolean;
|
||||
/**
|
||||
* Allow users to click on selected radio buttons in this group to toggle
|
||||
* them off. For example:
|
||||
* ```js
|
||||
* const radioGroup = form.getRadioGroup('some.radioGroup.field')
|
||||
* radioGroup.enableOffToggling()
|
||||
* ```
|
||||
* > **NOTE:** This feature is documented in the PDF specification
|
||||
* > (Table 226). However, most PDF readers do not respect this option and
|
||||
* > prevent users from toggling radio buttons off even when it is enabled.
|
||||
* > At the time of this writing (9/6/2020) Mac's Preview software did
|
||||
* > respect the option. Adobe Acrobat, Foxit Reader, and Google Chrome did
|
||||
* > not.
|
||||
*/
|
||||
enableOffToggling(): void;
|
||||
/**
|
||||
* Prevent users from clicking on selected radio buttons in this group to
|
||||
* toggle them off. Clicking on a selected radio button will have no effect.
|
||||
* The only way to deselect a selected radio button is to click on a
|
||||
* different radio button in the group. For example:
|
||||
* ```js
|
||||
* const radioGroup = form.getRadioGroup('some.radioGroup.field')
|
||||
* radioGroup.disableOffToggling()
|
||||
* ```
|
||||
*/
|
||||
disableOffToggling(): void;
|
||||
/**
|
||||
* Returns `true` if the radio buttons in this group are mutually exclusive.
|
||||
* This means that when the user selects a radio button, only that specific
|
||||
* button will be turned on. Even if other radio buttons in the group
|
||||
* represent the same value, they will not be enabled. The alternative to
|
||||
* this is that clicking a radio button will select that button along with
|
||||
* any other radio buttons in the group that share the same value. See
|
||||
* [[PDFRadioGroup.enableMutualExclusion]] and
|
||||
* [[PDFRadioGroup.disableMutualExclusion]].
|
||||
* For example:
|
||||
* ```js
|
||||
* const radioGroup = form.getRadioGroup('some.radioGroup.field')
|
||||
* if (radioGroup.isMutuallyExclusive()) console.log('Mutual exclusion is enabled')
|
||||
* ```
|
||||
*/
|
||||
isMutuallyExclusive(): boolean;
|
||||
/**
|
||||
* When the user clicks a radio button in this group it will be selected. In
|
||||
* addition, any other radio buttons in this group that share the same
|
||||
* underlying value will also be selected. For example:
|
||||
* ```js
|
||||
* const radioGroup = form.getRadioGroup('some.radioGroup.field')
|
||||
* radioGroup.enableMutualExclusion()
|
||||
* ```
|
||||
* Note that this option must be enabled prior to adding options to the
|
||||
* radio group. It does not currently apply retroactively to existing
|
||||
* radio buttons in the group.
|
||||
*/
|
||||
enableMutualExclusion(): void;
|
||||
/**
|
||||
* When the user clicks a radio button in this group only it will be selected.
|
||||
* No other radio buttons in the group will be selected, even if they share
|
||||
* the same underlying value. For example:
|
||||
* ```js
|
||||
* const radioGroup = form.getRadioGroup('some.radioGroup.field')
|
||||
* radioGroup.disableMutualExclusion()
|
||||
* ```
|
||||
* Note that this option must be disabled prior to adding options to the
|
||||
* radio group. It does not currently apply retroactively to existing
|
||||
* radio buttons in the group.
|
||||
*/
|
||||
disableMutualExclusion(): void;
|
||||
/**
|
||||
* Add a new radio button to this group on the specified page. For example:
|
||||
* ```js
|
||||
* const page = pdfDoc.addPage()
|
||||
*
|
||||
* const form = pdfDoc.getForm()
|
||||
* const radioGroup = form.createRadioGroup('best.gundam')
|
||||
*
|
||||
* const options = {
|
||||
* x: 50,
|
||||
* width: 25,
|
||||
* height: 25,
|
||||
* textColor: rgb(1, 0, 0),
|
||||
* backgroundColor: rgb(0, 1, 0),
|
||||
* borderColor: rgb(0, 0, 1),
|
||||
* borderWidth: 2,
|
||||
* rotate: degrees(90),
|
||||
* }
|
||||
*
|
||||
* radioGroup.addOptionToPage('Exia', page, { ...options, y: 50 })
|
||||
* radioGroup.addOptionToPage('Dynames', page, { ...options, y: 110 })
|
||||
* ```
|
||||
* This will create a new radio button widget for this radio group field.
|
||||
* @param option The option that the radio button widget represents.
|
||||
* @param page The page to which the radio button widget should be added.
|
||||
* @param options The options to be used when adding the radio button widget.
|
||||
*/
|
||||
addOptionToPage(option: string, page: PDFPage, options?: FieldAppearanceOptions): void;
|
||||
/**
|
||||
* Returns `true` if any of this group's radio button widgets do not have an
|
||||
* appearance stream for their current state. For example:
|
||||
* ```js
|
||||
* const radioGroup = form.getRadioGroup('some.radioGroup.field')
|
||||
* if (radioGroup.needsAppearancesUpdate()) console.log('Needs update')
|
||||
* ```
|
||||
* @returns Whether or not this radio group needs an appearance update.
|
||||
*/
|
||||
needsAppearancesUpdate(): boolean;
|
||||
/**
|
||||
* Update the appearance streams for each of this group's radio button widgets
|
||||
* using the default appearance provider for radio groups. For example:
|
||||
* ```js
|
||||
* const radioGroup = form.getRadioGroup('some.radioGroup.field')
|
||||
* radioGroup.defaultUpdateAppearances()
|
||||
* ```
|
||||
*/
|
||||
defaultUpdateAppearances(): void;
|
||||
/**
|
||||
* Update the appearance streams for each of this group's radio button widgets
|
||||
* using the given appearance provider. If no `provider` is passed, the
|
||||
* default appearance provider for radio groups will be used. For example:
|
||||
* ```js
|
||||
* const radioGroup = form.getRadioGroup('some.radioGroup.field')
|
||||
* radioGroup.updateAppearances((field, widget) => {
|
||||
* ...
|
||||
* return {
|
||||
* normal: { on: drawRadioButton(...), off: drawRadioButton(...) },
|
||||
* down: { on: drawRadioButton(...), off: drawRadioButton(...) },
|
||||
* }
|
||||
* })
|
||||
* ```
|
||||
* @param provider Optionally, the appearance provider to be used for
|
||||
* generating the contents of the appearance streams.
|
||||
*/
|
||||
updateAppearances(provider?: AppearanceProviderFor<PDFRadioGroup>): void;
|
||||
private updateWidgetAppearance;
|
||||
}
|
||||
//# sourceMappingURL=PDFRadioGroup.d.ts.map
|
||||
1
node_modules/pdf-lib/es/api/form/PDFRadioGroup.d.ts.map
generated
vendored
Normal file
1
node_modules/pdf-lib/es/api/form/PDFRadioGroup.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"PDFRadioGroup.d.ts","sourceRoot":"","sources":["../../../src/api/form/PDFRadioGroup.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,uBAA4B;AAC9C,OAAO,OAAO,mBAAwB;AACtC,OAAO,QAAQ,EAAE,EACf,sBAAsB,EAEvB,mBAA8B;AAC/B,OAAO,EACL,qBAAqB,EAGtB,sBAAiC;AAIlC,OAAO,EAEL,MAAM,EAIN,kBAAkB,EAEnB,mBAAiB;AAGlB;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,OAAO,OAAO,aAAc,SAAQ,QAAQ;IACjD;;;;;;;;;;;;OAYG;IACH,MAAM,CAAC,EAAE,oBACU,kBAAkB,OAC9B,MAAM,OACN,WAAW,mBACgC;IAElD,oEAAoE;IACpE,QAAQ,CAAC,SAAS,EAAE,kBAAkB,CAAC;IAEvC,OAAO;IAcP;;;;;;;;;;;;OAYG;IACH,UAAU,IAAI,MAAM,EAAE;IAkBtB;;;;;;;;;;;;OAYG;IACH,WAAW,IAAI,MAAM,GAAG,SAAS;IAuCjC;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,MAAM,CAAC,MAAM,EAAE,MAAM;IAwBrB;;;;;;;;;;;;OAYG;IACH,KAAK;IAKL;;;;;;;;;;OAUG;IACH,eAAe;IAIf;;;;;;;;;;;;;OAaG;IACH,iBAAiB;IAIjB;;;;;;;;;OASG;IACH,kBAAkB;IAIlB;;;;;;;;;;;;;;OAcG;IACH,mBAAmB;IAInB;;;;;;;;;;;OAWG;IACH,qBAAqB;IAIrB;;;;;;;;;;;OAWG;IACH,sBAAsB;IAItB;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACH,eAAe,CACb,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,OAAO,EACb,OAAO,CAAC,EAAE,sBAAsB;IAqClC;;;;;;;;OAQG;IACH,sBAAsB,IAAI,OAAO;IAcjC;;;;;;;OAOG;IACH,wBAAwB;IAUxB;;;;;;;;;;;;;;;;OAgBG;IACH,iBAAiB,CAAC,QAAQ,CAAC,EAAE,qBAAqB,CAAC,aAAa,CAAC;IAYjE,OAAO,CAAC,sBAAsB;CAS/B"}
|
||||
413
node_modules/pdf-lib/es/api/form/PDFRadioGroup.js
generated
vendored
Normal file
413
node_modules/pdf-lib/es/api/form/PDFRadioGroup.js
generated
vendored
Normal file
@@ -0,0 +1,413 @@
|
||||
import { __extends } from "tslib";
|
||||
import PDFPage from "../PDFPage";
|
||||
import PDFField, { assertFieldAppearanceOptions, } from "./PDFField";
|
||||
import { normalizeAppearance, defaultRadioGroupAppearanceProvider, } from "./appearances";
|
||||
import { rgb } from "../colors";
|
||||
import { degrees } from "../rotations";
|
||||
import { PDFName, PDFHexString, PDFDict, PDFAcroRadioButton, AcroButtonFlags, } from "../../core";
|
||||
import { assertIs, assertOrUndefined, assertIsOneOf } from "../../utils";
|
||||
/**
|
||||
* Represents a radio group field of a [[PDFForm]].
|
||||
*
|
||||
* [[PDFRadioGroup]] fields are collections of radio buttons. The purpose of a
|
||||
* radio group is to enable users to select one option from a set of mutually
|
||||
* exclusive choices. Each choice in a radio group is represented by a radio
|
||||
* button. Radio buttons each have two states: `on` and `off`. At most one
|
||||
* radio button in a group may be in the `on` state at any time. Users can
|
||||
* click on a radio button to select it (and thereby automatically deselect any
|
||||
* other radio button that might have already been selected). Some radio
|
||||
* groups allow users to toggle a selected radio button `off` by clicking on
|
||||
* it (see [[PDFRadioGroup.isOffToggleable]]).
|
||||
*
|
||||
* Note that some radio groups allow multiple radio buttons to be in the `on`
|
||||
* state at the same type **if** they represent the same underlying value (see
|
||||
* [[PDFRadioGroup.isMutuallyExclusive]]).
|
||||
*/
|
||||
var PDFRadioGroup = /** @class */ (function (_super) {
|
||||
__extends(PDFRadioGroup, _super);
|
||||
function PDFRadioGroup(acroRadioButton, ref, doc) {
|
||||
var _this = _super.call(this, acroRadioButton, ref, doc) || this;
|
||||
assertIs(acroRadioButton, 'acroRadioButton', [
|
||||
[PDFAcroRadioButton, 'PDFAcroRadioButton'],
|
||||
]);
|
||||
_this.acroField = acroRadioButton;
|
||||
return _this;
|
||||
}
|
||||
/**
|
||||
* Get the list of available options for this radio group. Each option is
|
||||
* represented by a radio button. These radio buttons are displayed at
|
||||
* various locations in the document, potentially on different pages (though
|
||||
* typically they are stacked horizontally or vertically on the same page).
|
||||
* For example:
|
||||
* ```js
|
||||
* const radioGroup = form.getRadioGroup('some.radioGroup.field')
|
||||
* const options = radioGroup.getOptions()
|
||||
* console.log('Radio Group options:', options)
|
||||
* ```
|
||||
* @returns The options for this radio group.
|
||||
*/
|
||||
PDFRadioGroup.prototype.getOptions = function () {
|
||||
var exportValues = this.acroField.getExportValues();
|
||||
if (exportValues) {
|
||||
var exportOptions = new Array(exportValues.length);
|
||||
for (var idx = 0, len = exportValues.length; idx < len; idx++) {
|
||||
exportOptions[idx] = exportValues[idx].decodeText();
|
||||
}
|
||||
return exportOptions;
|
||||
}
|
||||
var onValues = this.acroField.getOnValues();
|
||||
var onOptions = new Array(onValues.length);
|
||||
for (var idx = 0, len = onOptions.length; idx < len; idx++) {
|
||||
onOptions[idx] = onValues[idx].decodeText();
|
||||
}
|
||||
return onOptions;
|
||||
};
|
||||
/**
|
||||
* Get the selected option for this radio group. The selected option is
|
||||
* represented by the radio button in this group that is turned on. At most
|
||||
* one radio button in a group can be selected. If no buttons in this group
|
||||
* are selected, `undefined` is returned.
|
||||
* For example:
|
||||
* ```js
|
||||
* const radioGroup = form.getRadioGroup('some.radioGroup.field')
|
||||
* const selected = radioGroup.getSelected()
|
||||
* console.log('Selected radio button:', selected)
|
||||
* ```
|
||||
* @returns The selected option for this radio group.
|
||||
*/
|
||||
PDFRadioGroup.prototype.getSelected = function () {
|
||||
var value = this.acroField.getValue();
|
||||
if (value === PDFName.of('Off'))
|
||||
return undefined;
|
||||
var exportValues = this.acroField.getExportValues();
|
||||
if (exportValues) {
|
||||
var onValues = this.acroField.getOnValues();
|
||||
for (var idx = 0, len = onValues.length; idx < len; idx++) {
|
||||
if (onValues[idx] === value)
|
||||
return exportValues[idx].decodeText();
|
||||
}
|
||||
}
|
||||
return value.decodeText();
|
||||
};
|
||||
// // TODO: Figure out why this seems to crash Acrobat. Maybe it's because we
|
||||
// // aren't removing the widget reference from the page's Annots?
|
||||
// removeOption(option: string) {
|
||||
// assertIs(option, 'option', ['string']);
|
||||
// // TODO: Assert is valid `option`!
|
||||
// const onValues = this.acroField.getOnValues();
|
||||
// const exportValues = this.acroField.getExportValues();
|
||||
// if (exportValues) {
|
||||
// for (let idx = 0, len = exportValues.length; idx < len; idx++) {
|
||||
// if (exportValues[idx].decodeText() === option) {
|
||||
// this.acroField.removeWidget(idx);
|
||||
// this.acroField.removeExportValue(idx);
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// for (let idx = 0, len = onValues.length; idx < len; idx++) {
|
||||
// const value = onValues[idx];
|
||||
// if (value.decodeText() === option) {
|
||||
// this.acroField.removeWidget(idx);
|
||||
// this.acroField.removeExportValue(idx);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
/**
|
||||
* Select an option for this radio group. This operation is analogous to a
|
||||
* human user clicking one of the radio buttons in this group via a PDF
|
||||
* reader to toggle it on. This method will update the underlying state of
|
||||
* the radio group to indicate which option has been selected. PDF libraries
|
||||
* and readers will be able to extract this value from the saved document and
|
||||
* determine which option was selected.
|
||||
*
|
||||
* For example:
|
||||
* ```js
|
||||
* const radioGroup = form.getRadioGroup('best.superhero.radioGroup')
|
||||
* radioGroup.select('One Punch Man')
|
||||
* ```
|
||||
*
|
||||
* This method will mark this radio group as dirty, causing its appearance
|
||||
* streams to be updated when either [[PDFDocument.save]] or
|
||||
* [[PDFForm.updateFieldAppearances]] is called. The updated appearance
|
||||
* streams will display a dot inside the widget of this check box field
|
||||
* that represents the selected option.
|
||||
*
|
||||
* @param option The option to be selected.
|
||||
*/
|
||||
PDFRadioGroup.prototype.select = function (option) {
|
||||
assertIs(option, 'option', ['string']);
|
||||
var validOptions = this.getOptions();
|
||||
assertIsOneOf(option, 'option', validOptions);
|
||||
this.markAsDirty();
|
||||
var onValues = this.acroField.getOnValues();
|
||||
var exportValues = this.acroField.getExportValues();
|
||||
if (exportValues) {
|
||||
for (var idx = 0, len = exportValues.length; idx < len; idx++) {
|
||||
if (exportValues[idx].decodeText() === option) {
|
||||
this.acroField.setValue(onValues[idx]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (var idx = 0, len = onValues.length; idx < len; idx++) {
|
||||
var value = onValues[idx];
|
||||
if (value.decodeText() === option)
|
||||
this.acroField.setValue(value);
|
||||
}
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Clear any selected option for this dropdown. This will result in all
|
||||
* radio buttons in this group being toggled off. This method will update
|
||||
* the underlying state of the dropdown to indicate that no radio buttons
|
||||
* have been selected.
|
||||
* For example:
|
||||
* ```js
|
||||
* const radioGroup = form.getRadioGroup('some.radioGroup.field')
|
||||
* radioGroup.clear()
|
||||
* ```
|
||||
* This method will mark this radio group as dirty. See
|
||||
* [[PDFRadioGroup.select]] for more details about what this means.
|
||||
*/
|
||||
PDFRadioGroup.prototype.clear = function () {
|
||||
this.markAsDirty();
|
||||
this.acroField.setValue(PDFName.of('Off'));
|
||||
};
|
||||
/**
|
||||
* Returns `true` if users can click on radio buttons in this group to toggle
|
||||
* them off. The alternative is that once a user clicks on a radio button
|
||||
* to select it, the only way to deselect it is by selecting on another radio
|
||||
* button in the group. See [[PDFRadioGroup.enableOffToggling]] and
|
||||
* [[PDFRadioGroup.disableOffToggling]]. For example:
|
||||
* ```js
|
||||
* const radioGroup = form.getRadioGroup('some.radioGroup.field')
|
||||
* if (radioGroup.isOffToggleable()) console.log('Off toggling is enabled')
|
||||
* ```
|
||||
*/
|
||||
PDFRadioGroup.prototype.isOffToggleable = function () {
|
||||
return !this.acroField.hasFlag(AcroButtonFlags.NoToggleToOff);
|
||||
};
|
||||
/**
|
||||
* Allow users to click on selected radio buttons in this group to toggle
|
||||
* them off. For example:
|
||||
* ```js
|
||||
* const radioGroup = form.getRadioGroup('some.radioGroup.field')
|
||||
* radioGroup.enableOffToggling()
|
||||
* ```
|
||||
* > **NOTE:** This feature is documented in the PDF specification
|
||||
* > (Table 226). However, most PDF readers do not respect this option and
|
||||
* > prevent users from toggling radio buttons off even when it is enabled.
|
||||
* > At the time of this writing (9/6/2020) Mac's Preview software did
|
||||
* > respect the option. Adobe Acrobat, Foxit Reader, and Google Chrome did
|
||||
* > not.
|
||||
*/
|
||||
PDFRadioGroup.prototype.enableOffToggling = function () {
|
||||
this.acroField.setFlagTo(AcroButtonFlags.NoToggleToOff, false);
|
||||
};
|
||||
/**
|
||||
* Prevent users from clicking on selected radio buttons in this group to
|
||||
* toggle them off. Clicking on a selected radio button will have no effect.
|
||||
* The only way to deselect a selected radio button is to click on a
|
||||
* different radio button in the group. For example:
|
||||
* ```js
|
||||
* const radioGroup = form.getRadioGroup('some.radioGroup.field')
|
||||
* radioGroup.disableOffToggling()
|
||||
* ```
|
||||
*/
|
||||
PDFRadioGroup.prototype.disableOffToggling = function () {
|
||||
this.acroField.setFlagTo(AcroButtonFlags.NoToggleToOff, true);
|
||||
};
|
||||
/**
|
||||
* Returns `true` if the radio buttons in this group are mutually exclusive.
|
||||
* This means that when the user selects a radio button, only that specific
|
||||
* button will be turned on. Even if other radio buttons in the group
|
||||
* represent the same value, they will not be enabled. The alternative to
|
||||
* this is that clicking a radio button will select that button along with
|
||||
* any other radio buttons in the group that share the same value. See
|
||||
* [[PDFRadioGroup.enableMutualExclusion]] and
|
||||
* [[PDFRadioGroup.disableMutualExclusion]].
|
||||
* For example:
|
||||
* ```js
|
||||
* const radioGroup = form.getRadioGroup('some.radioGroup.field')
|
||||
* if (radioGroup.isMutuallyExclusive()) console.log('Mutual exclusion is enabled')
|
||||
* ```
|
||||
*/
|
||||
PDFRadioGroup.prototype.isMutuallyExclusive = function () {
|
||||
return !this.acroField.hasFlag(AcroButtonFlags.RadiosInUnison);
|
||||
};
|
||||
/**
|
||||
* When the user clicks a radio button in this group it will be selected. In
|
||||
* addition, any other radio buttons in this group that share the same
|
||||
* underlying value will also be selected. For example:
|
||||
* ```js
|
||||
* const radioGroup = form.getRadioGroup('some.radioGroup.field')
|
||||
* radioGroup.enableMutualExclusion()
|
||||
* ```
|
||||
* Note that this option must be enabled prior to adding options to the
|
||||
* radio group. It does not currently apply retroactively to existing
|
||||
* radio buttons in the group.
|
||||
*/
|
||||
PDFRadioGroup.prototype.enableMutualExclusion = function () {
|
||||
this.acroField.setFlagTo(AcroButtonFlags.RadiosInUnison, false);
|
||||
};
|
||||
/**
|
||||
* When the user clicks a radio button in this group only it will be selected.
|
||||
* No other radio buttons in the group will be selected, even if they share
|
||||
* the same underlying value. For example:
|
||||
* ```js
|
||||
* const radioGroup = form.getRadioGroup('some.radioGroup.field')
|
||||
* radioGroup.disableMutualExclusion()
|
||||
* ```
|
||||
* Note that this option must be disabled prior to adding options to the
|
||||
* radio group. It does not currently apply retroactively to existing
|
||||
* radio buttons in the group.
|
||||
*/
|
||||
PDFRadioGroup.prototype.disableMutualExclusion = function () {
|
||||
this.acroField.setFlagTo(AcroButtonFlags.RadiosInUnison, true);
|
||||
};
|
||||
/**
|
||||
* Add a new radio button to this group on the specified page. For example:
|
||||
* ```js
|
||||
* const page = pdfDoc.addPage()
|
||||
*
|
||||
* const form = pdfDoc.getForm()
|
||||
* const radioGroup = form.createRadioGroup('best.gundam')
|
||||
*
|
||||
* const options = {
|
||||
* x: 50,
|
||||
* width: 25,
|
||||
* height: 25,
|
||||
* textColor: rgb(1, 0, 0),
|
||||
* backgroundColor: rgb(0, 1, 0),
|
||||
* borderColor: rgb(0, 0, 1),
|
||||
* borderWidth: 2,
|
||||
* rotate: degrees(90),
|
||||
* }
|
||||
*
|
||||
* radioGroup.addOptionToPage('Exia', page, { ...options, y: 50 })
|
||||
* radioGroup.addOptionToPage('Dynames', page, { ...options, y: 110 })
|
||||
* ```
|
||||
* This will create a new radio button widget for this radio group field.
|
||||
* @param option The option that the radio button widget represents.
|
||||
* @param page The page to which the radio button widget should be added.
|
||||
* @param options The options to be used when adding the radio button widget.
|
||||
*/
|
||||
PDFRadioGroup.prototype.addOptionToPage = function (option, page, options) {
|
||||
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
||||
assertIs(option, 'option', ['string']);
|
||||
assertIs(page, 'page', [[PDFPage, 'PDFPage']]);
|
||||
assertFieldAppearanceOptions(options);
|
||||
// Create a widget for this radio button
|
||||
var widget = this.createWidget({
|
||||
x: (_a = options === null || options === void 0 ? void 0 : options.x) !== null && _a !== void 0 ? _a : 0,
|
||||
y: (_b = options === null || options === void 0 ? void 0 : options.y) !== null && _b !== void 0 ? _b : 0,
|
||||
width: (_c = options === null || options === void 0 ? void 0 : options.width) !== null && _c !== void 0 ? _c : 50,
|
||||
height: (_d = options === null || options === void 0 ? void 0 : options.height) !== null && _d !== void 0 ? _d : 50,
|
||||
textColor: (_e = options === null || options === void 0 ? void 0 : options.textColor) !== null && _e !== void 0 ? _e : rgb(0, 0, 0),
|
||||
backgroundColor: (_f = options === null || options === void 0 ? void 0 : options.backgroundColor) !== null && _f !== void 0 ? _f : rgb(1, 1, 1),
|
||||
borderColor: (_g = options === null || options === void 0 ? void 0 : options.borderColor) !== null && _g !== void 0 ? _g : rgb(0, 0, 0),
|
||||
borderWidth: (_h = options === null || options === void 0 ? void 0 : options.borderWidth) !== null && _h !== void 0 ? _h : 1,
|
||||
rotate: (_j = options === null || options === void 0 ? void 0 : options.rotate) !== null && _j !== void 0 ? _j : degrees(0),
|
||||
hidden: options === null || options === void 0 ? void 0 : options.hidden,
|
||||
page: page.ref,
|
||||
});
|
||||
var widgetRef = this.doc.context.register(widget.dict);
|
||||
// Add widget to this field
|
||||
var apStateValue = this.acroField.addWidgetWithOpt(widgetRef, PDFHexString.fromText(option), !this.isMutuallyExclusive());
|
||||
// Set appearance streams for widget
|
||||
widget.setAppearanceState(PDFName.of('Off'));
|
||||
this.updateWidgetAppearance(widget, apStateValue);
|
||||
// Add widget to the given page
|
||||
page.node.addAnnot(widgetRef);
|
||||
};
|
||||
/**
|
||||
* Returns `true` if any of this group's radio button widgets do not have an
|
||||
* appearance stream for their current state. For example:
|
||||
* ```js
|
||||
* const radioGroup = form.getRadioGroup('some.radioGroup.field')
|
||||
* if (radioGroup.needsAppearancesUpdate()) console.log('Needs update')
|
||||
* ```
|
||||
* @returns Whether or not this radio group needs an appearance update.
|
||||
*/
|
||||
PDFRadioGroup.prototype.needsAppearancesUpdate = function () {
|
||||
var _a;
|
||||
var widgets = this.acroField.getWidgets();
|
||||
for (var idx = 0, len = widgets.length; idx < len; idx++) {
|
||||
var widget = widgets[idx];
|
||||
var state = widget.getAppearanceState();
|
||||
var normal = (_a = widget.getAppearances()) === null || _a === void 0 ? void 0 : _a.normal;
|
||||
if (!(normal instanceof PDFDict))
|
||||
return true;
|
||||
if (state && !normal.has(state))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
/**
|
||||
* Update the appearance streams for each of this group's radio button widgets
|
||||
* using the default appearance provider for radio groups. For example:
|
||||
* ```js
|
||||
* const radioGroup = form.getRadioGroup('some.radioGroup.field')
|
||||
* radioGroup.defaultUpdateAppearances()
|
||||
* ```
|
||||
*/
|
||||
PDFRadioGroup.prototype.defaultUpdateAppearances = function () {
|
||||
this.updateAppearances();
|
||||
};
|
||||
// rg.updateAppearances((field: any, widget: any) => {
|
||||
// assert(field === rg);
|
||||
// assert(widget instanceof PDFWidgetAnnotation);
|
||||
// return { on: [...rectangle, ...circle], off: [...rectangle, ...circle] };
|
||||
// });
|
||||
/**
|
||||
* Update the appearance streams for each of this group's radio button widgets
|
||||
* using the given appearance provider. If no `provider` is passed, the
|
||||
* default appearance provider for radio groups will be used. For example:
|
||||
* ```js
|
||||
* const radioGroup = form.getRadioGroup('some.radioGroup.field')
|
||||
* radioGroup.updateAppearances((field, widget) => {
|
||||
* ...
|
||||
* return {
|
||||
* normal: { on: drawRadioButton(...), off: drawRadioButton(...) },
|
||||
* down: { on: drawRadioButton(...), off: drawRadioButton(...) },
|
||||
* }
|
||||
* })
|
||||
* ```
|
||||
* @param provider Optionally, the appearance provider to be used for
|
||||
* generating the contents of the appearance streams.
|
||||
*/
|
||||
PDFRadioGroup.prototype.updateAppearances = function (provider) {
|
||||
assertOrUndefined(provider, 'provider', [Function]);
|
||||
var widgets = this.acroField.getWidgets();
|
||||
for (var idx = 0, len = widgets.length; idx < len; idx++) {
|
||||
var widget = widgets[idx];
|
||||
var onValue = widget.getOnValue();
|
||||
if (!onValue)
|
||||
continue;
|
||||
this.updateWidgetAppearance(widget, onValue, provider);
|
||||
}
|
||||
};
|
||||
PDFRadioGroup.prototype.updateWidgetAppearance = function (widget, onValue, provider) {
|
||||
var apProvider = provider !== null && provider !== void 0 ? provider : defaultRadioGroupAppearanceProvider;
|
||||
var appearances = normalizeAppearance(apProvider(this, widget));
|
||||
this.updateOnOffWidgetAppearance(widget, onValue, appearances);
|
||||
};
|
||||
/**
|
||||
* > **NOTE:** You probably don't want to call this method directly. Instead,
|
||||
* > consider using the [[PDFForm.getOptionList]] method, which will create an
|
||||
* > instance of [[PDFOptionList]] for you.
|
||||
*
|
||||
* Create an instance of [[PDFOptionList]] from an existing acroRadioButton
|
||||
* and ref
|
||||
*
|
||||
* @param acroRadioButton The underlying `PDFAcroRadioButton` for this
|
||||
* radio group.
|
||||
* @param ref The unique reference for this radio group.
|
||||
* @param doc The document to which this radio group will belong.
|
||||
*/
|
||||
PDFRadioGroup.of = function (acroRadioButton, ref, doc) { return new PDFRadioGroup(acroRadioButton, ref, doc); };
|
||||
return PDFRadioGroup;
|
||||
}(PDFField));
|
||||
export default PDFRadioGroup;
|
||||
//# sourceMappingURL=PDFRadioGroup.js.map
|
||||
1
node_modules/pdf-lib/es/api/form/PDFRadioGroup.js.map
generated
vendored
Normal file
1
node_modules/pdf-lib/es/api/form/PDFRadioGroup.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
30
node_modules/pdf-lib/es/api/form/PDFSignature.d.ts
generated
vendored
Normal file
30
node_modules/pdf-lib/es/api/form/PDFSignature.d.ts
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
import PDFDocument from "../PDFDocument";
|
||||
import PDFField from "./PDFField";
|
||||
import { PDFRef, PDFAcroSignature } from "../../core";
|
||||
/**
|
||||
* Represents a signature field of a [[PDFForm]].
|
||||
*
|
||||
* [[PDFSignature]] fields are digital signatures. `pdf-lib` does not
|
||||
* currently provide any specialized APIs for creating digital signatures or
|
||||
* reading the contents of existing digital signatures.
|
||||
*/
|
||||
export default class PDFSignature extends PDFField {
|
||||
/**
|
||||
* > **NOTE:** You probably don't want to call this method directly. Instead,
|
||||
* > consider using the [[PDFForm.getSignature]] method, which will create an
|
||||
* > instance of [[PDFSignature]] for you.
|
||||
*
|
||||
* Create an instance of [[PDFSignature]] from an existing acroSignature and
|
||||
* ref
|
||||
*
|
||||
* @param acroSignature The underlying `PDFAcroSignature` for this signature.
|
||||
* @param ref The unique reference for this signature.
|
||||
* @param doc The document to which this signature will belong.
|
||||
*/
|
||||
static of: (acroSignature: PDFAcroSignature, ref: PDFRef, doc: PDFDocument) => PDFSignature;
|
||||
/** The low-level PDFAcroSignature wrapped by this signature. */
|
||||
readonly acroField: PDFAcroSignature;
|
||||
private constructor();
|
||||
needsAppearancesUpdate(): boolean;
|
||||
}
|
||||
//# sourceMappingURL=PDFSignature.d.ts.map
|
||||
1
node_modules/pdf-lib/es/api/form/PDFSignature.d.ts.map
generated
vendored
Normal file
1
node_modules/pdf-lib/es/api/form/PDFSignature.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"PDFSignature.d.ts","sourceRoot":"","sources":["../../../src/api/form/PDFSignature.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,uBAA4B;AAC9C,OAAO,QAAQ,mBAA8B;AAE7C,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,mBAAiB;AAGpD;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,OAAO,YAAa,SAAQ,QAAQ;IAChD;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,EAAE,kBACQ,gBAAgB,OAC1B,MAAM,OACN,WAAW,kBAC6B;IAE/C,gEAAgE;IAChE,QAAQ,CAAC,SAAS,EAAE,gBAAgB,CAAC;IAErC,OAAO;IAcP,sBAAsB;CAGvB"}
|
||||
41
node_modules/pdf-lib/es/api/form/PDFSignature.js
generated
vendored
Normal file
41
node_modules/pdf-lib/es/api/form/PDFSignature.js
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
import { __extends } from "tslib";
|
||||
import PDFField from "./PDFField";
|
||||
import { PDFAcroSignature } from "../../core";
|
||||
import { assertIs } from "../../utils";
|
||||
/**
|
||||
* Represents a signature field of a [[PDFForm]].
|
||||
*
|
||||
* [[PDFSignature]] fields are digital signatures. `pdf-lib` does not
|
||||
* currently provide any specialized APIs for creating digital signatures or
|
||||
* reading the contents of existing digital signatures.
|
||||
*/
|
||||
var PDFSignature = /** @class */ (function (_super) {
|
||||
__extends(PDFSignature, _super);
|
||||
function PDFSignature(acroSignature, ref, doc) {
|
||||
var _this = _super.call(this, acroSignature, ref, doc) || this;
|
||||
assertIs(acroSignature, 'acroSignature', [
|
||||
[PDFAcroSignature, 'PDFAcroSignature'],
|
||||
]);
|
||||
_this.acroField = acroSignature;
|
||||
return _this;
|
||||
}
|
||||
PDFSignature.prototype.needsAppearancesUpdate = function () {
|
||||
return false;
|
||||
};
|
||||
/**
|
||||
* > **NOTE:** You probably don't want to call this method directly. Instead,
|
||||
* > consider using the [[PDFForm.getSignature]] method, which will create an
|
||||
* > instance of [[PDFSignature]] for you.
|
||||
*
|
||||
* Create an instance of [[PDFSignature]] from an existing acroSignature and
|
||||
* ref
|
||||
*
|
||||
* @param acroSignature The underlying `PDFAcroSignature` for this signature.
|
||||
* @param ref The unique reference for this signature.
|
||||
* @param doc The document to which this signature will belong.
|
||||
*/
|
||||
PDFSignature.of = function (acroSignature, ref, doc) { return new PDFSignature(acroSignature, ref, doc); };
|
||||
return PDFSignature;
|
||||
}(PDFField));
|
||||
export default PDFSignature;
|
||||
//# sourceMappingURL=PDFSignature.js.map
|
||||
1
node_modules/pdf-lib/es/api/form/PDFSignature.js.map
generated
vendored
Normal file
1
node_modules/pdf-lib/es/api/form/PDFSignature.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"PDFSignature.js","sourceRoot":"","sources":["../../../src/api/form/PDFSignature.ts"],"names":[],"mappings":";AACA,OAAO,QAAQ,mBAA8B;AAE7C,OAAO,EAAU,gBAAgB,EAAE,mBAAiB;AACpD,OAAO,EAAE,QAAQ,EAAE,oBAAkB;AAErC;;;;;;GAMG;AACH;IAA0C,gCAAQ;IAsBhD,sBACE,aAA+B,EAC/B,GAAW,EACX,GAAgB;QAHlB,YAKE,kBAAM,aAAa,EAAE,GAAG,EAAE,GAAG,CAAC,SAO/B;QALC,QAAQ,CAAC,aAAa,EAAE,eAAe,EAAE;YACvC,CAAC,gBAAgB,EAAE,kBAAkB,CAAC;SACvC,CAAC,CAAC;QAEH,KAAI,CAAC,SAAS,GAAG,aAAa,CAAC;;IACjC,CAAC;IAED,6CAAsB,GAAtB;QACE,OAAO,KAAK,CAAC;IACf,CAAC;IArCD;;;;;;;;;;;OAWG;IACI,eAAE,GAAG,UACV,aAA+B,EAC/B,GAAW,EACX,GAAgB,IACb,OAAA,IAAI,YAAY,CAAC,aAAa,EAAE,GAAG,EAAE,GAAG,CAAC,EAAzC,CAAyC,CAAC;IAsBjD,mBAAC;CAAA,AAvCD,CAA0C,QAAQ,GAuCjD;eAvCoB,YAAY"}
|
||||
538
node_modules/pdf-lib/es/api/form/PDFTextField.d.ts
generated
vendored
Normal file
538
node_modules/pdf-lib/es/api/form/PDFTextField.d.ts
generated
vendored
Normal file
@@ -0,0 +1,538 @@
|
||||
import PDFDocument from "../PDFDocument";
|
||||
import PDFPage from "../PDFPage";
|
||||
import PDFFont from "../PDFFont";
|
||||
import PDFImage from "../PDFImage";
|
||||
import PDFField, { FieldAppearanceOptions } from "./PDFField";
|
||||
import { AppearanceProviderFor } from "./appearances";
|
||||
import { TextAlignment } from "../text/alignment";
|
||||
import { PDFRef, PDFAcroText } from "../../core";
|
||||
/**
|
||||
* Represents a text field of a [[PDFForm]].
|
||||
*
|
||||
* [[PDFTextField]] fields are boxes that display text entered by the user. The
|
||||
* purpose of a text field is to enable users to enter text or view text values
|
||||
* in the document prefilled by software. Users can click on a text field and
|
||||
* input text via their keyboard. Some text fields allow multiple lines of text
|
||||
* to be entered (see [[PDFTextField.isMultiline]]).
|
||||
*/
|
||||
export default class PDFTextField extends PDFField {
|
||||
/**
|
||||
* > **NOTE:** You probably don't want to call this method directly. Instead,
|
||||
* > consider using the [[PDFForm.getTextField]] method, which will create an
|
||||
* > instance of [[PDFTextField]] for you.
|
||||
*
|
||||
* Create an instance of [[PDFTextField]] from an existing acroText and ref
|
||||
*
|
||||
* @param acroText The underlying `PDFAcroText` for this text field.
|
||||
* @param ref The unique reference for this text field.
|
||||
* @param doc The document to which this text field will belong.
|
||||
*/
|
||||
static of: (acroText: PDFAcroText, ref: PDFRef, doc: PDFDocument) => PDFTextField;
|
||||
/** The low-level PDFAcroText wrapped by this text field. */
|
||||
readonly acroField: PDFAcroText;
|
||||
private constructor();
|
||||
/**
|
||||
* Get the text that this field contains. This text is visible to users who
|
||||
* view this field in a PDF reader.
|
||||
*
|
||||
* For example:
|
||||
* ```js
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
* const text = textField.getText()
|
||||
* console.log('Text field contents:', text)
|
||||
* ```
|
||||
*
|
||||
* Note that if this text field contains no underlying value, `undefined`
|
||||
* will be returned. Text fields may also contain an underlying value that
|
||||
* is simply an empty string (`''`). This detail is largely irrelevant for
|
||||
* most applications. In general, you'll want to treat both cases the same
|
||||
* way and simply consider the text field to be empty. In either case, the
|
||||
* text field will appear empty to users when viewed in a PDF reader.
|
||||
*
|
||||
* An error will be thrown if this is a rich text field. `pdf-lib` does not
|
||||
* support reading rich text fields. Nor do most PDF readers and writers.
|
||||
* Rich text fields are based on XFA (XML Forms Architecture). Relatively few
|
||||
* PDFs use rich text fields or XFA. Unlike PDF itself, XFA is not an ISO
|
||||
* standard. XFA has been deprecated in PDF 2.0:
|
||||
* * https://en.wikipedia.org/wiki/XFA
|
||||
* * http://blog.pdfshareforms.com/pdf-2-0-release-bid-farewell-xfa-forms/
|
||||
*
|
||||
* @returns The text contained in this text field.
|
||||
*/
|
||||
getText(): string | undefined;
|
||||
/**
|
||||
* Set the text for this field. This operation is analogous to a human user
|
||||
* clicking on the text field in a PDF reader and typing in text via their
|
||||
* keyboard. This method will update the underlying state of the text field
|
||||
* to indicate what text has been set. PDF libraries and readers will be able
|
||||
* to extract these values from the saved document and determine what text
|
||||
* was set.
|
||||
*
|
||||
* For example:
|
||||
* ```js
|
||||
* const textField = form.getTextField('best.superhero.text.field')
|
||||
* textField.setText('One Punch Man')
|
||||
* ```
|
||||
*
|
||||
* This method will mark this text field as dirty, causing its appearance
|
||||
* streams to be updated when either [[PDFDocument.save]] or
|
||||
* [[PDFForm.updateFieldAppearances]] is called. The updated streams will
|
||||
* display the text this field contains inside the widgets of this text
|
||||
* field.
|
||||
*
|
||||
* **IMPORTANT:** The default font used to update appearance streams is
|
||||
* [[StandardFonts.Helvetica]]. Note that this is a WinAnsi font. This means
|
||||
* that encoding errors will be thrown if this field contains text outside
|
||||
* the WinAnsi character set (the latin alphabet).
|
||||
*
|
||||
* Embedding a custom font and passing it to
|
||||
* [[PDFForm.updateFieldAppearances]] or [[PDFTextField.updateAppearances]]
|
||||
* allows you to generate appearance streams with characters outside the
|
||||
* latin alphabet (assuming the custom font supports them).
|
||||
*
|
||||
* If this is a rich text field, it will be converted to a standard text
|
||||
* field in order to set the text. `pdf-lib` does not support writing rich
|
||||
* text strings. Nor do most PDF readers and writers. See
|
||||
* [[PDFTextField.getText]] for more information about rich text fields and
|
||||
* their deprecation in PDF 2.0.
|
||||
*
|
||||
* @param text The text this field should contain.
|
||||
*/
|
||||
setText(text: string | undefined): void;
|
||||
/**
|
||||
* Get the alignment for this text field. This value represents the
|
||||
* justification of the text when it is displayed to the user in PDF readers.
|
||||
* There are three possible alignments: left, center, and right. For example:
|
||||
* ```js
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
* const alignment = textField.getAlignment()
|
||||
* if (alignment === TextAlignment.Left) console.log('Text is left justified')
|
||||
* if (alignment === TextAlignment.Center) console.log('Text is centered')
|
||||
* if (alignment === TextAlignment.Right) console.log('Text is right justified')
|
||||
* ```
|
||||
* @returns The alignment of this text field.
|
||||
*/
|
||||
getAlignment(): TextAlignment;
|
||||
/**
|
||||
* Set the alignment for this text field. This will determine the
|
||||
* justification of the text when it is displayed to the user in PDF readers.
|
||||
* There are three possible alignments: left, center, and right. For example:
|
||||
* ```js
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
*
|
||||
* // Text will be left justified when displayed
|
||||
* textField.setAlignment(TextAlignment.Left)
|
||||
*
|
||||
* // Text will be centered when displayed
|
||||
* textField.setAlignment(TextAlignment.Center)
|
||||
*
|
||||
* // Text will be right justified when displayed
|
||||
* textField.setAlignment(TextAlignment.Right)
|
||||
* ```
|
||||
* This method will mark this text field as dirty. See
|
||||
* [[PDFTextField.setText]] for more details about what this means.
|
||||
* @param alignment The alignment for this text field.
|
||||
*/
|
||||
setAlignment(alignment: TextAlignment): void;
|
||||
/**
|
||||
* Get the maximum length of this field. This value represents the maximum
|
||||
* number of characters that can be typed into this field by the user. If
|
||||
* this field does not have a maximum length, `undefined` is returned.
|
||||
* For example:
|
||||
* ```js
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
* const maxLength = textField.getMaxLength()
|
||||
* if (maxLength === undefined) console.log('No max length')
|
||||
* else console.log(`Max length is ${maxLength}`)
|
||||
* ```
|
||||
* @returns The maximum number of characters allowed in this field, or
|
||||
* `undefined` if no limit exists.
|
||||
*/
|
||||
getMaxLength(): number | undefined;
|
||||
/**
|
||||
* Set the maximum length of this field. This limits the number of characters
|
||||
* that can be typed into this field by the user. This also limits the length
|
||||
* of the string that can be passed to [[PDFTextField.setText]]. This limit
|
||||
* can be removed by passing `undefined` as `maxLength`. For example:
|
||||
* ```js
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
*
|
||||
* // Allow between 0 and 5 characters to be entered
|
||||
* textField.setMaxLength(5)
|
||||
*
|
||||
* // Allow any number of characters to be entered
|
||||
* textField.setMaxLength(undefined)
|
||||
* ```
|
||||
* This method will mark this text field as dirty. See
|
||||
* [[PDFTextField.setText]] for more details about what this means.
|
||||
* @param maxLength The maximum number of characters allowed in this field, or
|
||||
* `undefined` to remove the limit.
|
||||
*/
|
||||
setMaxLength(maxLength?: number): void;
|
||||
/**
|
||||
* Remove the maximum length for this text field. This allows any number of
|
||||
* characters to be typed into this field by the user. For example:
|
||||
* ```js
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
* textField.removeMaxLength()
|
||||
* ```
|
||||
* Calling this method is equivalent to passing `undefined` to
|
||||
* [[PDFTextField.setMaxLength]].
|
||||
*/
|
||||
removeMaxLength(): void;
|
||||
/**
|
||||
* Display an image inside the bounds of this text field's widgets. For example:
|
||||
* ```js
|
||||
* const pngImage = await pdfDoc.embedPng(...)
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
* textField.setImage(pngImage)
|
||||
* ```
|
||||
* This will update the appearances streams for each of this text field's widgets.
|
||||
* @param image The image that should be displayed.
|
||||
*/
|
||||
setImage(image: PDFImage): void;
|
||||
/**
|
||||
* Set the font size for this field. Larger font sizes will result in larger
|
||||
* text being displayed when PDF readers render this text field. Font sizes
|
||||
* may be integer or floating point numbers. Supplying a negative font size
|
||||
* will cause this method to throw an error.
|
||||
*
|
||||
* For example:
|
||||
* ```js
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
* textField.setFontSize(4)
|
||||
* textField.setFontSize(15.7)
|
||||
* ```
|
||||
*
|
||||
* > This method depends upon the existence of a default appearance
|
||||
* > (`/DA`) string. If this field does not have a default appearance string,
|
||||
* > or that string does not contain a font size (via the `Tf` operator),
|
||||
* > then this method will throw an error.
|
||||
*
|
||||
* @param fontSize The font size to be used when rendering text in this field.
|
||||
*/
|
||||
setFontSize(fontSize: number): void;
|
||||
/**
|
||||
* Returns `true` if each line of text is shown on a new line when this
|
||||
* field is displayed in a PDF reader. The alternative is that all lines of
|
||||
* text are merged onto a single line when displayed. See
|
||||
* [[PDFTextField.enableMultiline]] and [[PDFTextField.disableMultiline]].
|
||||
* For example:
|
||||
* ```js
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
* if (textField.isMultiline()) console.log('Multiline is enabled')
|
||||
* ```
|
||||
* @returns Whether or not this is a multiline text field.
|
||||
*/
|
||||
isMultiline(): boolean;
|
||||
/**
|
||||
* Display each line of text on a new line when this field is displayed in a
|
||||
* PDF reader. For example:
|
||||
* ```js
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
* textField.enableMultiline()
|
||||
* ```
|
||||
* This method will mark this text field as dirty. See
|
||||
* [[PDFTextField.setText]] for more details about what this means.
|
||||
*/
|
||||
enableMultiline(): void;
|
||||
/**
|
||||
* Display each line of text on the same line when this field is displayed
|
||||
* in a PDF reader. For example:
|
||||
* ```js
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
* textField.disableMultiline()
|
||||
* ```
|
||||
* This method will mark this text field as dirty. See
|
||||
* [[PDFTextField.setText]] for more details about what this means.
|
||||
*/
|
||||
disableMultiline(): void;
|
||||
/**
|
||||
* Returns `true` if this is a password text field. This means that the field
|
||||
* is intended for storing a secure password. See
|
||||
* [[PDFTextField.enablePassword]] and [[PDFTextField.disablePassword]].
|
||||
* For example:
|
||||
* ```js
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
* if (textField.isPassword()) console.log('Password is enabled')
|
||||
* ```
|
||||
* @returns Whether or not this is a password text field.
|
||||
*/
|
||||
isPassword(): boolean;
|
||||
/**
|
||||
* Indicate that this text field is intended for storing a secure password.
|
||||
* For example:
|
||||
* ```js
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
* textField.enablePassword()
|
||||
* ```
|
||||
* Values entered into password text fields should not be displayed on the
|
||||
* screen by PDF readers. Most PDF readers will display the value as
|
||||
* asterisks or bullets. PDF readers should never store values entered by the
|
||||
* user into password text fields. Similarly, applications should not
|
||||
* write data to a password text field.
|
||||
*
|
||||
* **Please note that this method does not cause entered values to be
|
||||
* encrypted or secured in any way! It simply sets a flag that PDF software
|
||||
* and readers can access to determine the _purpose_ of this field.**
|
||||
*/
|
||||
enablePassword(): void;
|
||||
/**
|
||||
* Indicate that this text field is **not** intended for storing a secure
|
||||
* password. For example:
|
||||
* ```js
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
* textField.disablePassword()
|
||||
* ```
|
||||
*/
|
||||
disablePassword(): void;
|
||||
/**
|
||||
* Returns `true` if the contents of this text field represent a file path.
|
||||
* See [[PDFTextField.enableFileSelection]] and
|
||||
* [[PDFTextField.disableFileSelection]]. For example:
|
||||
* ```js
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
* if (textField.isFileSelector()) console.log('Is a file selector')
|
||||
* ```
|
||||
* @returns Whether or not this field should contain file paths.
|
||||
*/
|
||||
isFileSelector(): boolean;
|
||||
/**
|
||||
* Indicate that this text field is intended to store a file path. The
|
||||
* contents of the file stored at that path should be submitted as the value
|
||||
* of the field. For example:
|
||||
* ```js
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
* textField.enableFileSelection()
|
||||
* ```
|
||||
*/
|
||||
enableFileSelection(): void;
|
||||
/**
|
||||
* Indicate that this text field is **not** intended to store a file path.
|
||||
* For example:
|
||||
* ```js
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
* textField.disableFileSelection()
|
||||
* ```
|
||||
*/
|
||||
disableFileSelection(): void;
|
||||
/**
|
||||
* Returns `true` if the text entered in this field should be spell checked
|
||||
* by PDF readers. See [[PDFTextField.enableSpellChecking]] and
|
||||
* [[PDFTextField.disableSpellChecking]]. For example:
|
||||
* ```js
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
* if (textField.isSpellChecked()) console.log('Spell checking is enabled')
|
||||
* ```
|
||||
* @returns Whether or not this field should be spell checked.
|
||||
*/
|
||||
isSpellChecked(): boolean;
|
||||
/**
|
||||
* Allow PDF readers to spell check the text entered in this field.
|
||||
* For example:
|
||||
* ```js
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
* textField.enableSpellChecking()
|
||||
* ```
|
||||
*/
|
||||
enableSpellChecking(): void;
|
||||
/**
|
||||
* Do not allow PDF readers to spell check the text entered in this field.
|
||||
* For example:
|
||||
* ```js
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
* textField.disableSpellChecking()
|
||||
* ```
|
||||
*/
|
||||
disableSpellChecking(): void;
|
||||
/**
|
||||
* Returns `true` if PDF readers should allow the user to scroll the text
|
||||
* field when its contents do not fit within the field's view bounds. See
|
||||
* [[PDFTextField.enableScrolling]] and [[PDFTextField.disableScrolling]].
|
||||
* For example:
|
||||
* ```js
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
* if (textField.isScrollable()) console.log('Scrolling is enabled')
|
||||
* ```
|
||||
* @returns Whether or not the field is scrollable in PDF readers.
|
||||
*/
|
||||
isScrollable(): boolean;
|
||||
/**
|
||||
* Allow PDF readers to present a scroll bar to the user when the contents
|
||||
* of this text field do not fit within its view bounds. For example:
|
||||
* ```js
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
* textField.enableScrolling()
|
||||
* ```
|
||||
* A horizontal scroll bar should be shown for singleline fields. A vertical
|
||||
* scroll bar should be shown for multiline fields.
|
||||
*/
|
||||
enableScrolling(): void;
|
||||
/**
|
||||
* Do not allow PDF readers to present a scroll bar to the user when the
|
||||
* contents of this text field do not fit within its view bounds. For example:
|
||||
* ```js
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
* textField.disableScrolling()
|
||||
* ```
|
||||
*/
|
||||
disableScrolling(): void;
|
||||
/**
|
||||
* Returns `true` if this is a combed text field. This means that the field
|
||||
* is split into `n` equal size cells with one character in each (where `n`
|
||||
* is equal to the max length of the text field). The result is that all
|
||||
* characters in this field are displayed an equal distance apart from one
|
||||
* another. See [[PDFTextField.enableCombing]] and
|
||||
* [[PDFTextField.disableCombing]]. For example:
|
||||
* ```js
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
* if (textField.isCombed()) console.log('Combing is enabled')
|
||||
* ```
|
||||
* Note that in order for a text field to be combed, the following must be
|
||||
* true (in addition to enabling combing):
|
||||
* * It must not be a multiline field (see [[PDFTextField.isMultiline]])
|
||||
* * It must not be a password field (see [[PDFTextField.isPassword]])
|
||||
* * It must not be a file selector field (see [[PDFTextField.isFileSelector]])
|
||||
* * It must have a max length defined (see [[PDFTextField.setMaxLength]])
|
||||
* @returns Whether or not this field is combed.
|
||||
*/
|
||||
isCombed(): boolean;
|
||||
/**
|
||||
* Split this field into `n` equal size cells with one character in each
|
||||
* (where `n` is equal to the max length of the text field). This will cause
|
||||
* all characters in the field to be displayed an equal distance apart from
|
||||
* one another. For example:
|
||||
* ```js
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
* textField.enableCombing()
|
||||
* ```
|
||||
*
|
||||
* In addition to calling this method, text fields must have a max length
|
||||
* defined in order to be combed (see [[PDFTextField.setMaxLength]]).
|
||||
*
|
||||
* This method will also call the following three methods internally:
|
||||
* * [[PDFTextField.disableMultiline]]
|
||||
* * [[PDFTextField.disablePassword]]
|
||||
* * [[PDFTextField.disableFileSelection]]
|
||||
*
|
||||
* This method will mark this text field as dirty. See
|
||||
* [[PDFTextField.setText]] for more details about what this means.
|
||||
*/
|
||||
enableCombing(): void;
|
||||
/**
|
||||
* Turn off combing for this text field. For example:
|
||||
* ```js
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
* textField.disableCombing()
|
||||
* ```
|
||||
* See [[PDFTextField.isCombed]] and [[PDFTextField.enableCombing]] for more
|
||||
* information about what combing is.
|
||||
*
|
||||
* This method will mark this text field as dirty. See
|
||||
* [[PDFTextField.setText]] for more details about what this means.
|
||||
*/
|
||||
disableCombing(): void;
|
||||
/**
|
||||
* Returns `true` if this text field contains rich text. See
|
||||
* [[PDFTextField.enableRichFormatting]] and
|
||||
* [[PDFTextField.disableRichFormatting]]. For example:
|
||||
* ```js
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
* if (textField.isRichFormatted()) console.log('Rich formatting enabled')
|
||||
* ```
|
||||
* @returns Whether or not this field contains rich text.
|
||||
*/
|
||||
isRichFormatted(): boolean;
|
||||
/**
|
||||
* Indicate that this field contains XFA data - or rich text. For example:
|
||||
* ```js
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
* textField.enableRichFormatting()
|
||||
* ```
|
||||
* Note that `pdf-lib` does not support reading or writing rich text fields.
|
||||
* Nor do most PDF readers and writers. Rich text fields are based on XFA
|
||||
* (XML Forms Architecture). Relatively few PDFs use rich text fields or XFA.
|
||||
* Unlike PDF itself, XFA is not an ISO standard. XFA has been deprecated in
|
||||
* PDF 2.0:
|
||||
* * https://en.wikipedia.org/wiki/XFA
|
||||
* * http://blog.pdfshareforms.com/pdf-2-0-release-bid-farewell-xfa-forms/
|
||||
*/
|
||||
enableRichFormatting(): void;
|
||||
/**
|
||||
* Indicate that this is a standard text field that does not XFA data (rich
|
||||
* text). For example:
|
||||
* ```js
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
* textField.disableRichFormatting()
|
||||
* ```
|
||||
*/
|
||||
disableRichFormatting(): void;
|
||||
/**
|
||||
* Show this text field on the specified page. For example:
|
||||
* ```js
|
||||
* const ubuntuFont = await pdfDoc.embedFont(ubuntuFontBytes)
|
||||
* const page = pdfDoc.addPage()
|
||||
*
|
||||
* const form = pdfDoc.getForm()
|
||||
* const textField = form.createTextField('best.gundam')
|
||||
* textField.setText('Exia')
|
||||
*
|
||||
* textField.addToPage(page, {
|
||||
* x: 50,
|
||||
* y: 75,
|
||||
* width: 200,
|
||||
* height: 100,
|
||||
* textColor: rgb(1, 0, 0),
|
||||
* backgroundColor: rgb(0, 1, 0),
|
||||
* borderColor: rgb(0, 0, 1),
|
||||
* borderWidth: 2,
|
||||
* rotate: degrees(90),
|
||||
* font: ubuntuFont,
|
||||
* })
|
||||
* ```
|
||||
* This will create a new widget for this text field.
|
||||
* @param page The page to which this text field widget should be added.
|
||||
* @param options The options to be used when adding this text field widget.
|
||||
*/
|
||||
addToPage(page: PDFPage, options?: FieldAppearanceOptions): void;
|
||||
/**
|
||||
* Returns `true` if this text field has been marked as dirty, or if any of
|
||||
* this text field's widgets do not have an appearance stream. For example:
|
||||
* ```js
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
* if (textField.needsAppearancesUpdate()) console.log('Needs update')
|
||||
* ```
|
||||
* @returns Whether or not this text field needs an appearance update.
|
||||
*/
|
||||
needsAppearancesUpdate(): boolean;
|
||||
/**
|
||||
* Update the appearance streams for each of this text field's widgets using
|
||||
* the default appearance provider for text fields. For example:
|
||||
* ```js
|
||||
* const helvetica = await pdfDoc.embedFont(StandardFonts.Helvetica)
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
* textField.defaultUpdateAppearances(helvetica)
|
||||
* ```
|
||||
* @param font The font to be used for creating the appearance streams.
|
||||
*/
|
||||
defaultUpdateAppearances(font: PDFFont): void;
|
||||
/**
|
||||
* Update the appearance streams for each of this text field's widgets using
|
||||
* the given appearance provider. If no `provider` is passed, the default
|
||||
* appearance provider for text fields will be used. For example:
|
||||
* ```js
|
||||
* const helvetica = await pdfDoc.embedFont(StandardFonts.Helvetica)
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
* textField.updateAppearances(helvetica, (field, widget, font) => {
|
||||
* ...
|
||||
* return drawTextField(...)
|
||||
* })
|
||||
* ```
|
||||
* @param font The font to be used for creating the appearance streams.
|
||||
* @param provider Optionally, the appearance provider to be used for
|
||||
* generating the contents of the appearance streams.
|
||||
*/
|
||||
updateAppearances(font: PDFFont, provider?: AppearanceProviderFor<PDFTextField>): void;
|
||||
private updateWidgetAppearance;
|
||||
}
|
||||
//# sourceMappingURL=PDFTextField.d.ts.map
|
||||
1
node_modules/pdf-lib/es/api/form/PDFTextField.d.ts.map
generated
vendored
Normal file
1
node_modules/pdf-lib/es/api/form/PDFTextField.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"PDFTextField.d.ts","sourceRoot":"","sources":["../../../src/api/form/PDFTextField.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,uBAA4B;AAC9C,OAAO,OAAO,mBAAwB;AACtC,OAAO,OAAO,mBAAwB;AACtC,OAAO,QAAQ,oBAAyB;AACxC,OAAO,QAAQ,EAAE,EACf,sBAAsB,EAEvB,mBAA8B;AAC/B,OAAO,EACL,qBAAqB,EAGtB,sBAAiC;AASlC,OAAO,EAAE,aAAa,EAAE,0BAA+B;AAEvD,OAAO,EAEL,MAAM,EAEN,WAAW,EAGZ,mBAAiB;AASlB;;;;;;;;GAQG;AACH,MAAM,CAAC,OAAO,OAAO,YAAa,SAAQ,QAAQ;IAChD;;;;;;;;;;OAUG;IACH,MAAM,CAAC,EAAE,aAAc,WAAW,OAAO,MAAM,OAAO,WAAW,kBAC1B;IAEvC,4DAA4D;IAC5D,QAAQ,CAAC,SAAS,EAAE,WAAW,CAAC;IAEhC,OAAO;IAQP;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACH,OAAO,IAAI,MAAM,GAAG,SAAS;IAQ7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAqCG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS;IAkBhC;;;;;;;;;;;;OAYG;IACH,YAAY,IAAI,aAAa;IAY7B;;;;;;;;;;;;;;;;;;;OAmBG;IACH,YAAY,CAAC,SAAS,EAAE,aAAa;IAMrC;;;;;;;;;;;;;OAaG;IACH,YAAY,IAAI,MAAM,GAAG,SAAS;IAIlC;;;;;;;;;;;;;;;;;;OAkBG;IACH,YAAY,CAAC,SAAS,CAAC,EAAE,MAAM;IAgB/B;;;;;;;;;OASG;IACH,eAAe;IAKf;;;;;;;;;OASG;IACH,QAAQ,CAAC,KAAK,EAAE,QAAQ;IAuBxB;;;;;;;;;;;;;;;;;;;OAmBG;IACH,WAAW,CAAC,QAAQ,EAAE,MAAM;IAM5B;;;;;;;;;;;OAWG;IACH,WAAW,IAAI,OAAO;IAItB;;;;;;;;;OASG;IACH,eAAe;IAKf;;;;;;;;;OASG;IACH,gBAAgB;IAKhB;;;;;;;;;;OAUG;IACH,UAAU,IAAI,OAAO;IAIrB;;;;;;;;;;;;;;;;OAgBG;IACH,cAAc;IAId;;;;;;;OAOG;IACH,eAAe;IAIf;;;;;;;;;OASG;IACH,cAAc,IAAI,OAAO;IAIzB;;;;;;;;OAQG;IACH,mBAAmB;IAInB;;;;;;;OAOG;IACH,oBAAoB;IAIpB;;;;;;;;;OASG;IACH,cAAc,IAAI,OAAO;IAIzB;;;;;;;OAOG;IACH,mBAAmB;IAInB;;;;;;;OAOG;IACH,oBAAoB;IAIpB;;;;;;;;;;OAUG;IACH,YAAY,IAAI,OAAO;IAIvB;;;;;;;;;OASG;IACH,eAAe;IAIf;;;;;;;OAOG;IACH,gBAAgB;IAIhB;;;;;;;;;;;;;;;;;;OAkBG;IACH,QAAQ,IAAI,OAAO;IAUnB;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,aAAa;IAeb;;;;;;;;;;;OAWG;IACH,cAAc;IAKd;;;;;;;;;OASG;IACH,eAAe,IAAI,OAAO;IAI1B;;;;;;;;;;;;;OAaG;IACH,oBAAoB;IAIpB;;;;;;;OAOG;IACH,qBAAqB;IAIrB;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACH,SAAS,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,sBAAsB;IAsCzD;;;;;;;;OAQG;IACH,sBAAsB,IAAI,OAAO;IAcjC;;;;;;;;;OASG;IACH,wBAAwB,CAAC,IAAI,EAAE,OAAO;IAKtC;;;;;;;;;;;;;;;OAeG;IACH,iBAAiB,CACf,IAAI,EAAE,OAAO,EACb,QAAQ,CAAC,EAAE,qBAAqB,CAAC,YAAY,CAAC;IAahD,OAAO,CAAC,sBAAsB;CAS/B"}
|
||||
737
node_modules/pdf-lib/es/api/form/PDFTextField.js
generated
vendored
Normal file
737
node_modules/pdf-lib/es/api/form/PDFTextField.js
generated
vendored
Normal file
@@ -0,0 +1,737 @@
|
||||
import { __extends } from "tslib";
|
||||
import PDFPage from "../PDFPage";
|
||||
import PDFFont from "../PDFFont";
|
||||
import PDFField, { assertFieldAppearanceOptions, } from "./PDFField";
|
||||
import { normalizeAppearance, defaultTextFieldAppearanceProvider, } from "./appearances";
|
||||
import { rgb } from "../colors";
|
||||
import { degrees } from "../rotations";
|
||||
import { RichTextFieldReadError, ExceededMaxLengthError, InvalidMaxLengthError, } from "../errors";
|
||||
import { ImageAlignment } from "../image/alignment";
|
||||
import { TextAlignment } from "../text/alignment";
|
||||
import { PDFHexString, PDFStream, PDFAcroText, AcroTextFlags, } from "../../core";
|
||||
import { assertIs, assertIsOneOf, assertOrUndefined, assertPositive, assertRangeOrUndefined, } from "../../utils";
|
||||
/**
|
||||
* Represents a text field of a [[PDFForm]].
|
||||
*
|
||||
* [[PDFTextField]] fields are boxes that display text entered by the user. The
|
||||
* purpose of a text field is to enable users to enter text or view text values
|
||||
* in the document prefilled by software. Users can click on a text field and
|
||||
* input text via their keyboard. Some text fields allow multiple lines of text
|
||||
* to be entered (see [[PDFTextField.isMultiline]]).
|
||||
*/
|
||||
var PDFTextField = /** @class */ (function (_super) {
|
||||
__extends(PDFTextField, _super);
|
||||
function PDFTextField(acroText, ref, doc) {
|
||||
var _this = _super.call(this, acroText, ref, doc) || this;
|
||||
assertIs(acroText, 'acroText', [[PDFAcroText, 'PDFAcroText']]);
|
||||
_this.acroField = acroText;
|
||||
return _this;
|
||||
}
|
||||
/**
|
||||
* Get the text that this field contains. This text is visible to users who
|
||||
* view this field in a PDF reader.
|
||||
*
|
||||
* For example:
|
||||
* ```js
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
* const text = textField.getText()
|
||||
* console.log('Text field contents:', text)
|
||||
* ```
|
||||
*
|
||||
* Note that if this text field contains no underlying value, `undefined`
|
||||
* will be returned. Text fields may also contain an underlying value that
|
||||
* is simply an empty string (`''`). This detail is largely irrelevant for
|
||||
* most applications. In general, you'll want to treat both cases the same
|
||||
* way and simply consider the text field to be empty. In either case, the
|
||||
* text field will appear empty to users when viewed in a PDF reader.
|
||||
*
|
||||
* An error will be thrown if this is a rich text field. `pdf-lib` does not
|
||||
* support reading rich text fields. Nor do most PDF readers and writers.
|
||||
* Rich text fields are based on XFA (XML Forms Architecture). Relatively few
|
||||
* PDFs use rich text fields or XFA. Unlike PDF itself, XFA is not an ISO
|
||||
* standard. XFA has been deprecated in PDF 2.0:
|
||||
* * https://en.wikipedia.org/wiki/XFA
|
||||
* * http://blog.pdfshareforms.com/pdf-2-0-release-bid-farewell-xfa-forms/
|
||||
*
|
||||
* @returns The text contained in this text field.
|
||||
*/
|
||||
PDFTextField.prototype.getText = function () {
|
||||
var value = this.acroField.getValue();
|
||||
if (!value && this.isRichFormatted()) {
|
||||
throw new RichTextFieldReadError(this.getName());
|
||||
}
|
||||
return value === null || value === void 0 ? void 0 : value.decodeText();
|
||||
};
|
||||
/**
|
||||
* Set the text for this field. This operation is analogous to a human user
|
||||
* clicking on the text field in a PDF reader and typing in text via their
|
||||
* keyboard. This method will update the underlying state of the text field
|
||||
* to indicate what text has been set. PDF libraries and readers will be able
|
||||
* to extract these values from the saved document and determine what text
|
||||
* was set.
|
||||
*
|
||||
* For example:
|
||||
* ```js
|
||||
* const textField = form.getTextField('best.superhero.text.field')
|
||||
* textField.setText('One Punch Man')
|
||||
* ```
|
||||
*
|
||||
* This method will mark this text field as dirty, causing its appearance
|
||||
* streams to be updated when either [[PDFDocument.save]] or
|
||||
* [[PDFForm.updateFieldAppearances]] is called. The updated streams will
|
||||
* display the text this field contains inside the widgets of this text
|
||||
* field.
|
||||
*
|
||||
* **IMPORTANT:** The default font used to update appearance streams is
|
||||
* [[StandardFonts.Helvetica]]. Note that this is a WinAnsi font. This means
|
||||
* that encoding errors will be thrown if this field contains text outside
|
||||
* the WinAnsi character set (the latin alphabet).
|
||||
*
|
||||
* Embedding a custom font and passing it to
|
||||
* [[PDFForm.updateFieldAppearances]] or [[PDFTextField.updateAppearances]]
|
||||
* allows you to generate appearance streams with characters outside the
|
||||
* latin alphabet (assuming the custom font supports them).
|
||||
*
|
||||
* If this is a rich text field, it will be converted to a standard text
|
||||
* field in order to set the text. `pdf-lib` does not support writing rich
|
||||
* text strings. Nor do most PDF readers and writers. See
|
||||
* [[PDFTextField.getText]] for more information about rich text fields and
|
||||
* their deprecation in PDF 2.0.
|
||||
*
|
||||
* @param text The text this field should contain.
|
||||
*/
|
||||
PDFTextField.prototype.setText = function (text) {
|
||||
assertOrUndefined(text, 'text', ['string']);
|
||||
var maxLength = this.getMaxLength();
|
||||
if (maxLength !== undefined && text && text.length > maxLength) {
|
||||
throw new ExceededMaxLengthError(text.length, maxLength, this.getName());
|
||||
}
|
||||
this.markAsDirty();
|
||||
this.disableRichFormatting();
|
||||
if (text) {
|
||||
this.acroField.setValue(PDFHexString.fromText(text));
|
||||
}
|
||||
else {
|
||||
this.acroField.removeValue();
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Get the alignment for this text field. This value represents the
|
||||
* justification of the text when it is displayed to the user in PDF readers.
|
||||
* There are three possible alignments: left, center, and right. For example:
|
||||
* ```js
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
* const alignment = textField.getAlignment()
|
||||
* if (alignment === TextAlignment.Left) console.log('Text is left justified')
|
||||
* if (alignment === TextAlignment.Center) console.log('Text is centered')
|
||||
* if (alignment === TextAlignment.Right) console.log('Text is right justified')
|
||||
* ```
|
||||
* @returns The alignment of this text field.
|
||||
*/
|
||||
PDFTextField.prototype.getAlignment = function () {
|
||||
var quadding = this.acroField.getQuadding();
|
||||
// prettier-ignore
|
||||
return (quadding === 0 ? TextAlignment.Left
|
||||
: quadding === 1 ? TextAlignment.Center
|
||||
: quadding === 2 ? TextAlignment.Right
|
||||
: TextAlignment.Left);
|
||||
};
|
||||
/**
|
||||
* Set the alignment for this text field. This will determine the
|
||||
* justification of the text when it is displayed to the user in PDF readers.
|
||||
* There are three possible alignments: left, center, and right. For example:
|
||||
* ```js
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
*
|
||||
* // Text will be left justified when displayed
|
||||
* textField.setAlignment(TextAlignment.Left)
|
||||
*
|
||||
* // Text will be centered when displayed
|
||||
* textField.setAlignment(TextAlignment.Center)
|
||||
*
|
||||
* // Text will be right justified when displayed
|
||||
* textField.setAlignment(TextAlignment.Right)
|
||||
* ```
|
||||
* This method will mark this text field as dirty. See
|
||||
* [[PDFTextField.setText]] for more details about what this means.
|
||||
* @param alignment The alignment for this text field.
|
||||
*/
|
||||
PDFTextField.prototype.setAlignment = function (alignment) {
|
||||
assertIsOneOf(alignment, 'alignment', TextAlignment);
|
||||
this.markAsDirty();
|
||||
this.acroField.setQuadding(alignment);
|
||||
};
|
||||
/**
|
||||
* Get the maximum length of this field. This value represents the maximum
|
||||
* number of characters that can be typed into this field by the user. If
|
||||
* this field does not have a maximum length, `undefined` is returned.
|
||||
* For example:
|
||||
* ```js
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
* const maxLength = textField.getMaxLength()
|
||||
* if (maxLength === undefined) console.log('No max length')
|
||||
* else console.log(`Max length is ${maxLength}`)
|
||||
* ```
|
||||
* @returns The maximum number of characters allowed in this field, or
|
||||
* `undefined` if no limit exists.
|
||||
*/
|
||||
PDFTextField.prototype.getMaxLength = function () {
|
||||
return this.acroField.getMaxLength();
|
||||
};
|
||||
/**
|
||||
* Set the maximum length of this field. This limits the number of characters
|
||||
* that can be typed into this field by the user. This also limits the length
|
||||
* of the string that can be passed to [[PDFTextField.setText]]. This limit
|
||||
* can be removed by passing `undefined` as `maxLength`. For example:
|
||||
* ```js
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
*
|
||||
* // Allow between 0 and 5 characters to be entered
|
||||
* textField.setMaxLength(5)
|
||||
*
|
||||
* // Allow any number of characters to be entered
|
||||
* textField.setMaxLength(undefined)
|
||||
* ```
|
||||
* This method will mark this text field as dirty. See
|
||||
* [[PDFTextField.setText]] for more details about what this means.
|
||||
* @param maxLength The maximum number of characters allowed in this field, or
|
||||
* `undefined` to remove the limit.
|
||||
*/
|
||||
PDFTextField.prototype.setMaxLength = function (maxLength) {
|
||||
assertRangeOrUndefined(maxLength, 'maxLength', 0, Number.MAX_SAFE_INTEGER);
|
||||
this.markAsDirty();
|
||||
if (maxLength === undefined) {
|
||||
this.acroField.removeMaxLength();
|
||||
}
|
||||
else {
|
||||
var text = this.getText();
|
||||
if (text && text.length > maxLength) {
|
||||
throw new InvalidMaxLengthError(text.length, maxLength, this.getName());
|
||||
}
|
||||
this.acroField.setMaxLength(maxLength);
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Remove the maximum length for this text field. This allows any number of
|
||||
* characters to be typed into this field by the user. For example:
|
||||
* ```js
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
* textField.removeMaxLength()
|
||||
* ```
|
||||
* Calling this method is equivalent to passing `undefined` to
|
||||
* [[PDFTextField.setMaxLength]].
|
||||
*/
|
||||
PDFTextField.prototype.removeMaxLength = function () {
|
||||
this.markAsDirty();
|
||||
this.acroField.removeMaxLength();
|
||||
};
|
||||
/**
|
||||
* Display an image inside the bounds of this text field's widgets. For example:
|
||||
* ```js
|
||||
* const pngImage = await pdfDoc.embedPng(...)
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
* textField.setImage(pngImage)
|
||||
* ```
|
||||
* This will update the appearances streams for each of this text field's widgets.
|
||||
* @param image The image that should be displayed.
|
||||
*/
|
||||
PDFTextField.prototype.setImage = function (image) {
|
||||
var fieldAlignment = this.getAlignment();
|
||||
// prettier-ignore
|
||||
var alignment = fieldAlignment === TextAlignment.Center ? ImageAlignment.Center
|
||||
: fieldAlignment === TextAlignment.Right ? ImageAlignment.Right
|
||||
: ImageAlignment.Left;
|
||||
var widgets = this.acroField.getWidgets();
|
||||
for (var idx = 0, len = widgets.length; idx < len; idx++) {
|
||||
var widget = widgets[idx];
|
||||
var streamRef = this.createImageAppearanceStream(widget, image, alignment);
|
||||
this.updateWidgetAppearances(widget, { normal: streamRef });
|
||||
}
|
||||
this.markAsClean();
|
||||
};
|
||||
/**
|
||||
* Set the font size for this field. Larger font sizes will result in larger
|
||||
* text being displayed when PDF readers render this text field. Font sizes
|
||||
* may be integer or floating point numbers. Supplying a negative font size
|
||||
* will cause this method to throw an error.
|
||||
*
|
||||
* For example:
|
||||
* ```js
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
* textField.setFontSize(4)
|
||||
* textField.setFontSize(15.7)
|
||||
* ```
|
||||
*
|
||||
* > This method depends upon the existence of a default appearance
|
||||
* > (`/DA`) string. If this field does not have a default appearance string,
|
||||
* > or that string does not contain a font size (via the `Tf` operator),
|
||||
* > then this method will throw an error.
|
||||
*
|
||||
* @param fontSize The font size to be used when rendering text in this field.
|
||||
*/
|
||||
PDFTextField.prototype.setFontSize = function (fontSize) {
|
||||
assertPositive(fontSize, 'fontSize');
|
||||
this.acroField.setFontSize(fontSize);
|
||||
this.markAsDirty();
|
||||
};
|
||||
/**
|
||||
* Returns `true` if each line of text is shown on a new line when this
|
||||
* field is displayed in a PDF reader. The alternative is that all lines of
|
||||
* text are merged onto a single line when displayed. See
|
||||
* [[PDFTextField.enableMultiline]] and [[PDFTextField.disableMultiline]].
|
||||
* For example:
|
||||
* ```js
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
* if (textField.isMultiline()) console.log('Multiline is enabled')
|
||||
* ```
|
||||
* @returns Whether or not this is a multiline text field.
|
||||
*/
|
||||
PDFTextField.prototype.isMultiline = function () {
|
||||
return this.acroField.hasFlag(AcroTextFlags.Multiline);
|
||||
};
|
||||
/**
|
||||
* Display each line of text on a new line when this field is displayed in a
|
||||
* PDF reader. For example:
|
||||
* ```js
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
* textField.enableMultiline()
|
||||
* ```
|
||||
* This method will mark this text field as dirty. See
|
||||
* [[PDFTextField.setText]] for more details about what this means.
|
||||
*/
|
||||
PDFTextField.prototype.enableMultiline = function () {
|
||||
this.markAsDirty();
|
||||
this.acroField.setFlagTo(AcroTextFlags.Multiline, true);
|
||||
};
|
||||
/**
|
||||
* Display each line of text on the same line when this field is displayed
|
||||
* in a PDF reader. For example:
|
||||
* ```js
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
* textField.disableMultiline()
|
||||
* ```
|
||||
* This method will mark this text field as dirty. See
|
||||
* [[PDFTextField.setText]] for more details about what this means.
|
||||
*/
|
||||
PDFTextField.prototype.disableMultiline = function () {
|
||||
this.markAsDirty();
|
||||
this.acroField.setFlagTo(AcroTextFlags.Multiline, false);
|
||||
};
|
||||
/**
|
||||
* Returns `true` if this is a password text field. This means that the field
|
||||
* is intended for storing a secure password. See
|
||||
* [[PDFTextField.enablePassword]] and [[PDFTextField.disablePassword]].
|
||||
* For example:
|
||||
* ```js
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
* if (textField.isPassword()) console.log('Password is enabled')
|
||||
* ```
|
||||
* @returns Whether or not this is a password text field.
|
||||
*/
|
||||
PDFTextField.prototype.isPassword = function () {
|
||||
return this.acroField.hasFlag(AcroTextFlags.Password);
|
||||
};
|
||||
/**
|
||||
* Indicate that this text field is intended for storing a secure password.
|
||||
* For example:
|
||||
* ```js
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
* textField.enablePassword()
|
||||
* ```
|
||||
* Values entered into password text fields should not be displayed on the
|
||||
* screen by PDF readers. Most PDF readers will display the value as
|
||||
* asterisks or bullets. PDF readers should never store values entered by the
|
||||
* user into password text fields. Similarly, applications should not
|
||||
* write data to a password text field.
|
||||
*
|
||||
* **Please note that this method does not cause entered values to be
|
||||
* encrypted or secured in any way! It simply sets a flag that PDF software
|
||||
* and readers can access to determine the _purpose_ of this field.**
|
||||
*/
|
||||
PDFTextField.prototype.enablePassword = function () {
|
||||
this.acroField.setFlagTo(AcroTextFlags.Password, true);
|
||||
};
|
||||
/**
|
||||
* Indicate that this text field is **not** intended for storing a secure
|
||||
* password. For example:
|
||||
* ```js
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
* textField.disablePassword()
|
||||
* ```
|
||||
*/
|
||||
PDFTextField.prototype.disablePassword = function () {
|
||||
this.acroField.setFlagTo(AcroTextFlags.Password, false);
|
||||
};
|
||||
/**
|
||||
* Returns `true` if the contents of this text field represent a file path.
|
||||
* See [[PDFTextField.enableFileSelection]] and
|
||||
* [[PDFTextField.disableFileSelection]]. For example:
|
||||
* ```js
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
* if (textField.isFileSelector()) console.log('Is a file selector')
|
||||
* ```
|
||||
* @returns Whether or not this field should contain file paths.
|
||||
*/
|
||||
PDFTextField.prototype.isFileSelector = function () {
|
||||
return this.acroField.hasFlag(AcroTextFlags.FileSelect);
|
||||
};
|
||||
/**
|
||||
* Indicate that this text field is intended to store a file path. The
|
||||
* contents of the file stored at that path should be submitted as the value
|
||||
* of the field. For example:
|
||||
* ```js
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
* textField.enableFileSelection()
|
||||
* ```
|
||||
*/
|
||||
PDFTextField.prototype.enableFileSelection = function () {
|
||||
this.acroField.setFlagTo(AcroTextFlags.FileSelect, true);
|
||||
};
|
||||
/**
|
||||
* Indicate that this text field is **not** intended to store a file path.
|
||||
* For example:
|
||||
* ```js
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
* textField.disableFileSelection()
|
||||
* ```
|
||||
*/
|
||||
PDFTextField.prototype.disableFileSelection = function () {
|
||||
this.acroField.setFlagTo(AcroTextFlags.FileSelect, false);
|
||||
};
|
||||
/**
|
||||
* Returns `true` if the text entered in this field should be spell checked
|
||||
* by PDF readers. See [[PDFTextField.enableSpellChecking]] and
|
||||
* [[PDFTextField.disableSpellChecking]]. For example:
|
||||
* ```js
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
* if (textField.isSpellChecked()) console.log('Spell checking is enabled')
|
||||
* ```
|
||||
* @returns Whether or not this field should be spell checked.
|
||||
*/
|
||||
PDFTextField.prototype.isSpellChecked = function () {
|
||||
return !this.acroField.hasFlag(AcroTextFlags.DoNotSpellCheck);
|
||||
};
|
||||
/**
|
||||
* Allow PDF readers to spell check the text entered in this field.
|
||||
* For example:
|
||||
* ```js
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
* textField.enableSpellChecking()
|
||||
* ```
|
||||
*/
|
||||
PDFTextField.prototype.enableSpellChecking = function () {
|
||||
this.acroField.setFlagTo(AcroTextFlags.DoNotSpellCheck, false);
|
||||
};
|
||||
/**
|
||||
* Do not allow PDF readers to spell check the text entered in this field.
|
||||
* For example:
|
||||
* ```js
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
* textField.disableSpellChecking()
|
||||
* ```
|
||||
*/
|
||||
PDFTextField.prototype.disableSpellChecking = function () {
|
||||
this.acroField.setFlagTo(AcroTextFlags.DoNotSpellCheck, true);
|
||||
};
|
||||
/**
|
||||
* Returns `true` if PDF readers should allow the user to scroll the text
|
||||
* field when its contents do not fit within the field's view bounds. See
|
||||
* [[PDFTextField.enableScrolling]] and [[PDFTextField.disableScrolling]].
|
||||
* For example:
|
||||
* ```js
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
* if (textField.isScrollable()) console.log('Scrolling is enabled')
|
||||
* ```
|
||||
* @returns Whether or not the field is scrollable in PDF readers.
|
||||
*/
|
||||
PDFTextField.prototype.isScrollable = function () {
|
||||
return !this.acroField.hasFlag(AcroTextFlags.DoNotScroll);
|
||||
};
|
||||
/**
|
||||
* Allow PDF readers to present a scroll bar to the user when the contents
|
||||
* of this text field do not fit within its view bounds. For example:
|
||||
* ```js
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
* textField.enableScrolling()
|
||||
* ```
|
||||
* A horizontal scroll bar should be shown for singleline fields. A vertical
|
||||
* scroll bar should be shown for multiline fields.
|
||||
*/
|
||||
PDFTextField.prototype.enableScrolling = function () {
|
||||
this.acroField.setFlagTo(AcroTextFlags.DoNotScroll, false);
|
||||
};
|
||||
/**
|
||||
* Do not allow PDF readers to present a scroll bar to the user when the
|
||||
* contents of this text field do not fit within its view bounds. For example:
|
||||
* ```js
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
* textField.disableScrolling()
|
||||
* ```
|
||||
*/
|
||||
PDFTextField.prototype.disableScrolling = function () {
|
||||
this.acroField.setFlagTo(AcroTextFlags.DoNotScroll, true);
|
||||
};
|
||||
/**
|
||||
* Returns `true` if this is a combed text field. This means that the field
|
||||
* is split into `n` equal size cells with one character in each (where `n`
|
||||
* is equal to the max length of the text field). The result is that all
|
||||
* characters in this field are displayed an equal distance apart from one
|
||||
* another. See [[PDFTextField.enableCombing]] and
|
||||
* [[PDFTextField.disableCombing]]. For example:
|
||||
* ```js
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
* if (textField.isCombed()) console.log('Combing is enabled')
|
||||
* ```
|
||||
* Note that in order for a text field to be combed, the following must be
|
||||
* true (in addition to enabling combing):
|
||||
* * It must not be a multiline field (see [[PDFTextField.isMultiline]])
|
||||
* * It must not be a password field (see [[PDFTextField.isPassword]])
|
||||
* * It must not be a file selector field (see [[PDFTextField.isFileSelector]])
|
||||
* * It must have a max length defined (see [[PDFTextField.setMaxLength]])
|
||||
* @returns Whether or not this field is combed.
|
||||
*/
|
||||
PDFTextField.prototype.isCombed = function () {
|
||||
return (this.acroField.hasFlag(AcroTextFlags.Comb) &&
|
||||
!this.isMultiline() &&
|
||||
!this.isPassword() &&
|
||||
!this.isFileSelector() &&
|
||||
this.getMaxLength() !== undefined);
|
||||
};
|
||||
/**
|
||||
* Split this field into `n` equal size cells with one character in each
|
||||
* (where `n` is equal to the max length of the text field). This will cause
|
||||
* all characters in the field to be displayed an equal distance apart from
|
||||
* one another. For example:
|
||||
* ```js
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
* textField.enableCombing()
|
||||
* ```
|
||||
*
|
||||
* In addition to calling this method, text fields must have a max length
|
||||
* defined in order to be combed (see [[PDFTextField.setMaxLength]]).
|
||||
*
|
||||
* This method will also call the following three methods internally:
|
||||
* * [[PDFTextField.disableMultiline]]
|
||||
* * [[PDFTextField.disablePassword]]
|
||||
* * [[PDFTextField.disableFileSelection]]
|
||||
*
|
||||
* This method will mark this text field as dirty. See
|
||||
* [[PDFTextField.setText]] for more details about what this means.
|
||||
*/
|
||||
PDFTextField.prototype.enableCombing = function () {
|
||||
if (this.getMaxLength() === undefined) {
|
||||
var msg = "PDFTextFields must have a max length in order to be combed";
|
||||
console.warn(msg);
|
||||
}
|
||||
this.markAsDirty();
|
||||
this.disableMultiline();
|
||||
this.disablePassword();
|
||||
this.disableFileSelection();
|
||||
this.acroField.setFlagTo(AcroTextFlags.Comb, true);
|
||||
};
|
||||
/**
|
||||
* Turn off combing for this text field. For example:
|
||||
* ```js
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
* textField.disableCombing()
|
||||
* ```
|
||||
* See [[PDFTextField.isCombed]] and [[PDFTextField.enableCombing]] for more
|
||||
* information about what combing is.
|
||||
*
|
||||
* This method will mark this text field as dirty. See
|
||||
* [[PDFTextField.setText]] for more details about what this means.
|
||||
*/
|
||||
PDFTextField.prototype.disableCombing = function () {
|
||||
this.markAsDirty();
|
||||
this.acroField.setFlagTo(AcroTextFlags.Comb, false);
|
||||
};
|
||||
/**
|
||||
* Returns `true` if this text field contains rich text. See
|
||||
* [[PDFTextField.enableRichFormatting]] and
|
||||
* [[PDFTextField.disableRichFormatting]]. For example:
|
||||
* ```js
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
* if (textField.isRichFormatted()) console.log('Rich formatting enabled')
|
||||
* ```
|
||||
* @returns Whether or not this field contains rich text.
|
||||
*/
|
||||
PDFTextField.prototype.isRichFormatted = function () {
|
||||
return this.acroField.hasFlag(AcroTextFlags.RichText);
|
||||
};
|
||||
/**
|
||||
* Indicate that this field contains XFA data - or rich text. For example:
|
||||
* ```js
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
* textField.enableRichFormatting()
|
||||
* ```
|
||||
* Note that `pdf-lib` does not support reading or writing rich text fields.
|
||||
* Nor do most PDF readers and writers. Rich text fields are based on XFA
|
||||
* (XML Forms Architecture). Relatively few PDFs use rich text fields or XFA.
|
||||
* Unlike PDF itself, XFA is not an ISO standard. XFA has been deprecated in
|
||||
* PDF 2.0:
|
||||
* * https://en.wikipedia.org/wiki/XFA
|
||||
* * http://blog.pdfshareforms.com/pdf-2-0-release-bid-farewell-xfa-forms/
|
||||
*/
|
||||
PDFTextField.prototype.enableRichFormatting = function () {
|
||||
this.acroField.setFlagTo(AcroTextFlags.RichText, true);
|
||||
};
|
||||
/**
|
||||
* Indicate that this is a standard text field that does not XFA data (rich
|
||||
* text). For example:
|
||||
* ```js
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
* textField.disableRichFormatting()
|
||||
* ```
|
||||
*/
|
||||
PDFTextField.prototype.disableRichFormatting = function () {
|
||||
this.acroField.setFlagTo(AcroTextFlags.RichText, false);
|
||||
};
|
||||
/**
|
||||
* Show this text field on the specified page. For example:
|
||||
* ```js
|
||||
* const ubuntuFont = await pdfDoc.embedFont(ubuntuFontBytes)
|
||||
* const page = pdfDoc.addPage()
|
||||
*
|
||||
* const form = pdfDoc.getForm()
|
||||
* const textField = form.createTextField('best.gundam')
|
||||
* textField.setText('Exia')
|
||||
*
|
||||
* textField.addToPage(page, {
|
||||
* x: 50,
|
||||
* y: 75,
|
||||
* width: 200,
|
||||
* height: 100,
|
||||
* textColor: rgb(1, 0, 0),
|
||||
* backgroundColor: rgb(0, 1, 0),
|
||||
* borderColor: rgb(0, 0, 1),
|
||||
* borderWidth: 2,
|
||||
* rotate: degrees(90),
|
||||
* font: ubuntuFont,
|
||||
* })
|
||||
* ```
|
||||
* This will create a new widget for this text field.
|
||||
* @param page The page to which this text field widget should be added.
|
||||
* @param options The options to be used when adding this text field widget.
|
||||
*/
|
||||
PDFTextField.prototype.addToPage = function (page, options) {
|
||||
var _a, _b, _c, _d, _e, _f, _g;
|
||||
assertIs(page, 'page', [[PDFPage, 'PDFPage']]);
|
||||
assertFieldAppearanceOptions(options);
|
||||
if (!options)
|
||||
options = {};
|
||||
if (!('textColor' in options))
|
||||
options.textColor = rgb(0, 0, 0);
|
||||
if (!('backgroundColor' in options))
|
||||
options.backgroundColor = rgb(1, 1, 1);
|
||||
if (!('borderColor' in options))
|
||||
options.borderColor = rgb(0, 0, 0);
|
||||
if (!('borderWidth' in options))
|
||||
options.borderWidth = 1;
|
||||
// Create a widget for this text field
|
||||
var widget = this.createWidget({
|
||||
x: (_a = options.x) !== null && _a !== void 0 ? _a : 0,
|
||||
y: (_b = options.y) !== null && _b !== void 0 ? _b : 0,
|
||||
width: (_c = options.width) !== null && _c !== void 0 ? _c : 200,
|
||||
height: (_d = options.height) !== null && _d !== void 0 ? _d : 50,
|
||||
textColor: options.textColor,
|
||||
backgroundColor: options.backgroundColor,
|
||||
borderColor: options.borderColor,
|
||||
borderWidth: (_e = options.borderWidth) !== null && _e !== void 0 ? _e : 0,
|
||||
rotate: (_f = options.rotate) !== null && _f !== void 0 ? _f : degrees(0),
|
||||
hidden: options.hidden,
|
||||
page: page.ref,
|
||||
});
|
||||
var widgetRef = this.doc.context.register(widget.dict);
|
||||
// Add widget to this field
|
||||
this.acroField.addWidget(widgetRef);
|
||||
// Set appearance streams for widget
|
||||
var font = (_g = options.font) !== null && _g !== void 0 ? _g : this.doc.getForm().getDefaultFont();
|
||||
this.updateWidgetAppearance(widget, font);
|
||||
// Add widget to the given page
|
||||
page.node.addAnnot(widgetRef);
|
||||
};
|
||||
/**
|
||||
* Returns `true` if this text field has been marked as dirty, or if any of
|
||||
* this text field's widgets do not have an appearance stream. For example:
|
||||
* ```js
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
* if (textField.needsAppearancesUpdate()) console.log('Needs update')
|
||||
* ```
|
||||
* @returns Whether or not this text field needs an appearance update.
|
||||
*/
|
||||
PDFTextField.prototype.needsAppearancesUpdate = function () {
|
||||
var _a;
|
||||
if (this.isDirty())
|
||||
return true;
|
||||
var widgets = this.acroField.getWidgets();
|
||||
for (var idx = 0, len = widgets.length; idx < len; idx++) {
|
||||
var widget = widgets[idx];
|
||||
var hasAppearances = ((_a = widget.getAppearances()) === null || _a === void 0 ? void 0 : _a.normal) instanceof PDFStream;
|
||||
if (!hasAppearances)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
/**
|
||||
* Update the appearance streams for each of this text field's widgets using
|
||||
* the default appearance provider for text fields. For example:
|
||||
* ```js
|
||||
* const helvetica = await pdfDoc.embedFont(StandardFonts.Helvetica)
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
* textField.defaultUpdateAppearances(helvetica)
|
||||
* ```
|
||||
* @param font The font to be used for creating the appearance streams.
|
||||
*/
|
||||
PDFTextField.prototype.defaultUpdateAppearances = function (font) {
|
||||
assertIs(font, 'font', [[PDFFont, 'PDFFont']]);
|
||||
this.updateAppearances(font);
|
||||
};
|
||||
/**
|
||||
* Update the appearance streams for each of this text field's widgets using
|
||||
* the given appearance provider. If no `provider` is passed, the default
|
||||
* appearance provider for text fields will be used. For example:
|
||||
* ```js
|
||||
* const helvetica = await pdfDoc.embedFont(StandardFonts.Helvetica)
|
||||
* const textField = form.getTextField('some.text.field')
|
||||
* textField.updateAppearances(helvetica, (field, widget, font) => {
|
||||
* ...
|
||||
* return drawTextField(...)
|
||||
* })
|
||||
* ```
|
||||
* @param font The font to be used for creating the appearance streams.
|
||||
* @param provider Optionally, the appearance provider to be used for
|
||||
* generating the contents of the appearance streams.
|
||||
*/
|
||||
PDFTextField.prototype.updateAppearances = function (font, provider) {
|
||||
assertIs(font, 'font', [[PDFFont, 'PDFFont']]);
|
||||
assertOrUndefined(provider, 'provider', [Function]);
|
||||
var widgets = this.acroField.getWidgets();
|
||||
for (var idx = 0, len = widgets.length; idx < len; idx++) {
|
||||
var widget = widgets[idx];
|
||||
this.updateWidgetAppearance(widget, font, provider);
|
||||
}
|
||||
this.markAsClean();
|
||||
};
|
||||
PDFTextField.prototype.updateWidgetAppearance = function (widget, font, provider) {
|
||||
var apProvider = provider !== null && provider !== void 0 ? provider : defaultTextFieldAppearanceProvider;
|
||||
var appearances = normalizeAppearance(apProvider(this, widget, font));
|
||||
this.updateWidgetAppearanceWithFont(widget, font, appearances);
|
||||
};
|
||||
/**
|
||||
* > **NOTE:** You probably don't want to call this method directly. Instead,
|
||||
* > consider using the [[PDFForm.getTextField]] method, which will create an
|
||||
* > instance of [[PDFTextField]] for you.
|
||||
*
|
||||
* Create an instance of [[PDFTextField]] from an existing acroText and ref
|
||||
*
|
||||
* @param acroText The underlying `PDFAcroText` for this text field.
|
||||
* @param ref The unique reference for this text field.
|
||||
* @param doc The document to which this text field will belong.
|
||||
*/
|
||||
PDFTextField.of = function (acroText, ref, doc) {
|
||||
return new PDFTextField(acroText, ref, doc);
|
||||
};
|
||||
return PDFTextField;
|
||||
}(PDFField));
|
||||
export default PDFTextField;
|
||||
//# sourceMappingURL=PDFTextField.js.map
|
||||
1
node_modules/pdf-lib/es/api/form/PDFTextField.js.map
generated
vendored
Normal file
1
node_modules/pdf-lib/es/api/form/PDFTextField.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
42
node_modules/pdf-lib/es/api/form/appearances.d.ts
generated
vendored
Normal file
42
node_modules/pdf-lib/es/api/form/appearances.d.ts
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
import { PDFOperator, PDFWidgetAnnotation } from "../../core";
|
||||
import PDFFont from "../PDFFont";
|
||||
import PDFButton from "./PDFButton";
|
||||
import PDFCheckBox from "./PDFCheckBox";
|
||||
import PDFDropdown from "./PDFDropdown";
|
||||
import PDFField from "./PDFField";
|
||||
import PDFOptionList from "./PDFOptionList";
|
||||
import PDFRadioGroup from "./PDFRadioGroup";
|
||||
import PDFSignature from "./PDFSignature";
|
||||
import PDFTextField from "./PDFTextField";
|
||||
/*********************** Appearance Provider Types ****************************/
|
||||
declare type CheckBoxAppearanceProvider = (checkBox: PDFCheckBox, widget: PDFWidgetAnnotation) => AppearanceOrMapping<{
|
||||
on: PDFOperator[];
|
||||
off: PDFOperator[];
|
||||
}>;
|
||||
declare type RadioGroupAppearanceProvider = (radioGroup: PDFRadioGroup, widget: PDFWidgetAnnotation) => AppearanceOrMapping<{
|
||||
on: PDFOperator[];
|
||||
off: PDFOperator[];
|
||||
}>;
|
||||
declare type ButtonAppearanceProvider = (button: PDFButton, widget: PDFWidgetAnnotation, font: PDFFont) => AppearanceOrMapping<PDFOperator[]>;
|
||||
declare type DropdownAppearanceProvider = (dropdown: PDFDropdown, widget: PDFWidgetAnnotation, font: PDFFont) => AppearanceOrMapping<PDFOperator[]>;
|
||||
declare type OptionListAppearanceProvider = (optionList: PDFOptionList, widget: PDFWidgetAnnotation, font: PDFFont) => AppearanceOrMapping<PDFOperator[]>;
|
||||
declare type TextFieldAppearanceProvider = (textField: PDFTextField, widget: PDFWidgetAnnotation, font: PDFFont) => AppearanceOrMapping<PDFOperator[]>;
|
||||
declare type SignatureAppearanceProvider = (signature: PDFSignature, widget: PDFWidgetAnnotation, font: PDFFont) => AppearanceOrMapping<PDFOperator[]>;
|
||||
/******************* Appearance Provider Utility Types ************************/
|
||||
export declare type AppearanceMapping<T> = {
|
||||
normal: T;
|
||||
rollover?: T;
|
||||
down?: T;
|
||||
};
|
||||
declare type AppearanceOrMapping<T> = T | AppearanceMapping<T>;
|
||||
export declare type AppearanceProviderFor<T extends PDFField> = T extends PDFCheckBox ? CheckBoxAppearanceProvider : T extends PDFRadioGroup ? RadioGroupAppearanceProvider : T extends PDFButton ? ButtonAppearanceProvider : T extends PDFDropdown ? DropdownAppearanceProvider : T extends PDFOptionList ? OptionListAppearanceProvider : T extends PDFTextField ? TextFieldAppearanceProvider : T extends PDFSignature ? SignatureAppearanceProvider : never;
|
||||
/********************* Appearance Provider Functions **************************/
|
||||
export declare const normalizeAppearance: <T>(appearance: T | AppearanceMapping<T>) => AppearanceMapping<T>;
|
||||
export declare const defaultCheckBoxAppearanceProvider: AppearanceProviderFor<PDFCheckBox>;
|
||||
export declare const defaultRadioGroupAppearanceProvider: AppearanceProviderFor<PDFRadioGroup>;
|
||||
export declare const defaultButtonAppearanceProvider: AppearanceProviderFor<PDFButton>;
|
||||
export declare const defaultTextFieldAppearanceProvider: AppearanceProviderFor<PDFTextField>;
|
||||
export declare const defaultDropdownAppearanceProvider: AppearanceProviderFor<PDFDropdown>;
|
||||
export declare const defaultOptionListAppearanceProvider: AppearanceProviderFor<PDFOptionList>;
|
||||
export {};
|
||||
//# sourceMappingURL=appearances.d.ts.map
|
||||
1
node_modules/pdf-lib/es/api/form/appearances.d.ts.map
generated
vendored
Normal file
1
node_modules/pdf-lib/es/api/form/appearances.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"appearances.d.ts","sourceRoot":"","sources":["../../../src/api/form/appearances.ts"],"names":[],"mappings":"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"}
|
||||
418
node_modules/pdf-lib/es/api/form/appearances.js
generated
vendored
Normal file
418
node_modules/pdf-lib/es/api/form/appearances.js
generated
vendored
Normal file
@@ -0,0 +1,418 @@
|
||||
import { __assign, __spreadArrays } from "tslib";
|
||||
import { drawCheckBox, rotateInPlace, drawRadioButton, drawButton, drawTextField, drawOptionList, } from "../operations";
|
||||
import { rgb, componentsToColor, setFillingColor, grayscale, cmyk, } from "../colors";
|
||||
import { reduceRotation, adjustDimsForRotation } from "../rotations";
|
||||
import { layoutMultilineText, layoutCombedText, layoutSinglelineText, } from "../text/layout";
|
||||
import { TextAlignment } from "../text/alignment";
|
||||
import { setFontAndSize } from "../operators";
|
||||
import { findLastMatch } from "../../utils";
|
||||
/********************* Appearance Provider Functions **************************/
|
||||
export var normalizeAppearance = function (appearance) {
|
||||
if ('normal' in appearance)
|
||||
return appearance;
|
||||
return { normal: appearance };
|
||||
};
|
||||
// Examples:
|
||||
// `/Helv 12 Tf` -> ['/Helv 12 Tf', 'Helv', '12']
|
||||
// `/HeBo 8.00 Tf` -> ['/HeBo 8 Tf', 'HeBo', '8.00']
|
||||
var tfRegex = /\/([^\0\t\n\f\r\ ]+)[\0\t\n\f\r\ ]+(\d*\.\d+|\d+)[\0\t\n\f\r\ ]+Tf/;
|
||||
var getDefaultFontSize = function (field) {
|
||||
var _a, _b;
|
||||
var da = (_a = field.getDefaultAppearance()) !== null && _a !== void 0 ? _a : '';
|
||||
var daMatch = (_b = findLastMatch(da, tfRegex).match) !== null && _b !== void 0 ? _b : [];
|
||||
var defaultFontSize = Number(daMatch[2]);
|
||||
return isFinite(defaultFontSize) ? defaultFontSize : undefined;
|
||||
};
|
||||
// Examples:
|
||||
// `0.3 g` -> ['0.3', 'g']
|
||||
// `0.3 1 .3 rg` -> ['0.3', '1', '.3', 'rg']
|
||||
// `0.3 1 .3 0 k` -> ['0.3', '1', '.3', '0', 'k']
|
||||
var colorRegex = /(\d*\.\d+|\d+)[\0\t\n\f\r\ ]*(\d*\.\d+|\d+)?[\0\t\n\f\r\ ]*(\d*\.\d+|\d+)?[\0\t\n\f\r\ ]*(\d*\.\d+|\d+)?[\0\t\n\f\r\ ]+(g|rg|k)/;
|
||||
var getDefaultColor = function (field) {
|
||||
var _a;
|
||||
var da = (_a = field.getDefaultAppearance()) !== null && _a !== void 0 ? _a : '';
|
||||
var daMatch = findLastMatch(da, colorRegex).match;
|
||||
var _b = daMatch !== null && daMatch !== void 0 ? daMatch : [], c1 = _b[1], c2 = _b[2], c3 = _b[3], c4 = _b[4], colorSpace = _b[5];
|
||||
if (colorSpace === 'g' && c1) {
|
||||
return grayscale(Number(c1));
|
||||
}
|
||||
if (colorSpace === 'rg' && c1 && c2 && c3) {
|
||||
return rgb(Number(c1), Number(c2), Number(c3));
|
||||
}
|
||||
if (colorSpace === 'k' && c1 && c2 && c3 && c4) {
|
||||
return cmyk(Number(c1), Number(c2), Number(c3), Number(c4));
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
var updateDefaultAppearance = function (field, color, font, fontSize) {
|
||||
var _a;
|
||||
if (fontSize === void 0) { fontSize = 0; }
|
||||
var da = [
|
||||
setFillingColor(color).toString(),
|
||||
setFontAndSize((_a = font === null || font === void 0 ? void 0 : font.name) !== null && _a !== void 0 ? _a : 'dummy__noop', fontSize).toString(),
|
||||
].join('\n');
|
||||
field.setDefaultAppearance(da);
|
||||
};
|
||||
export var defaultCheckBoxAppearanceProvider = function (checkBox, widget) {
|
||||
var _a, _b, _c;
|
||||
// The `/DA` entry can be at the widget or field level - so we handle both
|
||||
var widgetColor = getDefaultColor(widget);
|
||||
var fieldColor = getDefaultColor(checkBox.acroField);
|
||||
var rectangle = widget.getRectangle();
|
||||
var ap = widget.getAppearanceCharacteristics();
|
||||
var bs = widget.getBorderStyle();
|
||||
var borderWidth = (_a = bs === null || bs === void 0 ? void 0 : bs.getWidth()) !== null && _a !== void 0 ? _a : 0;
|
||||
var rotation = reduceRotation(ap === null || ap === void 0 ? void 0 : ap.getRotation());
|
||||
var _d = adjustDimsForRotation(rectangle, rotation), width = _d.width, height = _d.height;
|
||||
var rotate = rotateInPlace(__assign(__assign({}, rectangle), { rotation: rotation }));
|
||||
var black = rgb(0, 0, 0);
|
||||
var borderColor = (_b = componentsToColor(ap === null || ap === void 0 ? void 0 : ap.getBorderColor())) !== null && _b !== void 0 ? _b : black;
|
||||
var normalBackgroundColor = componentsToColor(ap === null || ap === void 0 ? void 0 : ap.getBackgroundColor());
|
||||
var downBackgroundColor = componentsToColor(ap === null || ap === void 0 ? void 0 : ap.getBackgroundColor(), 0.8);
|
||||
// Update color
|
||||
var textColor = (_c = widgetColor !== null && widgetColor !== void 0 ? widgetColor : fieldColor) !== null && _c !== void 0 ? _c : black;
|
||||
if (widgetColor) {
|
||||
updateDefaultAppearance(widget, textColor);
|
||||
}
|
||||
else {
|
||||
updateDefaultAppearance(checkBox.acroField, textColor);
|
||||
}
|
||||
var options = {
|
||||
x: 0 + borderWidth / 2,
|
||||
y: 0 + borderWidth / 2,
|
||||
width: width - borderWidth,
|
||||
height: height - borderWidth,
|
||||
thickness: 1.5,
|
||||
borderWidth: borderWidth,
|
||||
borderColor: borderColor,
|
||||
markColor: textColor,
|
||||
};
|
||||
return {
|
||||
normal: {
|
||||
on: __spreadArrays(rotate, drawCheckBox(__assign(__assign({}, options), { color: normalBackgroundColor, filled: true }))),
|
||||
off: __spreadArrays(rotate, drawCheckBox(__assign(__assign({}, options), { color: normalBackgroundColor, filled: false }))),
|
||||
},
|
||||
down: {
|
||||
on: __spreadArrays(rotate, drawCheckBox(__assign(__assign({}, options), { color: downBackgroundColor, filled: true }))),
|
||||
off: __spreadArrays(rotate, drawCheckBox(__assign(__assign({}, options), { color: downBackgroundColor, filled: false }))),
|
||||
},
|
||||
};
|
||||
};
|
||||
export var defaultRadioGroupAppearanceProvider = function (radioGroup, widget) {
|
||||
var _a, _b, _c;
|
||||
// The `/DA` entry can be at the widget or field level - so we handle both
|
||||
var widgetColor = getDefaultColor(widget);
|
||||
var fieldColor = getDefaultColor(radioGroup.acroField);
|
||||
var rectangle = widget.getRectangle();
|
||||
var ap = widget.getAppearanceCharacteristics();
|
||||
var bs = widget.getBorderStyle();
|
||||
var borderWidth = (_a = bs === null || bs === void 0 ? void 0 : bs.getWidth()) !== null && _a !== void 0 ? _a : 0;
|
||||
var rotation = reduceRotation(ap === null || ap === void 0 ? void 0 : ap.getRotation());
|
||||
var _d = adjustDimsForRotation(rectangle, rotation), width = _d.width, height = _d.height;
|
||||
var rotate = rotateInPlace(__assign(__assign({}, rectangle), { rotation: rotation }));
|
||||
var black = rgb(0, 0, 0);
|
||||
var borderColor = (_b = componentsToColor(ap === null || ap === void 0 ? void 0 : ap.getBorderColor())) !== null && _b !== void 0 ? _b : black;
|
||||
var normalBackgroundColor = componentsToColor(ap === null || ap === void 0 ? void 0 : ap.getBackgroundColor());
|
||||
var downBackgroundColor = componentsToColor(ap === null || ap === void 0 ? void 0 : ap.getBackgroundColor(), 0.8);
|
||||
// Update color
|
||||
var textColor = (_c = widgetColor !== null && widgetColor !== void 0 ? widgetColor : fieldColor) !== null && _c !== void 0 ? _c : black;
|
||||
if (widgetColor) {
|
||||
updateDefaultAppearance(widget, textColor);
|
||||
}
|
||||
else {
|
||||
updateDefaultAppearance(radioGroup.acroField, textColor);
|
||||
}
|
||||
var options = {
|
||||
x: width / 2,
|
||||
y: height / 2,
|
||||
width: width - borderWidth,
|
||||
height: height - borderWidth,
|
||||
borderWidth: borderWidth,
|
||||
borderColor: borderColor,
|
||||
dotColor: textColor,
|
||||
};
|
||||
return {
|
||||
normal: {
|
||||
on: __spreadArrays(rotate, drawRadioButton(__assign(__assign({}, options), { color: normalBackgroundColor, filled: true }))),
|
||||
off: __spreadArrays(rotate, drawRadioButton(__assign(__assign({}, options), { color: normalBackgroundColor, filled: false }))),
|
||||
},
|
||||
down: {
|
||||
on: __spreadArrays(rotate, drawRadioButton(__assign(__assign({}, options), { color: downBackgroundColor, filled: true }))),
|
||||
off: __spreadArrays(rotate, drawRadioButton(__assign(__assign({}, options), { color: downBackgroundColor, filled: false }))),
|
||||
},
|
||||
};
|
||||
};
|
||||
export var defaultButtonAppearanceProvider = function (button, widget, font) {
|
||||
var _a, _b, _c, _d, _e;
|
||||
// The `/DA` entry can be at the widget or field level - so we handle both
|
||||
var widgetColor = getDefaultColor(widget);
|
||||
var fieldColor = getDefaultColor(button.acroField);
|
||||
var widgetFontSize = getDefaultFontSize(widget);
|
||||
var fieldFontSize = getDefaultFontSize(button.acroField);
|
||||
var rectangle = widget.getRectangle();
|
||||
var ap = widget.getAppearanceCharacteristics();
|
||||
var bs = widget.getBorderStyle();
|
||||
var captions = ap === null || ap === void 0 ? void 0 : ap.getCaptions();
|
||||
var normalText = (_a = captions === null || captions === void 0 ? void 0 : captions.normal) !== null && _a !== void 0 ? _a : '';
|
||||
var downText = (_c = (_b = captions === null || captions === void 0 ? void 0 : captions.down) !== null && _b !== void 0 ? _b : normalText) !== null && _c !== void 0 ? _c : '';
|
||||
var borderWidth = (_d = bs === null || bs === void 0 ? void 0 : bs.getWidth()) !== null && _d !== void 0 ? _d : 0;
|
||||
var rotation = reduceRotation(ap === null || ap === void 0 ? void 0 : ap.getRotation());
|
||||
var _f = adjustDimsForRotation(rectangle, rotation), width = _f.width, height = _f.height;
|
||||
var rotate = rotateInPlace(__assign(__assign({}, rectangle), { rotation: rotation }));
|
||||
var black = rgb(0, 0, 0);
|
||||
var borderColor = componentsToColor(ap === null || ap === void 0 ? void 0 : ap.getBorderColor());
|
||||
var normalBackgroundColor = componentsToColor(ap === null || ap === void 0 ? void 0 : ap.getBackgroundColor());
|
||||
var downBackgroundColor = componentsToColor(ap === null || ap === void 0 ? void 0 : ap.getBackgroundColor(), 0.8);
|
||||
var bounds = {
|
||||
x: borderWidth,
|
||||
y: borderWidth,
|
||||
width: width - borderWidth * 2,
|
||||
height: height - borderWidth * 2,
|
||||
};
|
||||
var normalLayout = layoutSinglelineText(normalText, {
|
||||
alignment: TextAlignment.Center,
|
||||
fontSize: widgetFontSize !== null && widgetFontSize !== void 0 ? widgetFontSize : fieldFontSize,
|
||||
font: font,
|
||||
bounds: bounds,
|
||||
});
|
||||
var downLayout = layoutSinglelineText(downText, {
|
||||
alignment: TextAlignment.Center,
|
||||
fontSize: widgetFontSize !== null && widgetFontSize !== void 0 ? widgetFontSize : fieldFontSize,
|
||||
font: font,
|
||||
bounds: bounds,
|
||||
});
|
||||
// Update font size and color
|
||||
var fontSize = Math.min(normalLayout.fontSize, downLayout.fontSize);
|
||||
var textColor = (_e = widgetColor !== null && widgetColor !== void 0 ? widgetColor : fieldColor) !== null && _e !== void 0 ? _e : black;
|
||||
if (widgetColor || widgetFontSize !== undefined) {
|
||||
updateDefaultAppearance(widget, textColor, font, fontSize);
|
||||
}
|
||||
else {
|
||||
updateDefaultAppearance(button.acroField, textColor, font, fontSize);
|
||||
}
|
||||
var options = {
|
||||
x: 0 + borderWidth / 2,
|
||||
y: 0 + borderWidth / 2,
|
||||
width: width - borderWidth,
|
||||
height: height - borderWidth,
|
||||
borderWidth: borderWidth,
|
||||
borderColor: borderColor,
|
||||
textColor: textColor,
|
||||
font: font.name,
|
||||
fontSize: fontSize,
|
||||
};
|
||||
return {
|
||||
normal: __spreadArrays(rotate, drawButton(__assign(__assign({}, options), { color: normalBackgroundColor, textLines: [normalLayout.line] }))),
|
||||
down: __spreadArrays(rotate, drawButton(__assign(__assign({}, options), { color: downBackgroundColor, textLines: [downLayout.line] }))),
|
||||
};
|
||||
};
|
||||
export var defaultTextFieldAppearanceProvider = function (textField, widget, font) {
|
||||
var _a, _b, _c, _d;
|
||||
// The `/DA` entry can be at the widget or field level - so we handle both
|
||||
var widgetColor = getDefaultColor(widget);
|
||||
var fieldColor = getDefaultColor(textField.acroField);
|
||||
var widgetFontSize = getDefaultFontSize(widget);
|
||||
var fieldFontSize = getDefaultFontSize(textField.acroField);
|
||||
var rectangle = widget.getRectangle();
|
||||
var ap = widget.getAppearanceCharacteristics();
|
||||
var bs = widget.getBorderStyle();
|
||||
var text = (_a = textField.getText()) !== null && _a !== void 0 ? _a : '';
|
||||
var borderWidth = (_b = bs === null || bs === void 0 ? void 0 : bs.getWidth()) !== null && _b !== void 0 ? _b : 0;
|
||||
var rotation = reduceRotation(ap === null || ap === void 0 ? void 0 : ap.getRotation());
|
||||
var _e = adjustDimsForRotation(rectangle, rotation), width = _e.width, height = _e.height;
|
||||
var rotate = rotateInPlace(__assign(__assign({}, rectangle), { rotation: rotation }));
|
||||
var black = rgb(0, 0, 0);
|
||||
var borderColor = componentsToColor(ap === null || ap === void 0 ? void 0 : ap.getBorderColor());
|
||||
var normalBackgroundColor = componentsToColor(ap === null || ap === void 0 ? void 0 : ap.getBackgroundColor());
|
||||
var textLines;
|
||||
var fontSize;
|
||||
var padding = textField.isCombed() ? 0 : 1;
|
||||
var bounds = {
|
||||
x: borderWidth + padding,
|
||||
y: borderWidth + padding,
|
||||
width: width - (borderWidth + padding) * 2,
|
||||
height: height - (borderWidth + padding) * 2,
|
||||
};
|
||||
if (textField.isMultiline()) {
|
||||
var layout = layoutMultilineText(text, {
|
||||
alignment: textField.getAlignment(),
|
||||
fontSize: widgetFontSize !== null && widgetFontSize !== void 0 ? widgetFontSize : fieldFontSize,
|
||||
font: font,
|
||||
bounds: bounds,
|
||||
});
|
||||
textLines = layout.lines;
|
||||
fontSize = layout.fontSize;
|
||||
}
|
||||
else if (textField.isCombed()) {
|
||||
var layout = layoutCombedText(text, {
|
||||
fontSize: widgetFontSize !== null && widgetFontSize !== void 0 ? widgetFontSize : fieldFontSize,
|
||||
font: font,
|
||||
bounds: bounds,
|
||||
cellCount: (_c = textField.getMaxLength()) !== null && _c !== void 0 ? _c : 0,
|
||||
});
|
||||
textLines = layout.cells;
|
||||
fontSize = layout.fontSize;
|
||||
}
|
||||
else {
|
||||
var layout = layoutSinglelineText(text, {
|
||||
alignment: textField.getAlignment(),
|
||||
fontSize: widgetFontSize !== null && widgetFontSize !== void 0 ? widgetFontSize : fieldFontSize,
|
||||
font: font,
|
||||
bounds: bounds,
|
||||
});
|
||||
textLines = [layout.line];
|
||||
fontSize = layout.fontSize;
|
||||
}
|
||||
// Update font size and color
|
||||
var textColor = (_d = widgetColor !== null && widgetColor !== void 0 ? widgetColor : fieldColor) !== null && _d !== void 0 ? _d : black;
|
||||
if (widgetColor || widgetFontSize !== undefined) {
|
||||
updateDefaultAppearance(widget, textColor, font, fontSize);
|
||||
}
|
||||
else {
|
||||
updateDefaultAppearance(textField.acroField, textColor, font, fontSize);
|
||||
}
|
||||
var options = {
|
||||
x: 0 + borderWidth / 2,
|
||||
y: 0 + borderWidth / 2,
|
||||
width: width - borderWidth,
|
||||
height: height - borderWidth,
|
||||
borderWidth: borderWidth !== null && borderWidth !== void 0 ? borderWidth : 0,
|
||||
borderColor: borderColor,
|
||||
textColor: textColor,
|
||||
font: font.name,
|
||||
fontSize: fontSize,
|
||||
color: normalBackgroundColor,
|
||||
textLines: textLines,
|
||||
padding: padding,
|
||||
};
|
||||
return __spreadArrays(rotate, drawTextField(options));
|
||||
};
|
||||
export var defaultDropdownAppearanceProvider = function (dropdown, widget, font) {
|
||||
var _a, _b, _c;
|
||||
// The `/DA` entry can be at the widget or field level - so we handle both
|
||||
var widgetColor = getDefaultColor(widget);
|
||||
var fieldColor = getDefaultColor(dropdown.acroField);
|
||||
var widgetFontSize = getDefaultFontSize(widget);
|
||||
var fieldFontSize = getDefaultFontSize(dropdown.acroField);
|
||||
var rectangle = widget.getRectangle();
|
||||
var ap = widget.getAppearanceCharacteristics();
|
||||
var bs = widget.getBorderStyle();
|
||||
var text = (_a = dropdown.getSelected()[0]) !== null && _a !== void 0 ? _a : '';
|
||||
var borderWidth = (_b = bs === null || bs === void 0 ? void 0 : bs.getWidth()) !== null && _b !== void 0 ? _b : 0;
|
||||
var rotation = reduceRotation(ap === null || ap === void 0 ? void 0 : ap.getRotation());
|
||||
var _d = adjustDimsForRotation(rectangle, rotation), width = _d.width, height = _d.height;
|
||||
var rotate = rotateInPlace(__assign(__assign({}, rectangle), { rotation: rotation }));
|
||||
var black = rgb(0, 0, 0);
|
||||
var borderColor = componentsToColor(ap === null || ap === void 0 ? void 0 : ap.getBorderColor());
|
||||
var normalBackgroundColor = componentsToColor(ap === null || ap === void 0 ? void 0 : ap.getBackgroundColor());
|
||||
var padding = 1;
|
||||
var bounds = {
|
||||
x: borderWidth + padding,
|
||||
y: borderWidth + padding,
|
||||
width: width - (borderWidth + padding) * 2,
|
||||
height: height - (borderWidth + padding) * 2,
|
||||
};
|
||||
var _e = layoutSinglelineText(text, {
|
||||
alignment: TextAlignment.Left,
|
||||
fontSize: widgetFontSize !== null && widgetFontSize !== void 0 ? widgetFontSize : fieldFontSize,
|
||||
font: font,
|
||||
bounds: bounds,
|
||||
}), line = _e.line, fontSize = _e.fontSize;
|
||||
// Update font size and color
|
||||
var textColor = (_c = widgetColor !== null && widgetColor !== void 0 ? widgetColor : fieldColor) !== null && _c !== void 0 ? _c : black;
|
||||
if (widgetColor || widgetFontSize !== undefined) {
|
||||
updateDefaultAppearance(widget, textColor, font, fontSize);
|
||||
}
|
||||
else {
|
||||
updateDefaultAppearance(dropdown.acroField, textColor, font, fontSize);
|
||||
}
|
||||
var options = {
|
||||
x: 0 + borderWidth / 2,
|
||||
y: 0 + borderWidth / 2,
|
||||
width: width - borderWidth,
|
||||
height: height - borderWidth,
|
||||
borderWidth: borderWidth !== null && borderWidth !== void 0 ? borderWidth : 0,
|
||||
borderColor: borderColor,
|
||||
textColor: textColor,
|
||||
font: font.name,
|
||||
fontSize: fontSize,
|
||||
color: normalBackgroundColor,
|
||||
textLines: [line],
|
||||
padding: padding,
|
||||
};
|
||||
return __spreadArrays(rotate, drawTextField(options));
|
||||
};
|
||||
export var defaultOptionListAppearanceProvider = function (optionList, widget, font) {
|
||||
var _a, _b;
|
||||
// The `/DA` entry can be at the widget or field level - so we handle both
|
||||
var widgetColor = getDefaultColor(widget);
|
||||
var fieldColor = getDefaultColor(optionList.acroField);
|
||||
var widgetFontSize = getDefaultFontSize(widget);
|
||||
var fieldFontSize = getDefaultFontSize(optionList.acroField);
|
||||
var rectangle = widget.getRectangle();
|
||||
var ap = widget.getAppearanceCharacteristics();
|
||||
var bs = widget.getBorderStyle();
|
||||
var borderWidth = (_a = bs === null || bs === void 0 ? void 0 : bs.getWidth()) !== null && _a !== void 0 ? _a : 0;
|
||||
var rotation = reduceRotation(ap === null || ap === void 0 ? void 0 : ap.getRotation());
|
||||
var _c = adjustDimsForRotation(rectangle, rotation), width = _c.width, height = _c.height;
|
||||
var rotate = rotateInPlace(__assign(__assign({}, rectangle), { rotation: rotation }));
|
||||
var black = rgb(0, 0, 0);
|
||||
var borderColor = componentsToColor(ap === null || ap === void 0 ? void 0 : ap.getBorderColor());
|
||||
var normalBackgroundColor = componentsToColor(ap === null || ap === void 0 ? void 0 : ap.getBackgroundColor());
|
||||
var options = optionList.getOptions();
|
||||
var selected = optionList.getSelected();
|
||||
if (optionList.isSorted())
|
||||
options.sort();
|
||||
var text = '';
|
||||
for (var idx = 0, len = options.length; idx < len; idx++) {
|
||||
text += options[idx];
|
||||
if (idx < len - 1)
|
||||
text += '\n';
|
||||
}
|
||||
var padding = 1;
|
||||
var bounds = {
|
||||
x: borderWidth + padding,
|
||||
y: borderWidth + padding,
|
||||
width: width - (borderWidth + padding) * 2,
|
||||
height: height - (borderWidth + padding) * 2,
|
||||
};
|
||||
var _d = layoutMultilineText(text, {
|
||||
alignment: TextAlignment.Left,
|
||||
fontSize: widgetFontSize !== null && widgetFontSize !== void 0 ? widgetFontSize : fieldFontSize,
|
||||
font: font,
|
||||
bounds: bounds,
|
||||
}), lines = _d.lines, fontSize = _d.fontSize, lineHeight = _d.lineHeight;
|
||||
var selectedLines = [];
|
||||
for (var idx = 0, len = lines.length; idx < len; idx++) {
|
||||
var line = lines[idx];
|
||||
if (selected.includes(line.text))
|
||||
selectedLines.push(idx);
|
||||
}
|
||||
var blue = rgb(153 / 255, 193 / 255, 218 / 255);
|
||||
// Update font size and color
|
||||
var textColor = (_b = widgetColor !== null && widgetColor !== void 0 ? widgetColor : fieldColor) !== null && _b !== void 0 ? _b : black;
|
||||
if (widgetColor || widgetFontSize !== undefined) {
|
||||
updateDefaultAppearance(widget, textColor, font, fontSize);
|
||||
}
|
||||
else {
|
||||
updateDefaultAppearance(optionList.acroField, textColor, font, fontSize);
|
||||
}
|
||||
return __spreadArrays(rotate, drawOptionList({
|
||||
x: 0 + borderWidth / 2,
|
||||
y: 0 + borderWidth / 2,
|
||||
width: width - borderWidth,
|
||||
height: height - borderWidth,
|
||||
borderWidth: borderWidth !== null && borderWidth !== void 0 ? borderWidth : 0,
|
||||
borderColor: borderColor,
|
||||
textColor: textColor,
|
||||
font: font.name,
|
||||
fontSize: fontSize,
|
||||
color: normalBackgroundColor,
|
||||
textLines: lines,
|
||||
lineHeight: lineHeight,
|
||||
selectedColor: blue,
|
||||
selectedLines: selectedLines,
|
||||
padding: padding,
|
||||
}));
|
||||
};
|
||||
//# sourceMappingURL=appearances.js.map
|
||||
1
node_modules/pdf-lib/es/api/form/appearances.js.map
generated
vendored
Normal file
1
node_modules/pdf-lib/es/api/form/appearances.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
11
node_modules/pdf-lib/es/api/form/index.d.ts
generated
vendored
Normal file
11
node_modules/pdf-lib/es/api/form/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
export * from "./appearances";
|
||||
export { default as PDFButton } from "./PDFButton";
|
||||
export { default as PDFCheckBox } from "./PDFCheckBox";
|
||||
export { default as PDFDropdown } from "./PDFDropdown";
|
||||
export { default as PDFField } from "./PDFField";
|
||||
export { default as PDFForm } from "./PDFForm";
|
||||
export { default as PDFOptionList } from "./PDFOptionList";
|
||||
export { default as PDFRadioGroup } from "./PDFRadioGroup";
|
||||
export { default as PDFSignature } from "./PDFSignature";
|
||||
export { default as PDFTextField } from "./PDFTextField";
|
||||
//# sourceMappingURL=index.d.ts.map
|
||||
1
node_modules/pdf-lib/es/api/form/index.d.ts.map
generated
vendored
Normal file
1
node_modules/pdf-lib/es/api/form/index.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/api/form/index.ts"],"names":[],"mappings":"AAAA,cAUmJ,eAAe,CAVzH;AACzC,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MASmI,aAAa,CATjH;AAC9D,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAQ8I,eAAe,CAR5H;AAClE,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAO6J,eAAe,CAP3I;AAClE,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAM+K,YAAY,CAN7J;AAC5D,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAK4L,WAAW,CAL1K;AAC1D,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAIiM,iBAAiB,CAJ/K;AACtE,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAGkN,iBAAiB,CAHhM;AACtE,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAEoO,gBAAgB,CAFlN;AACpE,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MACoP,gBAAgB,CADlO"}
|
||||
11
node_modules/pdf-lib/es/api/form/index.js
generated
vendored
Normal file
11
node_modules/pdf-lib/es/api/form/index.js
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
export * from "./appearances";
|
||||
export { default as PDFButton } from "./PDFButton";
|
||||
export { default as PDFCheckBox } from "./PDFCheckBox";
|
||||
export { default as PDFDropdown } from "./PDFDropdown";
|
||||
export { default as PDFField } from "./PDFField";
|
||||
export { default as PDFForm } from "./PDFForm";
|
||||
export { default as PDFOptionList } from "./PDFOptionList";
|
||||
export { default as PDFRadioGroup } from "./PDFRadioGroup";
|
||||
export { default as PDFSignature } from "./PDFSignature";
|
||||
export { default as PDFTextField } from "./PDFTextField";
|
||||
//# sourceMappingURL=index.js.map
|
||||
1
node_modules/pdf-lib/es/api/form/index.js.map
generated
vendored
Normal file
1
node_modules/pdf-lib/es/api/form/index.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/api/form/index.ts"],"names":[],"mappings":"AAAA,cAUA,eAAe,CAV0B;AACzC,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAShB,aAAa,CATkC;AAC9D,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAQL,eAAe,CARuB;AAClE,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAOU,eAAe,CAPQ;AAClE,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAM4B,YAAY,CANV;AAC5D,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAKyC,WAAW,CALvB;AAC1D,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAI8C,iBAAiB,CAJ5B;AACtE,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAG+D,iBAAiB,CAH7C;AACtE,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAEiF,gBAAgB,CAF/D;AACpE,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MACiG,gBAAgB,CAD/E"}
|
||||
Reference in New Issue
Block a user