first commit
This commit is contained in:
21
node_modules/pdf-lib/LICENSE.md
generated
vendored
Normal file
21
node_modules/pdf-lib/LICENSE.md
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019 Andrew Dillon
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
1504
node_modules/pdf-lib/README.md
generated
vendored
Normal file
1504
node_modules/pdf-lib/README.md
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
8
node_modules/pdf-lib/cjs/api/Embeddable.d.ts
generated
vendored
Normal file
8
node_modules/pdf-lib/cjs/api/Embeddable.d.ts
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* A PDF entity, like images or fonts, which needs to be embedded into the
|
||||
* document before saving.
|
||||
*/
|
||||
export default interface Embeddable {
|
||||
embed: () => Promise<void>;
|
||||
}
|
||||
//# sourceMappingURL=Embeddable.d.ts.map
|
||||
1
node_modules/pdf-lib/cjs/api/Embeddable.d.ts.map
generated
vendored
Normal file
1
node_modules/pdf-lib/cjs/api/Embeddable.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"Embeddable.d.ts","sourceRoot":"","sources":["../../src/api/Embeddable.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,OAAO,WAAW,UAAU;IACjC,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5B"}
|
||||
3
node_modules/pdf-lib/cjs/api/Embeddable.js
generated
vendored
Normal file
3
node_modules/pdf-lib/cjs/api/Embeddable.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=Embeddable.js.map
|
||||
1
node_modules/pdf-lib/cjs/api/Embeddable.js.map
generated
vendored
Normal file
1
node_modules/pdf-lib/cjs/api/Embeddable.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"Embeddable.js","sourceRoot":"","sources":["../../src/api/Embeddable.ts"],"names":[],"mappings":""}
|
||||
779
node_modules/pdf-lib/cjs/api/PDFDocument.d.ts
generated
vendored
Normal file
779
node_modules/pdf-lib/cjs/api/PDFDocument.d.ts
generated
vendored
Normal file
@@ -0,0 +1,779 @@
|
||||
import PDFEmbeddedPage from "./PDFEmbeddedPage";
|
||||
import PDFFont from "./PDFFont";
|
||||
import PDFImage from "./PDFImage";
|
||||
import PDFPage from "./PDFPage";
|
||||
import PDFForm from "./form/PDFForm";
|
||||
import { StandardFonts } from "./StandardFonts";
|
||||
import { PageBoundingBox, PDFCatalog, PDFContext } from "../core";
|
||||
import { AttachmentOptions, SaveOptions, Base64SaveOptions, LoadOptions, CreateOptions, EmbedFontOptions, SetTitleOptions } from "./PDFDocumentOptions";
|
||||
import PDFRef from "../core/objects/PDFRef";
|
||||
import { Fontkit } from "../types/fontkit";
|
||||
import { TransformationMatrix } from "../types/matrix";
|
||||
/**
|
||||
* Represents a PDF document.
|
||||
*/
|
||||
export default class PDFDocument {
|
||||
/**
|
||||
* Load an existing [[PDFDocument]]. The input data can be provided in
|
||||
* multiple formats:
|
||||
*
|
||||
* | Type | Contents |
|
||||
* | ------------- | ------------------------------------------------------ |
|
||||
* | `string` | A base64 encoded string (or data URI) containing a PDF |
|
||||
* | `Uint8Array` | The raw bytes of a PDF |
|
||||
* | `ArrayBuffer` | The raw bytes of a PDF |
|
||||
*
|
||||
* For example:
|
||||
* ```js
|
||||
* import { PDFDocument } from 'pdf-lib'
|
||||
*
|
||||
* // pdf=string
|
||||
* const base64 =
|
||||
* 'JVBERi0xLjcKJYGBgYEKCjUgMCBvYmoKPDwKL0ZpbHRlciAvRmxhdGVEZWNvZGUKL0xlbm' +
|
||||
* 'd0aCAxMDQKPj4Kc3RyZWFtCniccwrhMlAAwaJ0Ln2P1Jyy1JLM5ERdc0MjCwUjE4WQNC4Q' +
|
||||
* '6cNlCFZkqGCqYGSqEJLLZWNuYGZiZmbkYuZsZmlmZGRgZmluDCQNzc3NTM2NzdzMXMxMjQ' +
|
||||
* 'ztFEKyuEK0uFxDuAAOERdVCmVuZHN0cmVhbQplbmRvYmoKCjYgMCBvYmoKPDwKL0ZpbHRl' +
|
||||
* 'ciAvRmxhdGVEZWNvZGUKL1R5cGUgL09ialN0bQovTiA0Ci9GaXJzdCAyMAovTGVuZ3RoID' +
|
||||
* 'IxNQo+PgpzdHJlYW0KeJxVj9GqwjAMhu/zFHkBzTo3nCCCiiKIHPEICuJF3cKoSCu2E8/b' +
|
||||
* '20wPIr1p8v9/8kVhgilmGfawX2CGaVrgcAi0/bsy0lrX7IGWpvJ4iJYEN3gEmrrGBlQwGs' +
|
||||
* 'HHO9VBX1wNrxAqMX87RBD5xpJuddqwd82tjAHxzV1U5LPgy52DKXWnr1Lheg+j/c/pzGVr' +
|
||||
* 'iqV0VlwZPXGPCJjElw/ybkwUmeoWgxesDXGhHJC/D/iikp1Av80ptKU0FdBEe25pPihAM1' +
|
||||
* 'u6ytgaaWfs2Hrz35CJT1+EWmAKZW5kc3RyZWFtCmVuZG9iagoKNyAwIG9iago8PAovU2l6' +
|
||||
* 'ZSA4Ci9Sb290IDIgMCBSCi9GaWx0ZXIgL0ZsYXRlRGVjb2RlCi9UeXBlIC9YUmVmCi9MZW' +
|
||||
* '5ndGggMzgKL1cgWyAxIDIgMiBdCi9JbmRleCBbIDAgOCBdCj4+CnN0cmVhbQp4nBXEwREA' +
|
||||
* 'EBAEsCwz3vrvRmOOyyOoGhZdutHN2MT55fIAVocD+AplbmRzdHJlYW0KZW5kb2JqCgpzdG' +
|
||||
* 'FydHhyZWYKNTEwCiUlRU9G'
|
||||
*
|
||||
* const dataUri = 'data:application/pdf;base64,' + base64
|
||||
*
|
||||
* const pdfDoc1 = await PDFDocument.load(base64)
|
||||
* const pdfDoc2 = await PDFDocument.load(dataUri)
|
||||
*
|
||||
* // pdf=Uint8Array
|
||||
* import fs from 'fs'
|
||||
* const uint8Array = fs.readFileSync('with_update_sections.pdf')
|
||||
* const pdfDoc3 = await PDFDocument.load(uint8Array)
|
||||
*
|
||||
* // pdf=ArrayBuffer
|
||||
* const url = 'https://pdf-lib.js.org/assets/with_update_sections.pdf'
|
||||
* const arrayBuffer = await fetch(url).then(res => res.arrayBuffer())
|
||||
* const pdfDoc4 = await PDFDocument.load(arrayBuffer)
|
||||
*
|
||||
* ```
|
||||
*
|
||||
* @param pdf The input data containing a PDF document.
|
||||
* @param options The options to be used when loading the document.
|
||||
* @returns Resolves with a document loaded from the input.
|
||||
*/
|
||||
static load(pdf: string | Uint8Array | ArrayBuffer, options?: LoadOptions): Promise<PDFDocument>;
|
||||
/**
|
||||
* Create a new [[PDFDocument]].
|
||||
* @returns Resolves with the newly created document.
|
||||
*/
|
||||
static create(options?: CreateOptions): Promise<PDFDocument>;
|
||||
/** The low-level context of this document. */
|
||||
readonly context: PDFContext;
|
||||
/** The catalog of this document. */
|
||||
readonly catalog: PDFCatalog;
|
||||
/** Whether or not this document is encrypted. */
|
||||
readonly isEncrypted: boolean;
|
||||
/** The default word breaks used in PDFPage.drawText */
|
||||
defaultWordBreaks: string[];
|
||||
private fontkit?;
|
||||
private pageCount;
|
||||
private readonly pageCache;
|
||||
private readonly pageMap;
|
||||
private readonly formCache;
|
||||
private readonly fonts;
|
||||
private readonly images;
|
||||
private readonly embeddedPages;
|
||||
private readonly embeddedFiles;
|
||||
private readonly javaScripts;
|
||||
private constructor();
|
||||
/**
|
||||
* Register a fontkit instance. This must be done before custom fonts can
|
||||
* be embedded. See [here](https://github.com/Hopding/pdf-lib/tree/master#fontkit-installation)
|
||||
* for instructions on how to install and register a fontkit instance.
|
||||
*
|
||||
* > You do **not** need to call this method to embed standard fonts.
|
||||
*
|
||||
* For example:
|
||||
* ```js
|
||||
* import { PDFDocument } from 'pdf-lib'
|
||||
* import fontkit from '@pdf-lib/fontkit'
|
||||
*
|
||||
* const pdfDoc = await PDFDocument.create()
|
||||
* pdfDoc.registerFontkit(fontkit)
|
||||
* ```
|
||||
*
|
||||
* @param fontkit The fontkit instance to be registered.
|
||||
*/
|
||||
registerFontkit(fontkit: Fontkit): void;
|
||||
/**
|
||||
* Get the [[PDFForm]] containing all interactive fields for this document.
|
||||
* 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 The form for this document.
|
||||
*/
|
||||
getForm(): PDFForm;
|
||||
/**
|
||||
* Get this document's title metadata. The title appears in the
|
||||
* "Document Properties" section of most PDF readers. For example:
|
||||
* ```js
|
||||
* const title = pdfDoc.getTitle()
|
||||
* ```
|
||||
* @returns A string containing the title of this document, if it has one.
|
||||
*/
|
||||
getTitle(): string | undefined;
|
||||
/**
|
||||
* Get this document's author metadata. The author appears in the
|
||||
* "Document Properties" section of most PDF readers. For example:
|
||||
* ```js
|
||||
* const author = pdfDoc.getAuthor()
|
||||
* ```
|
||||
* @returns A string containing the author of this document, if it has one.
|
||||
*/
|
||||
getAuthor(): string | undefined;
|
||||
/**
|
||||
* Get this document's subject metadata. The subject appears in the
|
||||
* "Document Properties" section of most PDF readers. For example:
|
||||
* ```js
|
||||
* const subject = pdfDoc.getSubject()
|
||||
* ```
|
||||
* @returns A string containing the subject of this document, if it has one.
|
||||
*/
|
||||
getSubject(): string | undefined;
|
||||
/**
|
||||
* Get this document's keywords metadata. The keywords appear in the
|
||||
* "Document Properties" section of most PDF readers. For example:
|
||||
* ```js
|
||||
* const keywords = pdfDoc.getKeywords()
|
||||
* ```
|
||||
* @returns A string containing the keywords of this document, if it has any.
|
||||
*/
|
||||
getKeywords(): string | undefined;
|
||||
/**
|
||||
* Get this document's creator metadata. The creator appears in the
|
||||
* "Document Properties" section of most PDF readers. For example:
|
||||
* ```js
|
||||
* const creator = pdfDoc.getCreator()
|
||||
* ```
|
||||
* @returns A string containing the creator of this document, if it has one.
|
||||
*/
|
||||
getCreator(): string | undefined;
|
||||
/**
|
||||
* Get this document's producer metadata. The producer appears in the
|
||||
* "Document Properties" section of most PDF readers. For example:
|
||||
* ```js
|
||||
* const producer = pdfDoc.getProducer()
|
||||
* ```
|
||||
* @returns A string containing the producer of this document, if it has one.
|
||||
*/
|
||||
getProducer(): string | undefined;
|
||||
/**
|
||||
* Get this document's creation date metadata. The creation date appears in
|
||||
* the "Document Properties" section of most PDF readers. For example:
|
||||
* ```js
|
||||
* const creationDate = pdfDoc.getCreationDate()
|
||||
* ```
|
||||
* @returns A Date containing the creation date of this document,
|
||||
* if it has one.
|
||||
*/
|
||||
getCreationDate(): Date | undefined;
|
||||
/**
|
||||
* Get this document's modification date metadata. The modification date
|
||||
* appears in the "Document Properties" section of most PDF readers.
|
||||
* For example:
|
||||
* ```js
|
||||
* const modification = pdfDoc.getModificationDate()
|
||||
* ```
|
||||
* @returns A Date containing the modification date of this document,
|
||||
* if it has one.
|
||||
*/
|
||||
getModificationDate(): Date | undefined;
|
||||
/**
|
||||
* Set this document's title metadata. The title will appear in the
|
||||
* "Document Properties" section of most PDF readers. For example:
|
||||
* ```js
|
||||
* pdfDoc.setTitle('🥚 The Life of an Egg 🍳')
|
||||
* ```
|
||||
*
|
||||
* To display the title in the window's title bar, set the
|
||||
* `showInWindowTitleBar` option to `true` (works for _most_ PDF readers).
|
||||
* For example:
|
||||
* ```js
|
||||
* pdfDoc.setTitle('🥚 The Life of an Egg 🍳', { showInWindowTitleBar: true })
|
||||
* ```
|
||||
*
|
||||
* @param title The title of this document.
|
||||
* @param options The options to be used when setting the title.
|
||||
*/
|
||||
setTitle(title: string, options?: SetTitleOptions): void;
|
||||
/**
|
||||
* Set this document's author metadata. The author will appear in the
|
||||
* "Document Properties" section of most PDF readers. For example:
|
||||
* ```js
|
||||
* pdfDoc.setAuthor('Humpty Dumpty')
|
||||
* ```
|
||||
* @param author The author of this document.
|
||||
*/
|
||||
setAuthor(author: string): void;
|
||||
/**
|
||||
* Set this document's subject metadata. The subject will appear in the
|
||||
* "Document Properties" section of most PDF readers. For example:
|
||||
* ```js
|
||||
* pdfDoc.setSubject('📘 An Epic Tale of Woe 📖')
|
||||
* ```
|
||||
* @param subject The subject of this document.
|
||||
*/
|
||||
setSubject(subject: string): void;
|
||||
/**
|
||||
* Set this document's keyword metadata. These keywords will appear in the
|
||||
* "Document Properties" section of most PDF readers. For example:
|
||||
* ```js
|
||||
* pdfDoc.setKeywords(['eggs', 'wall', 'fall', 'king', 'horses', 'men'])
|
||||
* ```
|
||||
* @param keywords An array of keywords associated with this document.
|
||||
*/
|
||||
setKeywords(keywords: string[]): void;
|
||||
/**
|
||||
* Set this document's creator metadata. The creator will appear in the
|
||||
* "Document Properties" section of most PDF readers. For example:
|
||||
* ```js
|
||||
* pdfDoc.setCreator('PDF App 9000 🤖')
|
||||
* ```
|
||||
* @param creator The creator of this document.
|
||||
*/
|
||||
setCreator(creator: string): void;
|
||||
/**
|
||||
* Set this document's producer metadata. The producer will appear in the
|
||||
* "Document Properties" section of most PDF readers. For example:
|
||||
* ```js
|
||||
* pdfDoc.setProducer('PDF App 9000 🤖')
|
||||
* ```
|
||||
* @param producer The producer of this document.
|
||||
*/
|
||||
setProducer(producer: string): void;
|
||||
/**
|
||||
* Set this document's language metadata. The language will appear in the
|
||||
* "Document Properties" section of some PDF readers. For example:
|
||||
* ```js
|
||||
* pdfDoc.setLanguage('en-us')
|
||||
* ```
|
||||
*
|
||||
* @param language An RFC 3066 _Language-Tag_ denoting the language of this
|
||||
* document, or an empty string if the language is unknown.
|
||||
*/
|
||||
setLanguage(language: string): void;
|
||||
/**
|
||||
* Set this document's creation date metadata. The creation date will appear
|
||||
* in the "Document Properties" section of most PDF readers. For example:
|
||||
* ```js
|
||||
* pdfDoc.setCreationDate(new Date())
|
||||
* ```
|
||||
* @param creationDate The date this document was created.
|
||||
*/
|
||||
setCreationDate(creationDate: Date): void;
|
||||
/**
|
||||
* Set this document's modification date metadata. The modification date will
|
||||
* appear in the "Document Properties" section of most PDF readers. For
|
||||
* example:
|
||||
* ```js
|
||||
* pdfDoc.setModificationDate(new Date())
|
||||
* ```
|
||||
* @param modificationDate The date this document was last modified.
|
||||
*/
|
||||
setModificationDate(modificationDate: Date): void;
|
||||
/**
|
||||
* Get the number of pages contained in this document. For example:
|
||||
* ```js
|
||||
* const totalPages = pdfDoc.getPageCount()
|
||||
* ```
|
||||
* @returns The number of pages in this document.
|
||||
*/
|
||||
getPageCount(): number;
|
||||
/**
|
||||
* Get an array of all the pages contained in this document. The pages are
|
||||
* stored in the array in the same order that they are rendered in the
|
||||
* document. For example:
|
||||
* ```js
|
||||
* const pages = pdfDoc.getPages()
|
||||
* pages[0] // The first page of the document
|
||||
* pages[2] // The third page of the document
|
||||
* pages[197] // The 198th page of the document
|
||||
* ```
|
||||
* @returns An array of all the pages contained in this document.
|
||||
*/
|
||||
getPages(): PDFPage[];
|
||||
/**
|
||||
* Get the page rendered at a particular `index` of the document. For example:
|
||||
* ```js
|
||||
* pdfDoc.getPage(0) // The first page of the document
|
||||
* pdfDoc.getPage(2) // The third page of the document
|
||||
* pdfDoc.getPage(197) // The 198th page of the document
|
||||
* ```
|
||||
* @returns The [[PDFPage]] rendered at the given `index` of the document.
|
||||
*/
|
||||
getPage(index: number): PDFPage;
|
||||
/**
|
||||
* Get an array of indices for all the pages contained in this document. The
|
||||
* array will contain a range of integers from
|
||||
* `0..pdfDoc.getPageCount() - 1`. For example:
|
||||
* ```js
|
||||
* const pdfDoc = await PDFDocument.create()
|
||||
* pdfDoc.addPage()
|
||||
* pdfDoc.addPage()
|
||||
* pdfDoc.addPage()
|
||||
*
|
||||
* const indices = pdfDoc.getPageIndices()
|
||||
* indices // => [0, 1, 2]
|
||||
* ```
|
||||
* @returns An array of indices for all pages contained in this document.
|
||||
*/
|
||||
getPageIndices(): number[];
|
||||
/**
|
||||
* Remove the page at a given index from this document. For example:
|
||||
* ```js
|
||||
* pdfDoc.removePage(0) // Remove the first page of the document
|
||||
* pdfDoc.removePage(2) // Remove the third page of the document
|
||||
* pdfDoc.removePage(197) // Remove the 198th page of the document
|
||||
* ```
|
||||
* Once a page has been removed, it will no longer be rendered at that index
|
||||
* in the document.
|
||||
* @param index The index of the page to be removed.
|
||||
*/
|
||||
removePage(index: number): void;
|
||||
/**
|
||||
* Add a page to the end of this document. This method accepts three
|
||||
* different value types for the `page` parameter:
|
||||
*
|
||||
* | Type | Behavior |
|
||||
* | ------------------ | ----------------------------------------------------------------------------------- |
|
||||
* | `undefined` | Create a new page and add it to the end of this document |
|
||||
* | `[number, number]` | Create a new page with the given dimensions and add it to the end of this document |
|
||||
* | `PDFPage` | Add the existing page to the end of this document |
|
||||
*
|
||||
* For example:
|
||||
* ```js
|
||||
* // page=undefined
|
||||
* const newPage = pdfDoc.addPage()
|
||||
*
|
||||
* // page=[number, number]
|
||||
* import { PageSizes } from 'pdf-lib'
|
||||
* const newPage1 = pdfDoc.addPage(PageSizes.A7)
|
||||
* const newPage2 = pdfDoc.addPage(PageSizes.Letter)
|
||||
* const newPage3 = pdfDoc.addPage([500, 750])
|
||||
*
|
||||
* // page=PDFPage
|
||||
* const pdfDoc1 = await PDFDocument.create()
|
||||
* const pdfDoc2 = await PDFDocument.load(...)
|
||||
* const [existingPage] = await pdfDoc1.copyPages(pdfDoc2, [0])
|
||||
* pdfDoc1.addPage(existingPage)
|
||||
* ```
|
||||
*
|
||||
* @param page Optionally, the desired dimensions or existing page.
|
||||
* @returns The newly created (or existing) page.
|
||||
*/
|
||||
addPage(page?: PDFPage | [number, number]): PDFPage;
|
||||
/**
|
||||
* Insert a page at a given index within this document. This method accepts
|
||||
* three different value types for the `page` parameter:
|
||||
*
|
||||
* | Type | Behavior |
|
||||
* | ------------------ | ------------------------------------------------------------------------------ |
|
||||
* | `undefined` | Create a new page and insert it into this document |
|
||||
* | `[number, number]` | Create a new page with the given dimensions and insert it into this document |
|
||||
* | `PDFPage` | Insert the existing page into this document |
|
||||
*
|
||||
* For example:
|
||||
* ```js
|
||||
* // page=undefined
|
||||
* const newPage = pdfDoc.insertPage(2)
|
||||
*
|
||||
* // page=[number, number]
|
||||
* import { PageSizes } from 'pdf-lib'
|
||||
* const newPage1 = pdfDoc.insertPage(2, PageSizes.A7)
|
||||
* const newPage2 = pdfDoc.insertPage(0, PageSizes.Letter)
|
||||
* const newPage3 = pdfDoc.insertPage(198, [500, 750])
|
||||
*
|
||||
* // page=PDFPage
|
||||
* const pdfDoc1 = await PDFDocument.create()
|
||||
* const pdfDoc2 = await PDFDocument.load(...)
|
||||
* const [existingPage] = await pdfDoc1.copyPages(pdfDoc2, [0])
|
||||
* pdfDoc1.insertPage(0, existingPage)
|
||||
* ```
|
||||
*
|
||||
* @param index The index at which the page should be inserted (zero-based).
|
||||
* @param page Optionally, the desired dimensions or existing page.
|
||||
* @returns The newly created (or existing) page.
|
||||
*/
|
||||
insertPage(index: number, page?: PDFPage | [number, number]): PDFPage;
|
||||
/**
|
||||
* Copy pages from a source document into this document. Allows pages to be
|
||||
* copied between different [[PDFDocument]] instances. For example:
|
||||
* ```js
|
||||
* const pdfDoc = await PDFDocument.create()
|
||||
* const srcDoc = await PDFDocument.load(...)
|
||||
*
|
||||
* const copiedPages = await pdfDoc.copyPages(srcDoc, [0, 3, 89])
|
||||
* const [firstPage, fourthPage, ninetiethPage] = copiedPages;
|
||||
*
|
||||
* pdfDoc.addPage(fourthPage)
|
||||
* pdfDoc.insertPage(0, ninetiethPage)
|
||||
* pdfDoc.addPage(firstPage)
|
||||
* ```
|
||||
* @param srcDoc The document from which pages should be copied.
|
||||
* @param indices The indices of the pages that should be copied.
|
||||
* @returns Resolves with an array of pages copied into this document.
|
||||
*/
|
||||
copyPages(srcDoc: PDFDocument, indices: number[]): Promise<PDFPage[]>;
|
||||
/**
|
||||
* Get a copy of this document.
|
||||
*
|
||||
* For example:
|
||||
* ```js
|
||||
* const srcDoc = await PDFDocument.load(...)
|
||||
* const pdfDoc = await srcDoc.copy()
|
||||
* ```
|
||||
*
|
||||
* > **NOTE:** This method won't copy all information over to the new
|
||||
* > document (acroforms, outlines, etc...).
|
||||
*
|
||||
* @returns Resolves with a copy this document.
|
||||
*/
|
||||
copy(): Promise<PDFDocument>;
|
||||
/**
|
||||
* Add JavaScript to this document. The supplied `script` is executed when the
|
||||
* document is opened. The `script` can be used to perform some operation
|
||||
* when the document is opened (e.g. logging to the console), or it can be
|
||||
* used to define a function that can be referenced later in a JavaScript
|
||||
* action. For example:
|
||||
* ```js
|
||||
* // Show "Hello World!" in the console when the PDF is opened
|
||||
* pdfDoc.addJavaScript(
|
||||
* 'main',
|
||||
* 'console.show(); console.println("Hello World!");'
|
||||
* );
|
||||
*
|
||||
* // Define a function named "foo" that can be called in JavaScript Actions
|
||||
* pdfDoc.addJavaScript(
|
||||
* 'foo',
|
||||
* 'function foo() { return "foo"; }'
|
||||
* );
|
||||
* ```
|
||||
* See the [JavaScript for Acrobat API Reference](https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/js_api_reference.pdf)
|
||||
* for details.
|
||||
* @param name The name of the script. Must be unique per document.
|
||||
* @param script The JavaScript to execute.
|
||||
*/
|
||||
addJavaScript(name: string, script: string): void;
|
||||
/**
|
||||
* Add an attachment to this document. Attachments are visible in the
|
||||
* "Attachments" panel of Adobe Acrobat and some other PDF readers. Any
|
||||
* type of file can be added as an attachment. This includes, but is not
|
||||
* limited to, `.png`, `.jpg`, `.pdf`, `.csv`, `.docx`, and `.xlsx` files.
|
||||
*
|
||||
* The input data can be provided in multiple formats:
|
||||
*
|
||||
* | Type | Contents |
|
||||
* | ------------- | -------------------------------------------------------------- |
|
||||
* | `string` | A base64 encoded string (or data URI) containing an attachment |
|
||||
* | `Uint8Array` | The raw bytes of an attachment |
|
||||
* | `ArrayBuffer` | The raw bytes of an attachment |
|
||||
*
|
||||
* For example:
|
||||
* ```js
|
||||
* // attachment=string
|
||||
* await pdfDoc.attach('/9j/4AAQSkZJRgABAQAAAQABAAD/2wBD...', 'cat_riding_unicorn.jpg', {
|
||||
* mimeType: 'image/jpeg',
|
||||
* description: 'Cool cat riding a unicorn! 🦄🐈🕶️',
|
||||
* creationDate: new Date('2019/12/01'),
|
||||
* modificationDate: new Date('2020/04/19'),
|
||||
* })
|
||||
* await pdfDoc.attach('data:image/jpeg;base64,/9j/4AAQ...', 'cat_riding_unicorn.jpg', {
|
||||
* mimeType: 'image/jpeg',
|
||||
* description: 'Cool cat riding a unicorn! 🦄🐈🕶️',
|
||||
* creationDate: new Date('2019/12/01'),
|
||||
* modificationDate: new Date('2020/04/19'),
|
||||
* })
|
||||
*
|
||||
* // attachment=Uint8Array
|
||||
* import fs from 'fs'
|
||||
* const uint8Array = fs.readFileSync('cat_riding_unicorn.jpg')
|
||||
* await pdfDoc.attach(uint8Array, 'cat_riding_unicorn.jpg', {
|
||||
* mimeType: 'image/jpeg',
|
||||
* description: 'Cool cat riding a unicorn! 🦄🐈🕶️',
|
||||
* creationDate: new Date('2019/12/01'),
|
||||
* modificationDate: new Date('2020/04/19'),
|
||||
* })
|
||||
*
|
||||
* // attachment=ArrayBuffer
|
||||
* const url = 'https://pdf-lib.js.org/assets/cat_riding_unicorn.jpg'
|
||||
* const arrayBuffer = await fetch(url).then(res => res.arrayBuffer())
|
||||
* await pdfDoc.attach(arrayBuffer, 'cat_riding_unicorn.jpg', {
|
||||
* mimeType: 'image/jpeg',
|
||||
* description: 'Cool cat riding a unicorn! 🦄🐈🕶️',
|
||||
* creationDate: new Date('2019/12/01'),
|
||||
* modificationDate: new Date('2020/04/19'),
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
* @param attachment The input data containing the file to be attached.
|
||||
* @param name The name of the file to be attached.
|
||||
* @returns Resolves when the attachment is complete.
|
||||
*/
|
||||
attach(attachment: string | Uint8Array | ArrayBuffer, name: string, options?: AttachmentOptions): Promise<void>;
|
||||
/**
|
||||
* Embed a font into this document. The input data can be provided in multiple
|
||||
* formats:
|
||||
*
|
||||
* | Type | Contents |
|
||||
* | --------------- | ------------------------------------------------------- |
|
||||
* | `StandardFonts` | One of the standard 14 fonts |
|
||||
* | `string` | A base64 encoded string (or data URI) containing a font |
|
||||
* | `Uint8Array` | The raw bytes of a font |
|
||||
* | `ArrayBuffer` | The raw bytes of a font |
|
||||
*
|
||||
* For example:
|
||||
* ```js
|
||||
* // font=StandardFonts
|
||||
* import { StandardFonts } from 'pdf-lib'
|
||||
* const font1 = await pdfDoc.embedFont(StandardFonts.Helvetica)
|
||||
*
|
||||
* // font=string
|
||||
* const font2 = await pdfDoc.embedFont('AAEAAAAVAQAABABQRFNJRx/upe...')
|
||||
* const font3 = await pdfDoc.embedFont('data:font/opentype;base64,AAEAAA...')
|
||||
*
|
||||
* // font=Uint8Array
|
||||
* import fs from 'fs'
|
||||
* const font4 = await pdfDoc.embedFont(fs.readFileSync('Ubuntu-R.ttf'))
|
||||
*
|
||||
* // font=ArrayBuffer
|
||||
* const url = 'https://pdf-lib.js.org/assets/ubuntu/Ubuntu-R.ttf'
|
||||
* const ubuntuBytes = await fetch(url).then(res => res.arrayBuffer())
|
||||
* const font5 = await pdfDoc.embedFont(ubuntuBytes)
|
||||
* ```
|
||||
* See also: [[registerFontkit]]
|
||||
* @param font The input data for a font.
|
||||
* @param options The options to be used when embedding the font.
|
||||
* @returns Resolves with the embedded font.
|
||||
*/
|
||||
embedFont(font: StandardFonts | string | Uint8Array | ArrayBuffer, options?: EmbedFontOptions): Promise<PDFFont>;
|
||||
/**
|
||||
* Embed a standard font into this document.
|
||||
* For example:
|
||||
* ```js
|
||||
* import { StandardFonts } from 'pdf-lib'
|
||||
* const helveticaFont = pdfDoc.embedFont(StandardFonts.Helvetica)
|
||||
* ```
|
||||
* @param font The standard font to be embedded.
|
||||
* @param customName The name to be used when embedding the font.
|
||||
* @returns The embedded font.
|
||||
*/
|
||||
embedStandardFont(font: StandardFonts, customName?: string): PDFFont;
|
||||
/**
|
||||
* Embed a JPEG image into this document. The input data can be provided in
|
||||
* multiple formats:
|
||||
*
|
||||
* | Type | Contents |
|
||||
* | ------------- | ------------------------------------------------------------- |
|
||||
* | `string` | A base64 encoded string (or data URI) containing a JPEG image |
|
||||
* | `Uint8Array` | The raw bytes of a JPEG image |
|
||||
* | `ArrayBuffer` | The raw bytes of a JPEG image |
|
||||
*
|
||||
* For example:
|
||||
* ```js
|
||||
* // jpg=string
|
||||
* const image1 = await pdfDoc.embedJpg('/9j/4AAQSkZJRgABAQAAAQABAAD/2wBD...')
|
||||
* const image2 = await pdfDoc.embedJpg('data:image/jpeg;base64,/9j/4AAQ...')
|
||||
*
|
||||
* // jpg=Uint8Array
|
||||
* import fs from 'fs'
|
||||
* const uint8Array = fs.readFileSync('cat_riding_unicorn.jpg')
|
||||
* const image3 = await pdfDoc.embedJpg(uint8Array)
|
||||
*
|
||||
* // jpg=ArrayBuffer
|
||||
* const url = 'https://pdf-lib.js.org/assets/cat_riding_unicorn.jpg'
|
||||
* const arrayBuffer = await fetch(url).then(res => res.arrayBuffer())
|
||||
* const image4 = await pdfDoc.embedJpg(arrayBuffer)
|
||||
* ```
|
||||
*
|
||||
* @param jpg The input data for a JPEG image.
|
||||
* @returns Resolves with the embedded image.
|
||||
*/
|
||||
embedJpg(jpg: string | Uint8Array | ArrayBuffer): Promise<PDFImage>;
|
||||
/**
|
||||
* Embed a PNG image into this document. The input data can be provided in
|
||||
* multiple formats:
|
||||
*
|
||||
* | Type | Contents |
|
||||
* | ------------- | ------------------------------------------------------------ |
|
||||
* | `string` | A base64 encoded string (or data URI) containing a PNG image |
|
||||
* | `Uint8Array` | The raw bytes of a PNG image |
|
||||
* | `ArrayBuffer` | The raw bytes of a PNG image |
|
||||
*
|
||||
* For example:
|
||||
* ```js
|
||||
* // png=string
|
||||
* const image1 = await pdfDoc.embedPng('iVBORw0KGgoAAAANSUhEUgAAAlgAAAF3...')
|
||||
* const image2 = await pdfDoc.embedPng('data:image/png;base64,iVBORw0KGg...')
|
||||
*
|
||||
* // png=Uint8Array
|
||||
* import fs from 'fs'
|
||||
* const uint8Array = fs.readFileSync('small_mario.png')
|
||||
* const image3 = await pdfDoc.embedPng(uint8Array)
|
||||
*
|
||||
* // png=ArrayBuffer
|
||||
* const url = 'https://pdf-lib.js.org/assets/small_mario.png'
|
||||
* const arrayBuffer = await fetch(url).then(res => res.arrayBuffer())
|
||||
* const image4 = await pdfDoc.embedPng(arrayBuffer)
|
||||
* ```
|
||||
*
|
||||
* @param png The input data for a PNG image.
|
||||
* @returns Resolves with the embedded image.
|
||||
*/
|
||||
embedPng(png: string | Uint8Array | ArrayBuffer): Promise<PDFImage>;
|
||||
/**
|
||||
* Embed one or more PDF pages into this document.
|
||||
*
|
||||
* For example:
|
||||
* ```js
|
||||
* const pdfDoc = await PDFDocument.create()
|
||||
*
|
||||
* const sourcePdfUrl = 'https://pdf-lib.js.org/assets/with_large_page_count.pdf'
|
||||
* const sourcePdf = await fetch(sourcePdfUrl).then((res) => res.arrayBuffer())
|
||||
*
|
||||
* // Embed page 74 of `sourcePdf` into `pdfDoc`
|
||||
* const [embeddedPage] = await pdfDoc.embedPdf(sourcePdf, [73])
|
||||
* ```
|
||||
*
|
||||
* See [[PDFDocument.load]] for examples of the allowed input data formats.
|
||||
*
|
||||
* @param pdf The input data containing a PDF document.
|
||||
* @param indices The indices of the pages that should be embedded.
|
||||
* @returns Resolves with an array of the embedded pages.
|
||||
*/
|
||||
embedPdf(pdf: string | Uint8Array | ArrayBuffer | PDFDocument, indices?: number[]): Promise<PDFEmbeddedPage[]>;
|
||||
/**
|
||||
* Embed a single PDF page into this document.
|
||||
*
|
||||
* For example:
|
||||
* ```js
|
||||
* const pdfDoc = await PDFDocument.create()
|
||||
*
|
||||
* const sourcePdfUrl = 'https://pdf-lib.js.org/assets/with_large_page_count.pdf'
|
||||
* const sourceBuffer = await fetch(sourcePdfUrl).then((res) => res.arrayBuffer())
|
||||
* const sourcePdfDoc = await PDFDocument.load(sourceBuffer)
|
||||
* const sourcePdfPage = sourcePdfDoc.getPages()[73]
|
||||
*
|
||||
* const embeddedPage = await pdfDoc.embedPage(
|
||||
* sourcePdfPage,
|
||||
*
|
||||
* // Clip a section of the source page so that we only embed part of it
|
||||
* { left: 100, right: 450, bottom: 330, top: 570 },
|
||||
*
|
||||
* // Translate all drawings of the embedded page by (10, 200) units
|
||||
* [1, 0, 0, 1, 10, 200],
|
||||
* )
|
||||
* ```
|
||||
*
|
||||
* @param page The page to be embedded.
|
||||
* @param boundingBox
|
||||
* Optionally, an area of the source page that should be embedded
|
||||
* (defaults to entire page).
|
||||
* @param transformationMatrix
|
||||
* Optionally, a transformation matrix that is always applied to the embedded
|
||||
* page anywhere it is drawn.
|
||||
* @returns Resolves with the embedded pdf page.
|
||||
*/
|
||||
embedPage(page: PDFPage, boundingBox?: PageBoundingBox, transformationMatrix?: TransformationMatrix): Promise<PDFEmbeddedPage>;
|
||||
/**
|
||||
* Embed one or more PDF pages into this document.
|
||||
*
|
||||
* For example:
|
||||
* ```js
|
||||
* const pdfDoc = await PDFDocument.create()
|
||||
*
|
||||
* const sourcePdfUrl = 'https://pdf-lib.js.org/assets/with_large_page_count.pdf'
|
||||
* const sourceBuffer = await fetch(sourcePdfUrl).then((res) => res.arrayBuffer())
|
||||
* const sourcePdfDoc = await PDFDocument.load(sourceBuffer)
|
||||
*
|
||||
* const page1 = sourcePdfDoc.getPages()[0]
|
||||
* const page2 = sourcePdfDoc.getPages()[52]
|
||||
* const page3 = sourcePdfDoc.getPages()[73]
|
||||
*
|
||||
* const embeddedPages = await pdfDoc.embedPages([page1, page2, page3])
|
||||
* ```
|
||||
*
|
||||
* @param page
|
||||
* The pages to be embedded (they must all share the same context).
|
||||
* @param boundingBoxes
|
||||
* Optionally, an array of clipping boundaries - one for each page
|
||||
* (defaults to entirety of each page).
|
||||
* @param transformationMatrices
|
||||
* Optionally, an array of transformation matrices - one for each page
|
||||
* (each page's transformation will apply anywhere it is drawn).
|
||||
* @returns Resolves with an array of the embedded pdf pages.
|
||||
*/
|
||||
embedPages(pages: PDFPage[], boundingBoxes?: (PageBoundingBox | undefined)[], transformationMatrices?: (TransformationMatrix | undefined)[]): Promise<PDFEmbeddedPage[]>;
|
||||
/**
|
||||
* > **NOTE:** You shouldn't need to call this method directly. The [[save]]
|
||||
* > and [[saveAsBase64]] methods will automatically ensure that all embedded
|
||||
* > assets are flushed before serializing the document.
|
||||
*
|
||||
* Flush all embedded fonts, PDF pages, and images to this document's
|
||||
* [[context]].
|
||||
*
|
||||
* @returns Resolves when the flush is complete.
|
||||
*/
|
||||
flush(): Promise<void>;
|
||||
/**
|
||||
* Serialize this document to an array of bytes making up a PDF file.
|
||||
* For example:
|
||||
* ```js
|
||||
* const pdfBytes = await pdfDoc.save()
|
||||
* ```
|
||||
*
|
||||
* There are a number of things you can do with the serialized document,
|
||||
* depending on the JavaScript environment you're running in:
|
||||
* * Write it to a file in Node or React Native
|
||||
* * Download it as a Blob in the browser
|
||||
* * Render it in an `iframe`
|
||||
*
|
||||
* @param options The options to be used when saving the document.
|
||||
* @returns Resolves with the bytes of the serialized document.
|
||||
*/
|
||||
save(options?: SaveOptions): Promise<Uint8Array>;
|
||||
/**
|
||||
* Serialize this document to a base64 encoded string or data URI making up a
|
||||
* PDF file. For example:
|
||||
* ```js
|
||||
* const base64String = await pdfDoc.saveAsBase64()
|
||||
* base64String // => 'JVBERi0xLjcKJYGBgYEKC...'
|
||||
*
|
||||
* const base64DataUri = await pdfDoc.saveAsBase64({ dataUri: true })
|
||||
* base64DataUri // => 'data:application/pdf;base64,JVBERi0xLjcKJYGBgYEKC...'
|
||||
* ```
|
||||
*
|
||||
* @param options The options to be used when saving the document.
|
||||
* @returns Resolves with a base64 encoded string or data URI of the
|
||||
* serialized document.
|
||||
*/
|
||||
saveAsBase64(options?: Base64SaveOptions): Promise<string>;
|
||||
findPageForAnnotationRef(ref: PDFRef): PDFPage | undefined;
|
||||
private embedAll;
|
||||
private updateInfoDict;
|
||||
private getInfoDict;
|
||||
private assertFontkit;
|
||||
private computePages;
|
||||
private getOrCreateForm;
|
||||
}
|
||||
//# sourceMappingURL=PDFDocument.d.ts.map
|
||||
1
node_modules/pdf-lib/cjs/api/PDFDocument.d.ts.map
generated
vendored
Normal file
1
node_modules/pdf-lib/cjs/api/PDFDocument.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"PDFDocument.d.ts","sourceRoot":"","sources":["../../src/api/PDFDocument.ts"],"names":[],"mappings":"AAOA,OAAO,eAAe,0BAAgC;AACtD,OAAO,OAAO,kBAAwB;AACtC,OAAO,QAAQ,mBAAyB;AACxC,OAAO,OAAO,kBAAwB;AACtC,OAAO,OAAO,uBAA6B;AAE3C,OAAO,EAAE,aAAa,EAAE,wBAA8B;AACtD,OAAO,EAIL,eAAe,EAEf,UAAU,EACV,UAAU,EAeX,gBAAiB;AAClB,OAAO,EAEL,iBAAiB,EACjB,WAAW,EACX,iBAAiB,EACjB,WAAW,E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AO,CAAC,cAAc;IAatB,OAAO,CAAC,WAAW;IAUnB,OAAO,CAAC,aAAa;IAKrB,OAAO,CAAC,YAAY,CAalB;IAEF,OAAO,CAAC,eAAe,CAGrB;CACH"}
|
||||
1369
node_modules/pdf-lib/cjs/api/PDFDocument.js
generated
vendored
Normal file
1369
node_modules/pdf-lib/cjs/api/PDFDocument.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1
node_modules/pdf-lib/cjs/api/PDFDocument.js.map
generated
vendored
Normal file
1
node_modules/pdf-lib/cjs/api/PDFDocument.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
38
node_modules/pdf-lib/cjs/api/PDFDocumentOptions.d.ts
generated
vendored
Normal file
38
node_modules/pdf-lib/cjs/api/PDFDocumentOptions.d.ts
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
import { EmbeddedFileOptions } from "../core/embedders/FileEmbedder";
|
||||
import { TypeFeatures } from "../types/fontkit";
|
||||
export declare enum ParseSpeeds {
|
||||
Fastest = Infinity,
|
||||
Fast = 1500,
|
||||
Medium = 500,
|
||||
Slow = 100
|
||||
}
|
||||
export interface AttachmentOptions extends EmbeddedFileOptions {
|
||||
}
|
||||
export interface SaveOptions {
|
||||
useObjectStreams?: boolean;
|
||||
addDefaultPage?: boolean;
|
||||
objectsPerTick?: number;
|
||||
updateFieldAppearances?: boolean;
|
||||
}
|
||||
export interface Base64SaveOptions extends SaveOptions {
|
||||
dataUri?: boolean;
|
||||
}
|
||||
export interface LoadOptions {
|
||||
ignoreEncryption?: boolean;
|
||||
parseSpeed?: ParseSpeeds | number;
|
||||
throwOnInvalidObject?: boolean;
|
||||
updateMetadata?: boolean;
|
||||
capNumbers?: boolean;
|
||||
}
|
||||
export interface CreateOptions {
|
||||
updateMetadata?: boolean;
|
||||
}
|
||||
export interface EmbedFontOptions {
|
||||
subset?: boolean;
|
||||
customName?: string;
|
||||
features?: TypeFeatures;
|
||||
}
|
||||
export interface SetTitleOptions {
|
||||
showInWindowTitleBar: boolean;
|
||||
}
|
||||
//# sourceMappingURL=PDFDocumentOptions.d.ts.map
|
||||
1
node_modules/pdf-lib/cjs/api/PDFDocumentOptions.d.ts.map
generated
vendored
Normal file
1
node_modules/pdf-lib/cjs/api/PDFDocumentOptions.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"PDFDocumentOptions.d.ts","sourceRoot":"","sources":["../../src/api/PDFDocumentOptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,uCAAwC;AACtE,OAAO,EAAE,YAAY,EAAE,yBAA0B;AAEjD,oBAAY,WAAW;IACrB,OAAO,WAAW;IAClB,IAAI,OAAO;IACX,MAAM,MAAM;IACZ,IAAI,MAAM;CACX;AAED,MAAM,WAAW,iBAAkB,SAAQ,mBAAmB;CAAG;AAEjE,MAAM,WAAW,WAAW;IAC1B,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,sBAAsB,CAAC,EAAE,OAAO,CAAC;CAClC;AAED,MAAM,WAAW,iBAAkB,SAAQ,WAAW;IACpD,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,WAAW;IAC1B,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,UAAU,CAAC,EAAE,WAAW,GAAG,MAAM,CAAC;IAClC,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,MAAM,WAAW,aAAa;IAC5B,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,gBAAgB;IAC/B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,YAAY,CAAC;CACzB;AAED,MAAM,WAAW,eAAe;IAC9B,oBAAoB,EAAE,OAAO,CAAC;CAC/B"}
|
||||
11
node_modules/pdf-lib/cjs/api/PDFDocumentOptions.js
generated
vendored
Normal file
11
node_modules/pdf-lib/cjs/api/PDFDocumentOptions.js
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ParseSpeeds = void 0;
|
||||
var ParseSpeeds;
|
||||
(function (ParseSpeeds) {
|
||||
ParseSpeeds[ParseSpeeds["Fastest"] = Infinity] = "Fastest";
|
||||
ParseSpeeds[ParseSpeeds["Fast"] = 1500] = "Fast";
|
||||
ParseSpeeds[ParseSpeeds["Medium"] = 500] = "Medium";
|
||||
ParseSpeeds[ParseSpeeds["Slow"] = 100] = "Slow";
|
||||
})(ParseSpeeds = exports.ParseSpeeds || (exports.ParseSpeeds = {}));
|
||||
//# sourceMappingURL=PDFDocumentOptions.js.map
|
||||
1
node_modules/pdf-lib/cjs/api/PDFDocumentOptions.js.map
generated
vendored
Normal file
1
node_modules/pdf-lib/cjs/api/PDFDocumentOptions.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"PDFDocumentOptions.js","sourceRoot":"","sources":["../../src/api/PDFDocumentOptions.ts"],"names":[],"mappings":";;;AAGA,IAAY,WAKX;AALD,WAAY,WAAW;IACrB,0DAAkB,CAAA;IAClB,gDAAW,CAAA;IACX,mDAAY,CAAA;IACZ,+CAAU,CAAA;AACZ,CAAC,EALW,WAAW,GAAX,mBAAW,KAAX,mBAAW,QAKtB"}
|
||||
39
node_modules/pdf-lib/cjs/api/PDFEmbeddedFile.d.ts
generated
vendored
Normal file
39
node_modules/pdf-lib/cjs/api/PDFEmbeddedFile.d.ts
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
import Embeddable from "./Embeddable";
|
||||
import PDFDocument from "./PDFDocument";
|
||||
import FileEmbedder from "../core/embedders/FileEmbedder";
|
||||
import { PDFRef } from "../core";
|
||||
/**
|
||||
* Represents a file that has been embedded in a [[PDFDocument]].
|
||||
*/
|
||||
export default class PDFEmbeddedFile implements Embeddable {
|
||||
/**
|
||||
* > **NOTE:** You probably don't want to call this method directly. Instead,
|
||||
* > consider using the [[PDFDocument.attach]] method, which will create
|
||||
* instances of [[PDFEmbeddedFile]] for you.
|
||||
*
|
||||
* Create an instance of [[PDFEmbeddedFile]] from an existing ref and embedder
|
||||
*
|
||||
* @param ref The unique reference for this file.
|
||||
* @param doc The document to which the file will belong.
|
||||
* @param embedder The embedder that will be used to embed the file.
|
||||
*/
|
||||
static of: (ref: PDFRef, doc: PDFDocument, embedder: FileEmbedder) => PDFEmbeddedFile;
|
||||
/** The unique reference assigned to this embedded file within the document. */
|
||||
readonly ref: PDFRef;
|
||||
/** The document to which this embedded file belongs. */
|
||||
readonly doc: PDFDocument;
|
||||
private alreadyEmbedded;
|
||||
private readonly embedder;
|
||||
private constructor();
|
||||
/**
|
||||
* > **NOTE:** You probably don't need to call this method directly. The
|
||||
* > [[PDFDocument.save]] and [[PDFDocument.saveAsBase64]] methods will
|
||||
* > automatically ensure all embeddable files get embedded.
|
||||
*
|
||||
* Embed this embeddable file in its document.
|
||||
*
|
||||
* @returns Resolves when the embedding is complete.
|
||||
*/
|
||||
embed(): Promise<void>;
|
||||
}
|
||||
//# sourceMappingURL=PDFEmbeddedFile.d.ts.map
|
||||
1
node_modules/pdf-lib/cjs/api/PDFEmbeddedFile.d.ts.map
generated
vendored
Normal file
1
node_modules/pdf-lib/cjs/api/PDFEmbeddedFile.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"PDFEmbeddedFile.d.ts","sourceRoot":"","sources":["../../src/api/PDFEmbeddedFile.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,qBAA2B;AAC5C,OAAO,WAAW,sBAA4B;AAC9C,OAAO,YAAY,uCAAwC;AAC3D,OAAO,EAA4C,MAAM,EAAE,gBAAiB;AAE5E;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,eAAgB,YAAW,UAAU;IACxD;;;;;;;;;;OAUG;IACH,MAAM,CAAC,EAAE,QAAS,MAAM,OAAO,WAAW,YAAY,YAAY,qBACxB;IAE1C,+EAA+E;IAC/E,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IAErB,wDAAwD;IACxD,QAAQ,CAAC,GAAG,EAAE,WAAW,CAAC;IAE1B,OAAO,CAAC,eAAe,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAe;IAExC,OAAO;IAMP;;;;;;;;OAQG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CA0C7B"}
|
||||
84
node_modules/pdf-lib/cjs/api/PDFEmbeddedFile.js
generated
vendored
Normal file
84
node_modules/pdf-lib/cjs/api/PDFEmbeddedFile.js
generated
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var tslib_1 = require("tslib");
|
||||
var core_1 = require("../core");
|
||||
/**
|
||||
* Represents a file that has been embedded in a [[PDFDocument]].
|
||||
*/
|
||||
var PDFEmbeddedFile = /** @class */ (function () {
|
||||
function PDFEmbeddedFile(ref, doc, embedder) {
|
||||
this.alreadyEmbedded = false;
|
||||
this.ref = ref;
|
||||
this.doc = doc;
|
||||
this.embedder = embedder;
|
||||
}
|
||||
/**
|
||||
* > **NOTE:** You probably don't need to call this method directly. The
|
||||
* > [[PDFDocument.save]] and [[PDFDocument.saveAsBase64]] methods will
|
||||
* > automatically ensure all embeddable files get embedded.
|
||||
*
|
||||
* Embed this embeddable file in its document.
|
||||
*
|
||||
* @returns Resolves when the embedding is complete.
|
||||
*/
|
||||
PDFEmbeddedFile.prototype.embed = function () {
|
||||
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
||||
var ref, Names, EmbeddedFiles, EFNames, AF;
|
||||
return tslib_1.__generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
if (!!this.alreadyEmbedded) return [3 /*break*/, 2];
|
||||
return [4 /*yield*/, this.embedder.embedIntoContext(this.doc.context, this.ref)];
|
||||
case 1:
|
||||
ref = _a.sent();
|
||||
if (!this.doc.catalog.has(core_1.PDFName.of('Names'))) {
|
||||
this.doc.catalog.set(core_1.PDFName.of('Names'), this.doc.context.obj({}));
|
||||
}
|
||||
Names = this.doc.catalog.lookup(core_1.PDFName.of('Names'), core_1.PDFDict);
|
||||
if (!Names.has(core_1.PDFName.of('EmbeddedFiles'))) {
|
||||
Names.set(core_1.PDFName.of('EmbeddedFiles'), this.doc.context.obj({}));
|
||||
}
|
||||
EmbeddedFiles = Names.lookup(core_1.PDFName.of('EmbeddedFiles'), core_1.PDFDict);
|
||||
if (!EmbeddedFiles.has(core_1.PDFName.of('Names'))) {
|
||||
EmbeddedFiles.set(core_1.PDFName.of('Names'), this.doc.context.obj([]));
|
||||
}
|
||||
EFNames = EmbeddedFiles.lookup(core_1.PDFName.of('Names'), core_1.PDFArray);
|
||||
EFNames.push(core_1.PDFHexString.fromText(this.embedder.fileName));
|
||||
EFNames.push(ref);
|
||||
/**
|
||||
* The AF-Tag is needed to achieve PDF-A3 compliance for embedded files
|
||||
*
|
||||
* The following document outlines the uses cases of the associated files (AF) tag.
|
||||
* See:
|
||||
* https://www.pdfa.org/wp-content/uploads/2018/10/PDF20_AN002-AF.pdf
|
||||
*/
|
||||
if (!this.doc.catalog.has(core_1.PDFName.of('AF'))) {
|
||||
this.doc.catalog.set(core_1.PDFName.of('AF'), this.doc.context.obj([]));
|
||||
}
|
||||
AF = this.doc.catalog.lookup(core_1.PDFName.of('AF'), core_1.PDFArray);
|
||||
AF.push(ref);
|
||||
this.alreadyEmbedded = true;
|
||||
_a.label = 2;
|
||||
case 2: return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
/**
|
||||
* > **NOTE:** You probably don't want to call this method directly. Instead,
|
||||
* > consider using the [[PDFDocument.attach]] method, which will create
|
||||
* instances of [[PDFEmbeddedFile]] for you.
|
||||
*
|
||||
* Create an instance of [[PDFEmbeddedFile]] from an existing ref and embedder
|
||||
*
|
||||
* @param ref The unique reference for this file.
|
||||
* @param doc The document to which the file will belong.
|
||||
* @param embedder The embedder that will be used to embed the file.
|
||||
*/
|
||||
PDFEmbeddedFile.of = function (ref, doc, embedder) {
|
||||
return new PDFEmbeddedFile(ref, doc, embedder);
|
||||
};
|
||||
return PDFEmbeddedFile;
|
||||
}());
|
||||
exports.default = PDFEmbeddedFile;
|
||||
//# sourceMappingURL=PDFEmbeddedFile.js.map
|
||||
1
node_modules/pdf-lib/cjs/api/PDFEmbeddedFile.js.map
generated
vendored
Normal file
1
node_modules/pdf-lib/cjs/api/PDFEmbeddedFile.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"PDFEmbeddedFile.js","sourceRoot":"","sources":["../../src/api/PDFEmbeddedFile.ts"],"names":[],"mappings":";;;AAGA,gCAA4E;AAE5E;;GAEG;AACH;IAwBE,yBAAoB,GAAW,EAAE,GAAgB,EAAE,QAAsB;QAHjE,oBAAe,GAAG,KAAK,CAAC;QAI9B,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED;;;;;;;;OAQG;IACG,+BAAK,GAAX;;;;;;6BACM,CAAC,IAAI,CAAC,eAAe,EAArB,wBAAqB;wBACX,qBAAM,IAAI,CAAC,QAAQ,CAAC,gBAAgB,CAC9C,IAAI,CAAC,GAAG,CAAC,OAAO,EAChB,IAAI,CAAC,GAAG,CACT,EAAA;;wBAHK,GAAG,GAAG,SAGX;wBAED,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,cAAO,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,EAAE;4BAC9C,IAAI,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AAC,cAAO,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,EAAE;4BAC3C,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,cAAO,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;yBAClE;wBACK,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,cAAO,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,eAAQ,CAAC,CAAC;wBAC/D,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;wBAEb,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC;;;;;;KAE/B;IA/ED;;;;;;;;;;OAUG;IACI,kBAAE,GAAG,UAAC,GAAW,EAAE,GAAgB,EAAE,QAAsB;QAChE,OAAA,IAAI,eAAe,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,CAAC;IAAvC,CAAuC,CAAC;IAoE5C,sBAAC;CAAA,AAjFD,IAiFC;kBAjFoB,eAAe"}
|
||||
74
node_modules/pdf-lib/cjs/api/PDFEmbeddedPage.d.ts
generated
vendored
Normal file
74
node_modules/pdf-lib/cjs/api/PDFEmbeddedPage.d.ts
generated
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
import Embeddable from "./Embeddable";
|
||||
import PDFDocument from "./PDFDocument";
|
||||
import { PDFPageEmbedder, PDFRef } from "../core";
|
||||
/**
|
||||
* Represents a PDF page that has been embedded in a [[PDFDocument]].
|
||||
*/
|
||||
export default class PDFEmbeddedPage implements Embeddable {
|
||||
/**
|
||||
* > **NOTE:** You probably don't want to call this method directly. Instead,
|
||||
* > consider using the [[PDFDocument.embedPdf]] and
|
||||
* > [[PDFDocument.embedPage]] methods, which will create instances of
|
||||
* > [[PDFEmbeddedPage]] for you.
|
||||
*
|
||||
* Create an instance of [[PDFEmbeddedPage]] from an existing ref and embedder
|
||||
*
|
||||
* @param ref The unique reference for this embedded page.
|
||||
* @param doc The document to which the embedded page will belong.
|
||||
* @param embedder The embedder that will be used to embed the page.
|
||||
*/
|
||||
static of: (ref: PDFRef, doc: PDFDocument, embedder: PDFPageEmbedder) => PDFEmbeddedPage;
|
||||
/** The unique reference assigned to this embedded page within the document. */
|
||||
readonly ref: PDFRef;
|
||||
/** The document to which this embedded page belongs. */
|
||||
readonly doc: PDFDocument;
|
||||
/** The width of this page in pixels. */
|
||||
readonly width: number;
|
||||
/** The height of this page in pixels. */
|
||||
readonly height: number;
|
||||
private alreadyEmbedded;
|
||||
private readonly embedder;
|
||||
private constructor();
|
||||
/**
|
||||
* Compute the width and height of this page after being scaled by the
|
||||
* given `factor`. For example:
|
||||
* ```js
|
||||
* embeddedPage.width // => 500
|
||||
* embeddedPage.height // => 250
|
||||
*
|
||||
* const scaled = embeddedPage.scale(0.5)
|
||||
* scaled.width // => 250
|
||||
* scaled.height // => 125
|
||||
* ```
|
||||
* This operation is often useful before drawing a page with
|
||||
* [[PDFPage.drawPage]] to compute the `width` and `height` options.
|
||||
* @param factor The factor by which this page should be scaled.
|
||||
* @returns The width and height of the page after being scaled.
|
||||
*/
|
||||
scale(factor: number): {
|
||||
width: number;
|
||||
height: number;
|
||||
};
|
||||
/**
|
||||
* Get the width and height of this page. For example:
|
||||
* ```js
|
||||
* const { width, height } = embeddedPage.size()
|
||||
* ```
|
||||
* @returns The width and height of the page.
|
||||
*/
|
||||
size(): {
|
||||
width: number;
|
||||
height: number;
|
||||
};
|
||||
/**
|
||||
* > **NOTE:** You probably don't need to call this method directly. The
|
||||
* > [[PDFDocument.save]] and [[PDFDocument.saveAsBase64]] methods will
|
||||
* > automatically ensure all embeddable pages get embedded.
|
||||
*
|
||||
* Embed this embeddable page in its document.
|
||||
*
|
||||
* @returns Resolves when the embedding is complete.
|
||||
*/
|
||||
embed(): Promise<void>;
|
||||
}
|
||||
//# sourceMappingURL=PDFEmbeddedPage.d.ts.map
|
||||
1
node_modules/pdf-lib/cjs/api/PDFEmbeddedPage.d.ts.map
generated
vendored
Normal file
1
node_modules/pdf-lib/cjs/api/PDFEmbeddedPage.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"PDFEmbeddedPage.d.ts","sourceRoot":"","sources":["../../src/api/PDFEmbeddedPage.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,qBAA2B;AAC5C,OAAO,WAAW,sBAA4B;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,gBAAiB;AAGnD;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,eAAgB,YAAW,UAAU;IACxD;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,EAAE,QAAS,MAAM,OAAO,WAAW,YAAY,eAAe,qBAC3B;IAE1C,+EAA+E;IAC/E,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IAErB,wDAAwD;IACxD,QAAQ,CAAC,GAAG,EAAE,WAAW,CAAC;IAE1B,wCAAwC;IACxC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAEvB,yCAAyC;IACzC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB,OAAO,CAAC,eAAe,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAkB;IAE3C,OAAO;IAiBP;;;;;;;;;;;;;;;OAeG;IACH,KAAK,CAAC,MAAM,EAAE,MAAM;;;;IAKpB;;;;;;OAMG;IACH,IAAI;;;;IAIJ;;;;;;;;OAQG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAM7B"}
|
||||
95
node_modules/pdf-lib/cjs/api/PDFEmbeddedPage.js
generated
vendored
Normal file
95
node_modules/pdf-lib/cjs/api/PDFEmbeddedPage.js
generated
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var tslib_1 = require("tslib");
|
||||
var PDFDocument_1 = tslib_1.__importDefault(require("./PDFDocument"));
|
||||
var core_1 = require("../core");
|
||||
var utils_1 = require("../utils");
|
||||
/**
|
||||
* Represents a PDF page that has been embedded in a [[PDFDocument]].
|
||||
*/
|
||||
var PDFEmbeddedPage = /** @class */ (function () {
|
||||
function PDFEmbeddedPage(ref, doc, embedder) {
|
||||
this.alreadyEmbedded = false;
|
||||
utils_1.assertIs(ref, 'ref', [[core_1.PDFRef, 'PDFRef']]);
|
||||
utils_1.assertIs(doc, 'doc', [[PDFDocument_1.default, 'PDFDocument']]);
|
||||
utils_1.assertIs(embedder, 'embedder', [[core_1.PDFPageEmbedder, 'PDFPageEmbedder']]);
|
||||
this.ref = ref;
|
||||
this.doc = doc;
|
||||
this.width = embedder.width;
|
||||
this.height = embedder.height;
|
||||
this.embedder = embedder;
|
||||
}
|
||||
/**
|
||||
* Compute the width and height of this page after being scaled by the
|
||||
* given `factor`. For example:
|
||||
* ```js
|
||||
* embeddedPage.width // => 500
|
||||
* embeddedPage.height // => 250
|
||||
*
|
||||
* const scaled = embeddedPage.scale(0.5)
|
||||
* scaled.width // => 250
|
||||
* scaled.height // => 125
|
||||
* ```
|
||||
* This operation is often useful before drawing a page with
|
||||
* [[PDFPage.drawPage]] to compute the `width` and `height` options.
|
||||
* @param factor The factor by which this page should be scaled.
|
||||
* @returns The width and height of the page after being scaled.
|
||||
*/
|
||||
PDFEmbeddedPage.prototype.scale = function (factor) {
|
||||
utils_1.assertIs(factor, 'factor', ['number']);
|
||||
return { width: this.width * factor, height: this.height * factor };
|
||||
};
|
||||
/**
|
||||
* Get the width and height of this page. For example:
|
||||
* ```js
|
||||
* const { width, height } = embeddedPage.size()
|
||||
* ```
|
||||
* @returns The width and height of the page.
|
||||
*/
|
||||
PDFEmbeddedPage.prototype.size = function () {
|
||||
return this.scale(1);
|
||||
};
|
||||
/**
|
||||
* > **NOTE:** You probably don't need to call this method directly. The
|
||||
* > [[PDFDocument.save]] and [[PDFDocument.saveAsBase64]] methods will
|
||||
* > automatically ensure all embeddable pages get embedded.
|
||||
*
|
||||
* Embed this embeddable page in its document.
|
||||
*
|
||||
* @returns Resolves when the embedding is complete.
|
||||
*/
|
||||
PDFEmbeddedPage.prototype.embed = function () {
|
||||
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
||||
return tslib_1.__generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
if (!!this.alreadyEmbedded) return [3 /*break*/, 2];
|
||||
return [4 /*yield*/, this.embedder.embedIntoContext(this.doc.context, this.ref)];
|
||||
case 1:
|
||||
_a.sent();
|
||||
this.alreadyEmbedded = true;
|
||||
_a.label = 2;
|
||||
case 2: return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
/**
|
||||
* > **NOTE:** You probably don't want to call this method directly. Instead,
|
||||
* > consider using the [[PDFDocument.embedPdf]] and
|
||||
* > [[PDFDocument.embedPage]] methods, which will create instances of
|
||||
* > [[PDFEmbeddedPage]] for you.
|
||||
*
|
||||
* Create an instance of [[PDFEmbeddedPage]] from an existing ref and embedder
|
||||
*
|
||||
* @param ref The unique reference for this embedded page.
|
||||
* @param doc The document to which the embedded page will belong.
|
||||
* @param embedder The embedder that will be used to embed the page.
|
||||
*/
|
||||
PDFEmbeddedPage.of = function (ref, doc, embedder) {
|
||||
return new PDFEmbeddedPage(ref, doc, embedder);
|
||||
};
|
||||
return PDFEmbeddedPage;
|
||||
}());
|
||||
exports.default = PDFEmbeddedPage;
|
||||
//# sourceMappingURL=PDFEmbeddedPage.js.map
|
||||
1
node_modules/pdf-lib/cjs/api/PDFEmbeddedPage.js.map
generated
vendored
Normal file
1
node_modules/pdf-lib/cjs/api/PDFEmbeddedPage.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"PDFEmbeddedPage.js","sourceRoot":"","sources":["../../src/api/PDFEmbeddedPage.ts"],"names":[],"mappings":";;;AACA,sEAA8C;AAC9C,gCAAmD;AACnD,kCAAqC;AAErC;;GAEG;AACH;IA+BE,yB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IAAI,CAAC,eAAe,GAAG,IAAI,CAAC;;;;;;KAE/B;IA7FD;;;;;;;;;;;OAWG;IACI,kBAAE,GAAG,UAAC,GAAW,EAAE,GAAgB,EAAE,QAAyB;QACnE,OAAA,IAAI,eAAe,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,CAAC;IAAvC,CAAuC,CAAC;IAiF5C,sBAAC;CAAA,AA/FD,IA+FC;kBA/FoB,eAAe"}
|
||||
95
node_modules/pdf-lib/cjs/api/PDFFont.d.ts
generated
vendored
Normal file
95
node_modules/pdf-lib/cjs/api/PDFFont.d.ts
generated
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
import Embeddable from "./Embeddable";
|
||||
import PDFDocument from "./PDFDocument";
|
||||
import { CustomFontEmbedder, PDFHexString, PDFRef, StandardFontEmbedder } from "../core";
|
||||
export declare type FontEmbedder = CustomFontEmbedder | StandardFontEmbedder;
|
||||
/**
|
||||
* Represents a font that has been embedded in a [[PDFDocument]].
|
||||
*/
|
||||
export default class PDFFont implements Embeddable {
|
||||
/**
|
||||
* > **NOTE:** You probably don't want to call this method directly. Instead,
|
||||
* > consider using the [[PDFDocument.embedFont]] and
|
||||
* > [[PDFDocument.embedStandardFont]] methods, which will create instances
|
||||
* > of [[PDFFont]] for you.
|
||||
*
|
||||
* Create an instance of [[PDFFont]] from an existing ref and embedder
|
||||
*
|
||||
* @param ref The unique reference for this font.
|
||||
* @param doc The document to which the font will belong.
|
||||
* @param embedder The embedder that will be used to embed the font.
|
||||
*/
|
||||
static of: (ref: PDFRef, doc: PDFDocument, embedder: FontEmbedder) => PDFFont;
|
||||
/** The unique reference assigned to this font within the document. */
|
||||
readonly ref: PDFRef;
|
||||
/** The document to which this font belongs. */
|
||||
readonly doc: PDFDocument;
|
||||
/** The name of this font. */
|
||||
readonly name: string;
|
||||
private modified;
|
||||
private readonly embedder;
|
||||
private constructor();
|
||||
/**
|
||||
* > **NOTE:** You probably don't need to call this method directly. The
|
||||
* > [[PDFPage.drawText]] method will automatically encode the text it is
|
||||
* > given.
|
||||
*
|
||||
* Encodes a string of text in this font.
|
||||
*
|
||||
* @param text The text to be encoded.
|
||||
* @returns The encoded text as a hex string.
|
||||
*/
|
||||
encodeText(text: string): PDFHexString;
|
||||
/**
|
||||
* Measure the width of a string of text drawn in this font at a given size.
|
||||
* For example:
|
||||
* ```js
|
||||
* const width = font.widthOfTextAtSize('Foo Bar Qux Baz', 36)
|
||||
* ```
|
||||
* @param text The string of text to be measured.
|
||||
* @param size The font size to be used for this measurement.
|
||||
* @returns The width of the string of text when drawn in this font at the
|
||||
* given size.
|
||||
*/
|
||||
widthOfTextAtSize(text: string, size: number): number;
|
||||
/**
|
||||
* Measure the height of this font at a given size. For example:
|
||||
* ```js
|
||||
* const height = font.heightAtSize(24)
|
||||
* ```
|
||||
*
|
||||
* The `options.descender` value controls whether or not the font's
|
||||
* descender is included in the height calculation.
|
||||
*
|
||||
* @param size The font size to be used for this measurement.
|
||||
* @param options The options to be used when computing this measurement.
|
||||
* @returns The height of this font at the given size.
|
||||
*/
|
||||
heightAtSize(size: number, options?: {
|
||||
descender?: boolean;
|
||||
}): number;
|
||||
/**
|
||||
* Compute the font size at which this font is a given height. For example:
|
||||
* ```js
|
||||
* const fontSize = font.sizeAtHeight(12)
|
||||
* ```
|
||||
* @param height The height to be used for this calculation.
|
||||
* @returns The font size at which this font is the given height.
|
||||
*/
|
||||
sizeAtHeight(height: number): number;
|
||||
/**
|
||||
* Get the set of unicode code points that can be represented by this font.
|
||||
* @returns The set of unicode code points supported by this font.
|
||||
*/
|
||||
getCharacterSet(): number[];
|
||||
/**
|
||||
* > **NOTE:** You probably don't need to call this method directly. The
|
||||
* > [[PDFDocument.save]] and [[PDFDocument.saveAsBase64]] methods will
|
||||
* > automatically ensure all fonts get embedded.
|
||||
*
|
||||
* Embed this font in its document.
|
||||
*
|
||||
* @returns Resolves when the embedding is complete.
|
||||
*/
|
||||
embed(): Promise<void>;
|
||||
}
|
||||
//# sourceMappingURL=PDFFont.d.ts.map
|
||||
1
node_modules/pdf-lib/cjs/api/PDFFont.d.ts.map
generated
vendored
Normal file
1
node_modules/pdf-lib/cjs/api/PDFFont.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"PDFFont.d.ts","sourceRoot":"","sources":["../../src/api/PDFFont.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,qBAA4B;AAC7C,OAAO,WAAW,sBAA4B;AAC9C,OAAO,EACL,kBAAkB,EAClB,YAAY,EACZ,MAAM,EACN,oBAAoB,EACrB,gBAAiB;AAGlB,oBAAY,YAAY,GAAG,kBAAkB,GAAG,oBAAoB,CAAC;AAErE;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,OAAQ,YAAW,UAAU;IAChD;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,EAAE,QAAS,MAAM,OAAO,WAAW,YAAY,YAAY,aAChC;IAElC,sEAAsE;IACtE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IAErB,+CAA+C;IAC/C,QAAQ,CAAC,GAAG,EAAE,WAAW,CAAC;IAE1B,6BAA6B;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,OAAO,CAAC,QAAQ,CAAQ;IACxB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAe;IAExC,OAAO;IAeP;;;;;;;;;OASG;IACH,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY;IAMtC;;;;;;;;;;OAUG;IACH,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM;IAMrD;;;;;;;;;;;;OAYG;IACH,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,MAAM;IAQrE;;;;;;;OAOG;IACH,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;IAKpC;;;OAGG;IACH,eAAe,IAAI,MAAM,EAAE;IAQ3B;;;;;;;;OAQG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAO7B"}
|
||||
143
node_modules/pdf-lib/cjs/api/PDFFont.js
generated
vendored
Normal file
143
node_modules/pdf-lib/cjs/api/PDFFont.js
generated
vendored
Normal file
@@ -0,0 +1,143 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var tslib_1 = require("tslib");
|
||||
var PDFDocument_1 = tslib_1.__importDefault(require("./PDFDocument"));
|
||||
var core_1 = require("../core");
|
||||
var utils_1 = require("../utils");
|
||||
/**
|
||||
* Represents a font that has been embedded in a [[PDFDocument]].
|
||||
*/
|
||||
var PDFFont = /** @class */ (function () {
|
||||
function PDFFont(ref, doc, embedder) {
|
||||
this.modified = true;
|
||||
utils_1.assertIs(ref, 'ref', [[core_1.PDFRef, 'PDFRef']]);
|
||||
utils_1.assertIs(doc, 'doc', [[PDFDocument_1.default, 'PDFDocument']]);
|
||||
utils_1.assertIs(embedder, 'embedder', [
|
||||
[core_1.CustomFontEmbedder, 'CustomFontEmbedder'],
|
||||
[core_1.StandardFontEmbedder, 'StandardFontEmbedder'],
|
||||
]);
|
||||
this.ref = ref;
|
||||
this.doc = doc;
|
||||
this.name = embedder.fontName;
|
||||
this.embedder = embedder;
|
||||
}
|
||||
/**
|
||||
* > **NOTE:** You probably don't need to call this method directly. The
|
||||
* > [[PDFPage.drawText]] method will automatically encode the text it is
|
||||
* > given.
|
||||
*
|
||||
* Encodes a string of text in this font.
|
||||
*
|
||||
* @param text The text to be encoded.
|
||||
* @returns The encoded text as a hex string.
|
||||
*/
|
||||
PDFFont.prototype.encodeText = function (text) {
|
||||
utils_1.assertIs(text, 'text', ['string']);
|
||||
this.modified = true;
|
||||
return this.embedder.encodeText(text);
|
||||
};
|
||||
/**
|
||||
* Measure the width of a string of text drawn in this font at a given size.
|
||||
* For example:
|
||||
* ```js
|
||||
* const width = font.widthOfTextAtSize('Foo Bar Qux Baz', 36)
|
||||
* ```
|
||||
* @param text The string of text to be measured.
|
||||
* @param size The font size to be used for this measurement.
|
||||
* @returns The width of the string of text when drawn in this font at the
|
||||
* given size.
|
||||
*/
|
||||
PDFFont.prototype.widthOfTextAtSize = function (text, size) {
|
||||
utils_1.assertIs(text, 'text', ['string']);
|
||||
utils_1.assertIs(size, 'size', ['number']);
|
||||
return this.embedder.widthOfTextAtSize(text, size);
|
||||
};
|
||||
/**
|
||||
* Measure the height of this font at a given size. For example:
|
||||
* ```js
|
||||
* const height = font.heightAtSize(24)
|
||||
* ```
|
||||
*
|
||||
* The `options.descender` value controls whether or not the font's
|
||||
* descender is included in the height calculation.
|
||||
*
|
||||
* @param size The font size to be used for this measurement.
|
||||
* @param options The options to be used when computing this measurement.
|
||||
* @returns The height of this font at the given size.
|
||||
*/
|
||||
PDFFont.prototype.heightAtSize = function (size, options) {
|
||||
var _a;
|
||||
utils_1.assertIs(size, 'size', ['number']);
|
||||
utils_1.assertOrUndefined(options === null || options === void 0 ? void 0 : options.descender, 'options.descender', ['boolean']);
|
||||
return this.embedder.heightOfFontAtSize(size, {
|
||||
descender: (_a = options === null || options === void 0 ? void 0 : options.descender) !== null && _a !== void 0 ? _a : true,
|
||||
});
|
||||
};
|
||||
/**
|
||||
* Compute the font size at which this font is a given height. For example:
|
||||
* ```js
|
||||
* const fontSize = font.sizeAtHeight(12)
|
||||
* ```
|
||||
* @param height The height to be used for this calculation.
|
||||
* @returns The font size at which this font is the given height.
|
||||
*/
|
||||
PDFFont.prototype.sizeAtHeight = function (height) {
|
||||
utils_1.assertIs(height, 'height', ['number']);
|
||||
return this.embedder.sizeOfFontAtHeight(height);
|
||||
};
|
||||
/**
|
||||
* Get the set of unicode code points that can be represented by this font.
|
||||
* @returns The set of unicode code points supported by this font.
|
||||
*/
|
||||
PDFFont.prototype.getCharacterSet = function () {
|
||||
if (this.embedder instanceof core_1.StandardFontEmbedder) {
|
||||
return this.embedder.encoding.supportedCodePoints;
|
||||
}
|
||||
else {
|
||||
return this.embedder.font.characterSet;
|
||||
}
|
||||
};
|
||||
/**
|
||||
* > **NOTE:** You probably don't need to call this method directly. The
|
||||
* > [[PDFDocument.save]] and [[PDFDocument.saveAsBase64]] methods will
|
||||
* > automatically ensure all fonts get embedded.
|
||||
*
|
||||
* Embed this font in its document.
|
||||
*
|
||||
* @returns Resolves when the embedding is complete.
|
||||
*/
|
||||
PDFFont.prototype.embed = function () {
|
||||
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
||||
return tslib_1.__generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
if (!this.modified) return [3 /*break*/, 2];
|
||||
return [4 /*yield*/, this.embedder.embedIntoContext(this.doc.context, this.ref)];
|
||||
case 1:
|
||||
_a.sent();
|
||||
this.modified = false;
|
||||
_a.label = 2;
|
||||
case 2: return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
/**
|
||||
* > **NOTE:** You probably don't want to call this method directly. Instead,
|
||||
* > consider using the [[PDFDocument.embedFont]] and
|
||||
* > [[PDFDocument.embedStandardFont]] methods, which will create instances
|
||||
* > of [[PDFFont]] for you.
|
||||
*
|
||||
* Create an instance of [[PDFFont]] from an existing ref and embedder
|
||||
*
|
||||
* @param ref The unique reference for this font.
|
||||
* @param doc The document to which the font will belong.
|
||||
* @param embedder The embedder that will be used to embed the font.
|
||||
*/
|
||||
PDFFont.of = function (ref, doc, embedder) {
|
||||
return new PDFFont(ref, doc, embedder);
|
||||
};
|
||||
return PDFFont;
|
||||
}());
|
||||
exports.default = PDFFont;
|
||||
//# sourceMappingURL=PDFFont.js.map
|
||||
1
node_modules/pdf-lib/cjs/api/PDFFont.js.map
generated
vendored
Normal file
1
node_modules/pdf-lib/cjs/api/PDFFont.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"PDFFont.js","sourceRoot":"","sources":["../../src/api/PDFFont.ts"],"names":[],"mappings":";;;AACA,sEAA8C;A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,QAAsB;QAChE,OAAA,IAAI,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,CAAC;IAA/B,CAA+B,CAAC;IA4HpC,cAAC;CAAA,AA1ID,IA0IC;kBA1IoB,OAAO"}
|
||||
96
node_modules/pdf-lib/cjs/api/PDFImage.d.ts
generated
vendored
Normal file
96
node_modules/pdf-lib/cjs/api/PDFImage.d.ts
generated
vendored
Normal file
@@ -0,0 +1,96 @@
|
||||
import Embeddable from "./Embeddable";
|
||||
import PDFDocument from "./PDFDocument";
|
||||
import { JpegEmbedder, PDFRef, PngEmbedder } from "../core";
|
||||
export declare type ImageEmbedder = JpegEmbedder | PngEmbedder;
|
||||
/**
|
||||
* Represents an image that has been embedded in a [[PDFDocument]].
|
||||
*/
|
||||
export default class PDFImage implements Embeddable {
|
||||
/**
|
||||
* > **NOTE:** You probably don't want to call this method directly. Instead,
|
||||
* > consider using the [[PDFDocument.embedPng]] and [[PDFDocument.embedJpg]]
|
||||
* > methods, which will create instances of [[PDFImage]] for you.
|
||||
*
|
||||
* Create an instance of [[PDFImage]] from an existing ref and embedder
|
||||
*
|
||||
* @param ref The unique reference for this image.
|
||||
* @param doc The document to which the image will belong.
|
||||
* @param embedder The embedder that will be used to embed the image.
|
||||
*/
|
||||
static of: (ref: PDFRef, doc: PDFDocument, embedder: ImageEmbedder) => PDFImage;
|
||||
/** The unique reference assigned to this image within the document. */
|
||||
readonly ref: PDFRef;
|
||||
/** The document to which this image belongs. */
|
||||
readonly doc: PDFDocument;
|
||||
/** The width of this image in pixels. */
|
||||
readonly width: number;
|
||||
/** The height of this image in pixels. */
|
||||
readonly height: number;
|
||||
private embedder;
|
||||
private embedTask;
|
||||
private constructor();
|
||||
/**
|
||||
* Compute the width and height of this image after being scaled by the
|
||||
* given `factor`. For example:
|
||||
* ```js
|
||||
* image.width // => 500
|
||||
* image.height // => 250
|
||||
*
|
||||
* const scaled = image.scale(0.5)
|
||||
* scaled.width // => 250
|
||||
* scaled.height // => 125
|
||||
* ```
|
||||
* This operation is often useful before drawing an image with
|
||||
* [[PDFPage.drawImage]] to compute the `width` and `height` options.
|
||||
* @param factor The factor by which this image should be scaled.
|
||||
* @returns The width and height of the image after being scaled.
|
||||
*/
|
||||
scale(factor: number): {
|
||||
width: number;
|
||||
height: number;
|
||||
};
|
||||
/**
|
||||
* Get the width and height of this image after scaling it as large as
|
||||
* possible while maintaining its aspect ratio and not exceeding the
|
||||
* specified `width` and `height`. For example:
|
||||
* ```
|
||||
* image.width // => 500
|
||||
* image.height // => 250
|
||||
*
|
||||
* const scaled = image.scaleToFit(750, 1000)
|
||||
* scaled.width // => 750
|
||||
* scaled.height // => 375
|
||||
* ```
|
||||
* The `width` and `height` parameters can also be thought of as the width
|
||||
* and height of a box that the scaled image must fit within.
|
||||
* @param width The bounding box's width.
|
||||
* @param height The bounding box's height.
|
||||
* @returns The width and height of the image after being scaled.
|
||||
*/
|
||||
scaleToFit(width: number, height: number): {
|
||||
width: number;
|
||||
height: number;
|
||||
};
|
||||
/**
|
||||
* Get the width and height of this image. For example:
|
||||
* ```js
|
||||
* const { width, height } = image.size()
|
||||
* ```
|
||||
* @returns The width and height of the image.
|
||||
*/
|
||||
size(): {
|
||||
width: number;
|
||||
height: number;
|
||||
};
|
||||
/**
|
||||
* > **NOTE:** You probably don't need to call this method directly. The
|
||||
* > [[PDFDocument.save]] and [[PDFDocument.saveAsBase64]] methods will
|
||||
* > automatically ensure all images get embedded.
|
||||
*
|
||||
* Embed this image in its document.
|
||||
*
|
||||
* @returns Resolves when the embedding is complete.
|
||||
*/
|
||||
embed(): Promise<void>;
|
||||
}
|
||||
//# sourceMappingURL=PDFImage.d.ts.map
|
||||
1
node_modules/pdf-lib/cjs/api/PDFImage.d.ts.map
generated
vendored
Normal file
1
node_modules/pdf-lib/cjs/api/PDFImage.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"PDFImage.d.ts","sourceRoot":"","sources":["../../src/api/PDFImage.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,qBAA2B;AAC5C,OAAO,WAAW,sBAA4B;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,WAAW,EAAE,gBAAiB;AAG7D,oBAAY,aAAa,GAAG,YAAY,GAAG,WAAW,CAAC;AAEvD;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,QAAS,YAAW,UAAU;IACjD;;;;;;;;;;OAUG;IACH,MAAM,CAAC,EAAE,QAAS,MAAM,OAAO,WAAW,YAAY,aAAa,cAChC;IAEnC,uEAAuE;IACvE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IAErB,gDAAgD;IAChD,QAAQ,CAAC,GAAG,EAAE,WAAW,CAAC;IAE1B,yCAAyC;IACzC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAEvB,0CAA0C;IAC1C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB,OAAO,CAAC,QAAQ,CAA4B;IAC5C,OAAO,CAAC,SAAS,CAA8B;IAE/C,OAAO;IAgBP;;;;;;;;;;;;;;;OAeG;IACH,KAAK,CAAC,MAAM,EAAE,MAAM;;;;IAKpB;;;;;;;;;;;;;;;;;OAiBG;IACH,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;;;;IAWxC;;;;;;OAMG;IACH,IAAI;;;;IAIJ;;;;;;;;OAQG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAgB7B"}
|
||||
132
node_modules/pdf-lib/cjs/api/PDFImage.js
generated
vendored
Normal file
132
node_modules/pdf-lib/cjs/api/PDFImage.js
generated
vendored
Normal file
@@ -0,0 +1,132 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var tslib_1 = require("tslib");
|
||||
var PDFDocument_1 = tslib_1.__importDefault(require("./PDFDocument"));
|
||||
var core_1 = require("../core");
|
||||
var utils_1 = require("../utils");
|
||||
/**
|
||||
* Represents an image that has been embedded in a [[PDFDocument]].
|
||||
*/
|
||||
var PDFImage = /** @class */ (function () {
|
||||
function PDFImage(ref, doc, embedder) {
|
||||
utils_1.assertIs(ref, 'ref', [[core_1.PDFRef, 'PDFRef']]);
|
||||
utils_1.assertIs(doc, 'doc', [[PDFDocument_1.default, 'PDFDocument']]);
|
||||
utils_1.assertIs(embedder, 'embedder', [
|
||||
[core_1.JpegEmbedder, 'JpegEmbedder'],
|
||||
[core_1.PngEmbedder, 'PngEmbedder'],
|
||||
]);
|
||||
this.ref = ref;
|
||||
this.doc = doc;
|
||||
this.width = embedder.width;
|
||||
this.height = embedder.height;
|
||||
this.embedder = embedder;
|
||||
}
|
||||
/**
|
||||
* Compute the width and height of this image after being scaled by the
|
||||
* given `factor`. For example:
|
||||
* ```js
|
||||
* image.width // => 500
|
||||
* image.height // => 250
|
||||
*
|
||||
* const scaled = image.scale(0.5)
|
||||
* scaled.width // => 250
|
||||
* scaled.height // => 125
|
||||
* ```
|
||||
* This operation is often useful before drawing an image with
|
||||
* [[PDFPage.drawImage]] to compute the `width` and `height` options.
|
||||
* @param factor The factor by which this image should be scaled.
|
||||
* @returns The width and height of the image after being scaled.
|
||||
*/
|
||||
PDFImage.prototype.scale = function (factor) {
|
||||
utils_1.assertIs(factor, 'factor', ['number']);
|
||||
return { width: this.width * factor, height: this.height * factor };
|
||||
};
|
||||
/**
|
||||
* Get the width and height of this image after scaling it as large as
|
||||
* possible while maintaining its aspect ratio and not exceeding the
|
||||
* specified `width` and `height`. For example:
|
||||
* ```
|
||||
* image.width // => 500
|
||||
* image.height // => 250
|
||||
*
|
||||
* const scaled = image.scaleToFit(750, 1000)
|
||||
* scaled.width // => 750
|
||||
* scaled.height // => 375
|
||||
* ```
|
||||
* The `width` and `height` parameters can also be thought of as the width
|
||||
* and height of a box that the scaled image must fit within.
|
||||
* @param width The bounding box's width.
|
||||
* @param height The bounding box's height.
|
||||
* @returns The width and height of the image after being scaled.
|
||||
*/
|
||||
PDFImage.prototype.scaleToFit = function (width, height) {
|
||||
utils_1.assertIs(width, 'width', ['number']);
|
||||
utils_1.assertIs(height, 'height', ['number']);
|
||||
var imgWidthScale = width / this.width;
|
||||
var imgHeightScale = height / this.height;
|
||||
var scale = Math.min(imgWidthScale, imgHeightScale);
|
||||
return this.scale(scale);
|
||||
};
|
||||
/**
|
||||
* Get the width and height of this image. For example:
|
||||
* ```js
|
||||
* const { width, height } = image.size()
|
||||
* ```
|
||||
* @returns The width and height of the image.
|
||||
*/
|
||||
PDFImage.prototype.size = function () {
|
||||
return this.scale(1);
|
||||
};
|
||||
/**
|
||||
* > **NOTE:** You probably don't need to call this method directly. The
|
||||
* > [[PDFDocument.save]] and [[PDFDocument.saveAsBase64]] methods will
|
||||
* > automatically ensure all images get embedded.
|
||||
*
|
||||
* Embed this image in its document.
|
||||
*
|
||||
* @returns Resolves when the embedding is complete.
|
||||
*/
|
||||
PDFImage.prototype.embed = function () {
|
||||
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
||||
var _a, doc, ref;
|
||||
return tslib_1.__generator(this, function (_b) {
|
||||
switch (_b.label) {
|
||||
case 0:
|
||||
if (!this.embedder)
|
||||
return [2 /*return*/];
|
||||
// The image should only be embedded once. If there's a pending embed
|
||||
// operation then wait on it. Otherwise we need to start the embed.
|
||||
if (!this.embedTask) {
|
||||
_a = this, doc = _a.doc, ref = _a.ref;
|
||||
this.embedTask = this.embedder.embedIntoContext(doc.context, ref);
|
||||
}
|
||||
return [4 /*yield*/, this.embedTask];
|
||||
case 1:
|
||||
_b.sent();
|
||||
// We clear `this.embedder` so that the indirectly referenced image data
|
||||
// can be garbage collected, thus avoiding a memory leak.
|
||||
// See https://github.com/Hopding/pdf-lib/pull/1032/files.
|
||||
this.embedder = undefined;
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
/**
|
||||
* > **NOTE:** You probably don't want to call this method directly. Instead,
|
||||
* > consider using the [[PDFDocument.embedPng]] and [[PDFDocument.embedJpg]]
|
||||
* > methods, which will create instances of [[PDFImage]] for you.
|
||||
*
|
||||
* Create an instance of [[PDFImage]] from an existing ref and embedder
|
||||
*
|
||||
* @param ref The unique reference for this image.
|
||||
* @param doc The document to which the image will belong.
|
||||
* @param embedder The embedder that will be used to embed the image.
|
||||
*/
|
||||
PDFImage.of = function (ref, doc, embedder) {
|
||||
return new PDFImage(ref, doc, embedder);
|
||||
};
|
||||
return PDFImage;
|
||||
}());
|
||||
exports.default = PDFImage;
|
||||
//# sourceMappingURL=PDFImage.js.map
|
||||
1
node_modules/pdf-lib/cjs/api/PDFImage.js.map
generated
vendored
Normal file
1
node_modules/pdf-lib/cjs/api/PDFImage.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"PDFImage.js","sourceRoot":"","sources":["../../src/api/PDFImage.ts"],"names":[],"mappings":";;;AACA,sEAA8C;AAC9C,gCAA6D;AAC7D,kCAAqC;AAIrC;;GAEG;AACH;IA8BE,kBAAoB,GAAW,EAAE,GAAgB,EAAE,QAAuB;QACxE,gBAAQ,CAAC,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC,aAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;QAC3C,gBAAQ,CAAC,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC,qBAAW,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC;QACrD,gBAAQ,CAAC,QAAQ,EAAE,UAAU,EAAE;YAC7B,CAAC,mBAAY,EAAE,cAAc,CAAC;YAC9B,CAAC,kBAAW,EAAE,aAAa,CAAC;SAC7B,CAAC,CAAC;QAEH,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC;QAC5B,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC;QAE9B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CA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M,IAAI,CAAC,SAAS,EAAA;;wBAApB,SAAoB,CAAC;wBAErB,wEAAwE;wBACxE,yDAAyD;wBACzD,0DAA0D;wBAC1D,IAAI,CAAC,QAAQ,GAAG,SAAS,CAAC;;;;;KAC3B;IAlID;;;;;;;;;;OAUG;IACI,WAAE,GAAG,UAAC,GAAW,EAAE,GAAgB,EAAE,QAAuB;QACjE,OAAA,IAAI,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,CAAC;IAAhC,CAAgC,CAAC;IAuHrC,eAAC;CAAA,AApID,IAoIC;kBApIoB,QAAQ"}
|
||||
39
node_modules/pdf-lib/cjs/api/PDFJavaScript.d.ts
generated
vendored
Normal file
39
node_modules/pdf-lib/cjs/api/PDFJavaScript.d.ts
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
import Embeddable from "./Embeddable";
|
||||
import PDFDocument from "./PDFDocument";
|
||||
import JavaScriptEmbedder from "../core/embedders/JavaScriptEmbedder";
|
||||
import { PDFRef } from "../core";
|
||||
/**
|
||||
* Represents JavaScript that has been embedded in a [[PDFDocument]].
|
||||
*/
|
||||
export default class PDFJavaScript implements Embeddable {
|
||||
/**
|
||||
* > **NOTE:** You probably don't want to call this method directly. Instead,
|
||||
* > consider using the [[PDFDocument.addJavaScript]] method, which will
|
||||
* create instances of [[PDFJavaScript]] for you.
|
||||
*
|
||||
* Create an instance of [[PDFJavaScript]] from an existing ref and script
|
||||
*
|
||||
* @param ref The unique reference for this script.
|
||||
* @param doc The document to which the script will belong.
|
||||
* @param embedder The embedder that will be used to embed the script.
|
||||
*/
|
||||
static of: (ref: PDFRef, doc: PDFDocument, embedder: JavaScriptEmbedder) => PDFJavaScript;
|
||||
/** The unique reference assigned to this embedded script within the document. */
|
||||
readonly ref: PDFRef;
|
||||
/** The document to which this embedded script belongs. */
|
||||
readonly doc: PDFDocument;
|
||||
private alreadyEmbedded;
|
||||
private readonly embedder;
|
||||
private constructor();
|
||||
/**
|
||||
* > **NOTE:** You probably don't need to call this method directly. The
|
||||
* > [[PDFDocument.save]] and [[PDFDocument.saveAsBase64]] methods will
|
||||
* > automatically ensure all JavaScripts get embedded.
|
||||
*
|
||||
* Embed this JavaScript in its document.
|
||||
*
|
||||
* @returns Resolves when the embedding is complete.
|
||||
*/
|
||||
embed(): Promise<void>;
|
||||
}
|
||||
//# sourceMappingURL=PDFJavaScript.d.ts.map
|
||||
1
node_modules/pdf-lib/cjs/api/PDFJavaScript.d.ts.map
generated
vendored
Normal file
1
node_modules/pdf-lib/cjs/api/PDFJavaScript.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"PDFJavaScript.d.ts","sourceRoot":"","sources":["../../src/api/PDFJavaScript.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,qBAA2B;AAC5C,OAAO,WAAW,sBAA4B;AAC9C,OAAO,kBAAkB,6CAA8C;AACvE,OAAO,EAA4C,MAAM,EAAE,gBAAiB;AAE5E;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,aAAc,YAAW,UAAU;IACtD;;;;;;;;;;OAUG;IACH,MAAM,CAAC,EAAE,QAAS,MAAM,OAAO,WAAW,YAAY,kBAAkB,mBAChC;IAExC,iFAAiF;IACjF,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IAErB,0DAA0D;IAC1D,QAAQ,CAAC,GAAG,EAAE,WAAW,CAAC;IAE1B,OAAO,CAAC,eAAe,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAqB;IAE9C,OAAO;IAUP;;;;;;;;OAQG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CA8B7B"}
|
||||
73
node_modules/pdf-lib/cjs/api/PDFJavaScript.js
generated
vendored
Normal file
73
node_modules/pdf-lib/cjs/api/PDFJavaScript.js
generated
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var tslib_1 = require("tslib");
|
||||
var core_1 = require("../core");
|
||||
/**
|
||||
* Represents JavaScript that has been embedded in a [[PDFDocument]].
|
||||
*/
|
||||
var PDFJavaScript = /** @class */ (function () {
|
||||
function PDFJavaScript(ref, doc, embedder) {
|
||||
this.alreadyEmbedded = false;
|
||||
this.ref = ref;
|
||||
this.doc = doc;
|
||||
this.embedder = embedder;
|
||||
}
|
||||
/**
|
||||
* > **NOTE:** You probably don't need to call this method directly. The
|
||||
* > [[PDFDocument.save]] and [[PDFDocument.saveAsBase64]] methods will
|
||||
* > automatically ensure all JavaScripts get embedded.
|
||||
*
|
||||
* Embed this JavaScript in its document.
|
||||
*
|
||||
* @returns Resolves when the embedding is complete.
|
||||
*/
|
||||
PDFJavaScript.prototype.embed = function () {
|
||||
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
||||
var _a, catalog, context, ref, Names, Javascript, JSNames;
|
||||
return tslib_1.__generator(this, function (_b) {
|
||||
switch (_b.label) {
|
||||
case 0:
|
||||
if (!!this.alreadyEmbedded) return [3 /*break*/, 2];
|
||||
_a = this.doc, catalog = _a.catalog, context = _a.context;
|
||||
return [4 /*yield*/, this.embedder.embedIntoContext(this.doc.context, this.ref)];
|
||||
case 1:
|
||||
ref = _b.sent();
|
||||
if (!catalog.has(core_1.PDFName.of('Names'))) {
|
||||
catalog.set(core_1.PDFName.of('Names'), context.obj({}));
|
||||
}
|
||||
Names = catalog.lookup(core_1.PDFName.of('Names'), core_1.PDFDict);
|
||||
if (!Names.has(core_1.PDFName.of('JavaScript'))) {
|
||||
Names.set(core_1.PDFName.of('JavaScript'), context.obj({}));
|
||||
}
|
||||
Javascript = Names.lookup(core_1.PDFName.of('JavaScript'), core_1.PDFDict);
|
||||
if (!Javascript.has(core_1.PDFName.of('Names'))) {
|
||||
Javascript.set(core_1.PDFName.of('Names'), context.obj([]));
|
||||
}
|
||||
JSNames = Javascript.lookup(core_1.PDFName.of('Names'), core_1.PDFArray);
|
||||
JSNames.push(core_1.PDFHexString.fromText(this.embedder.scriptName));
|
||||
JSNames.push(ref);
|
||||
this.alreadyEmbedded = true;
|
||||
_b.label = 2;
|
||||
case 2: return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
/**
|
||||
* > **NOTE:** You probably don't want to call this method directly. Instead,
|
||||
* > consider using the [[PDFDocument.addJavaScript]] method, which will
|
||||
* create instances of [[PDFJavaScript]] for you.
|
||||
*
|
||||
* Create an instance of [[PDFJavaScript]] from an existing ref and script
|
||||
*
|
||||
* @param ref The unique reference for this script.
|
||||
* @param doc The document to which the script will belong.
|
||||
* @param embedder The embedder that will be used to embed the script.
|
||||
*/
|
||||
PDFJavaScript.of = function (ref, doc, embedder) {
|
||||
return new PDFJavaScript(ref, doc, embedder);
|
||||
};
|
||||
return PDFJavaScript;
|
||||
}());
|
||||
exports.default = PDFJavaScript;
|
||||
//# sourceMappingURL=PDFJavaScript.js.map
|
||||
1
node_modules/pdf-lib/cjs/api/PDFJavaScript.js.map
generated
vendored
Normal file
1
node_modules/pdf-lib/cjs/api/PDFJavaScript.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"PDFJavaScript.js","sourceRoot":"","sources":["../../src/api/PDFJavaScript.ts"],"names":[],"mappings":";;;AAGA,gCAA4E;AAE5E;;GAEG;AACH;IAwBE,uBACE,GAAW,EACX,GAAgB,EAChB,QAA4B;QANtB,oBAAe,GAAG,KAAK,CAAC;QAQ9B,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED;;;;;;;;OAQG;IACG,6BAAK,GAAX;;;;;;6BACM,CAAC,IAAI,CAAC,eAAe,EAArB,wBAAqB;wBACjB,KAAuB,IAAI,CAAC,GAAG,EAA7B,OAAO,aAAA,EAAE,OAAO,aAAA,CAAc;wBAE1B,qBAAM,IAAI,CAAC,QAAQ,CAAC,gBAAgB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ElB,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC;;;;;;KAE/B;IAvED;;;;;;;;;;OAUG;IACI,gBAAE,GAAG,UAAC,GAAW,EAAE,GAAgB,EAAE,QAA4B;QACtE,OAAA,IAAI,aAAa,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,CAAC;IAArC,CAAqC,CAAC;IA4D1C,oBAAC;CAAA,AAzED,IAyEC;kBAzEoB,aAAa"}
|
||||
898
node_modules/pdf-lib/cjs/api/PDFPage.d.ts
generated
vendored
Normal file
898
node_modules/pdf-lib/cjs/api/PDFPage.d.ts
generated
vendored
Normal file
@@ -0,0 +1,898 @@
|
||||
import { Color } from "./colors";
|
||||
import PDFDocument from "./PDFDocument";
|
||||
import PDFEmbeddedPage from "./PDFEmbeddedPage";
|
||||
import PDFFont from "./PDFFont";
|
||||
import PDFImage from "./PDFImage";
|
||||
import { PDFPageDrawCircleOptions, PDFPageDrawEllipseOptions, PDFPageDrawImageOptions, PDFPageDrawLineOptions, PDFPageDrawPageOptions, PDFPageDrawRectangleOptions, PDFPageDrawSquareOptions, PDFPageDrawSVGOptions, PDFPageDrawTextOptions } from "./PDFPageOptions";
|
||||
import { Rotation } from "./rotations";
|
||||
import { PDFOperator, PDFPageLeaf, PDFRef } from "../core";
|
||||
/**
|
||||
* Represents a single page of a [[PDFDocument]].
|
||||
*/
|
||||
export default class PDFPage {
|
||||
/**
|
||||
* > **NOTE:** You probably don't want to call this method directly. Instead,
|
||||
* > consider using the [[PDFDocument.addPage]] and [[PDFDocument.insertPage]]
|
||||
* > methods, which can create instances of [[PDFPage]] for you.
|
||||
*
|
||||
* Create an instance of [[PDFPage]] from an existing leaf node.
|
||||
*
|
||||
* @param leafNode The leaf node to be wrapped.
|
||||
* @param ref The unique reference for the page.
|
||||
* @param doc The document to which the page will belong.
|
||||
*/
|
||||
static of: (leafNode: PDFPageLeaf, ref: PDFRef, doc: PDFDocument) => PDFPage;
|
||||
/**
|
||||
* > **NOTE:** You probably don't want to call this method directly. Instead,
|
||||
* > consider using the [[PDFDocument.addPage]] and [[PDFDocument.insertPage]]
|
||||
* > methods, which can create instances of [[PDFPage]] for you.
|
||||
*
|
||||
* Create an instance of [[PDFPage]].
|
||||
*
|
||||
* @param doc The document to which the page will belong.
|
||||
*/
|
||||
static create: (doc: PDFDocument) => PDFPage;
|
||||
/** The low-level PDFDictionary wrapped by this page. */
|
||||
readonly node: PDFPageLeaf;
|
||||
/** The unique reference assigned to this page within the document. */
|
||||
readonly ref: PDFRef;
|
||||
/** The document to which this page belongs. */
|
||||
readonly doc: PDFDocument;
|
||||
private fontKey?;
|
||||
private font?;
|
||||
private fontSize;
|
||||
private fontColor;
|
||||
private lineHeight;
|
||||
private x;
|
||||
private y;
|
||||
private contentStream?;
|
||||
private contentStreamRef?;
|
||||
private constructor();
|
||||
/**
|
||||
* Rotate this page by a multiple of 90 degrees. For example:
|
||||
* ```js
|
||||
* import { degrees } from 'pdf-lib'
|
||||
*
|
||||
* page.setRotation(degrees(-90))
|
||||
* page.setRotation(degrees(0))
|
||||
* page.setRotation(degrees(90))
|
||||
* page.setRotation(degrees(180))
|
||||
* page.setRotation(degrees(270))
|
||||
* ```
|
||||
* @param angle The angle to rotate this page.
|
||||
*/
|
||||
setRotation(angle: Rotation): void;
|
||||
/**
|
||||
* Get this page's rotation angle in degrees. For example:
|
||||
* ```js
|
||||
* const rotationAngle = page.getRotation().angle;
|
||||
* ```
|
||||
* @returns The rotation angle of the page in degrees (always a multiple of
|
||||
* 90 degrees).
|
||||
*/
|
||||
getRotation(): Rotation;
|
||||
/**
|
||||
* Resize this page by increasing or decreasing its width and height. For
|
||||
* example:
|
||||
* ```js
|
||||
* page.setSize(250, 500)
|
||||
* page.setSize(page.getWidth() + 50, page.getHeight() + 100)
|
||||
* page.setSize(page.getWidth() - 50, page.getHeight() - 100)
|
||||
* ```
|
||||
*
|
||||
* Note that the PDF specification does not allow for pages to have explicit
|
||||
* widths and heights. Instead it defines the "size" of a page in terms of
|
||||
* five rectangles: the MediaBox, CropBox, BleedBox, TrimBox, and ArtBox. As a
|
||||
* result, this method cannot directly change the width and height of a page.
|
||||
* Instead, it works by adjusting these five boxes.
|
||||
*
|
||||
* This method performs the following steps:
|
||||
* 1. Set width & height of MediaBox.
|
||||
* 2. Set width & height of CropBox, if it has same dimensions as MediaBox.
|
||||
* 3. Set width & height of BleedBox, if it has same dimensions as MediaBox.
|
||||
* 4. Set width & height of TrimBox, if it has same dimensions as MediaBox.
|
||||
* 5. Set width & height of ArtBox, if it has same dimensions as MediaBox.
|
||||
*
|
||||
* This approach works well for most PDF documents as all PDF pages must
|
||||
* have a MediaBox, but relatively few have a CropBox, BleedBox, TrimBox, or
|
||||
* ArtBox. And when they do have these additional boxes, they often have the
|
||||
* same dimensions as the MediaBox. However, if you find this method does not
|
||||
* work for your document, consider setting the boxes directly:
|
||||
* * [[PDFPage.setMediaBox]]
|
||||
* * [[PDFPage.setCropBox]]
|
||||
* * [[PDFPage.setBleedBox]]
|
||||
* * [[PDFPage.setTrimBox]]
|
||||
* * [[PDFPage.setArtBox]]
|
||||
*
|
||||
* @param width The new width of the page.
|
||||
* @param height The new height of the page.
|
||||
*/
|
||||
setSize(width: number, height: number): void;
|
||||
/**
|
||||
* Resize this page by increasing or decreasing its width. For example:
|
||||
* ```js
|
||||
* page.setWidth(250)
|
||||
* page.setWidth(page.getWidth() + 50)
|
||||
* page.setWidth(page.getWidth() - 50)
|
||||
* ```
|
||||
*
|
||||
* This method uses [[PDFPage.setSize]] to set the page's width.
|
||||
*
|
||||
* @param width The new width of the page.
|
||||
*/
|
||||
setWidth(width: number): void;
|
||||
/**
|
||||
* Resize this page by increasing or decreasing its height. For example:
|
||||
* ```js
|
||||
* page.setHeight(500)
|
||||
* page.setHeight(page.getWidth() + 100)
|
||||
* page.setHeight(page.getWidth() - 100)
|
||||
* ```
|
||||
*
|
||||
* This method uses [[PDFPage.setSize]] to set the page's height.
|
||||
*
|
||||
* @param height The new height of the page.
|
||||
*/
|
||||
setHeight(height: number): void;
|
||||
/**
|
||||
* Set the MediaBox of this page. For example:
|
||||
* ```js
|
||||
* const mediaBox = page.getMediaBox()
|
||||
*
|
||||
* page.setMediaBox(0, 0, 250, 500)
|
||||
* page.setMediaBox(mediaBox.x, mediaBox.y, 50, 100)
|
||||
* page.setMediaBox(15, 5, mediaBox.width - 50, mediaBox.height - 100)
|
||||
* ```
|
||||
*
|
||||
* See [[PDFPage.getMediaBox]] for details about what the MediaBox represents.
|
||||
*
|
||||
* @param x The x coordinate of the lower left corner of the new MediaBox.
|
||||
* @param y The y coordinate of the lower left corner of the new MediaBox.
|
||||
* @param width The width of the new MediaBox.
|
||||
* @param height The height of the new MediaBox.
|
||||
*/
|
||||
setMediaBox(x: number, y: number, width: number, height: number): void;
|
||||
/**
|
||||
* Set the CropBox of this page. For example:
|
||||
* ```js
|
||||
* const cropBox = page.getCropBox()
|
||||
*
|
||||
* page.setCropBox(0, 0, 250, 500)
|
||||
* page.setCropBox(cropBox.x, cropBox.y, 50, 100)
|
||||
* page.setCropBox(15, 5, cropBox.width - 50, cropBox.height - 100)
|
||||
* ```
|
||||
*
|
||||
* See [[PDFPage.getCropBox]] for details about what the CropBox represents.
|
||||
*
|
||||
* @param x The x coordinate of the lower left corner of the new CropBox.
|
||||
* @param y The y coordinate of the lower left corner of the new CropBox.
|
||||
* @param width The width of the new CropBox.
|
||||
* @param height The height of the new CropBox.
|
||||
*/
|
||||
setCropBox(x: number, y: number, width: number, height: number): void;
|
||||
/**
|
||||
* Set the BleedBox of this page. For example:
|
||||
* ```js
|
||||
* const bleedBox = page.getBleedBox()
|
||||
*
|
||||
* page.setBleedBox(0, 0, 250, 500)
|
||||
* page.setBleedBox(bleedBox.x, bleedBox.y, 50, 100)
|
||||
* page.setBleedBox(15, 5, bleedBox.width - 50, bleedBox.height - 100)
|
||||
* ```
|
||||
*
|
||||
* See [[PDFPage.getBleedBox]] for details about what the BleedBox represents.
|
||||
*
|
||||
* @param x The x coordinate of the lower left corner of the new BleedBox.
|
||||
* @param y The y coordinate of the lower left corner of the new BleedBox.
|
||||
* @param width The width of the new BleedBox.
|
||||
* @param height The height of the new BleedBox.
|
||||
*/
|
||||
setBleedBox(x: number, y: number, width: number, height: number): void;
|
||||
/**
|
||||
* Set the TrimBox of this page. For example:
|
||||
* ```js
|
||||
* const trimBox = page.getTrimBox()
|
||||
*
|
||||
* page.setTrimBox(0, 0, 250, 500)
|
||||
* page.setTrimBox(trimBox.x, trimBox.y, 50, 100)
|
||||
* page.setTrimBox(15, 5, trimBox.width - 50, trimBox.height - 100)
|
||||
* ```
|
||||
*
|
||||
* See [[PDFPage.getTrimBox]] for details about what the TrimBox represents.
|
||||
*
|
||||
* @param x The x coordinate of the lower left corner of the new TrimBox.
|
||||
* @param y The y coordinate of the lower left corner of the new TrimBox.
|
||||
* @param width The width of the new TrimBox.
|
||||
* @param height The height of the new TrimBox.
|
||||
*/
|
||||
setTrimBox(x: number, y: number, width: number, height: number): void;
|
||||
/**
|
||||
* Set the ArtBox of this page. For example:
|
||||
* ```js
|
||||
* const artBox = page.getArtBox()
|
||||
*
|
||||
* page.setArtBox(0, 0, 250, 500)
|
||||
* page.setArtBox(artBox.x, artBox.y, 50, 100)
|
||||
* page.setArtBox(15, 5, artBox.width - 50, artBox.height - 100)
|
||||
* ```
|
||||
*
|
||||
* See [[PDFPage.getArtBox]] for details about what the ArtBox represents.
|
||||
*
|
||||
* @param x The x coordinate of the lower left corner of the new ArtBox.
|
||||
* @param y The y coordinate of the lower left corner of the new ArtBox.
|
||||
* @param width The width of the new ArtBox.
|
||||
* @param height The height of the new ArtBox.
|
||||
*/
|
||||
setArtBox(x: number, y: number, width: number, height: number): void;
|
||||
/**
|
||||
* Get this page's width and height. For example:
|
||||
* ```js
|
||||
* const { width, height } = page.getSize()
|
||||
* ```
|
||||
*
|
||||
* This method uses [[PDFPage.getMediaBox]] to obtain the page's
|
||||
* width and height.
|
||||
*
|
||||
* @returns The width and height of the page.
|
||||
*/
|
||||
getSize(): {
|
||||
width: number;
|
||||
height: number;
|
||||
};
|
||||
/**
|
||||
* Get this page's width. For example:
|
||||
* ```js
|
||||
* const width = page.getWidth()
|
||||
* ```
|
||||
*
|
||||
* This method uses [[PDFPage.getSize]] to obtain the page's size.
|
||||
*
|
||||
* @returns The width of the page.
|
||||
*/
|
||||
getWidth(): number;
|
||||
/**
|
||||
* Get this page's height. For example:
|
||||
* ```js
|
||||
* const height = page.getHeight()
|
||||
* ```
|
||||
*
|
||||
* This method uses [[PDFPage.getSize]] to obtain the page's size.
|
||||
*
|
||||
* @returns The height of the page.
|
||||
*/
|
||||
getHeight(): number;
|
||||
/**
|
||||
* Get the rectangle defining this page's MediaBox. For example:
|
||||
* ```js
|
||||
* const { x, y, width, height } = page.getMediaBox()
|
||||
* ```
|
||||
*
|
||||
* The MediaBox of a page defines the boundaries of the physical medium on
|
||||
* which the page is to be displayed/printed. It may include extended area
|
||||
* surrounding the page content for bleed marks, printing marks, etc...
|
||||
* It may also include areas close to the edges of the medium that cannot be
|
||||
* marked because of physical limitations of the output device. Content
|
||||
* falling outside this boundary may safely be discarded without affecting
|
||||
* the meaning of the PDF file.
|
||||
*
|
||||
* @returns An object defining the lower left corner of the MediaBox and its
|
||||
* width & height.
|
||||
*/
|
||||
getMediaBox(): {
|
||||
x: number;
|
||||
y: number;
|
||||
width: number;
|
||||
height: number;
|
||||
};
|
||||
/**
|
||||
* Get the rectangle defining this page's CropBox. For example:
|
||||
* ```js
|
||||
* const { x, y, width, height } = page.getCropBox()
|
||||
* ```
|
||||
*
|
||||
* The CropBox of a page defines the region to which the contents of the page
|
||||
* shall be clipped when displayed or printed. Unlike the other boxes, the
|
||||
* CropBox does not necessarily represent the physical page geometry. It
|
||||
* merely imposes clipping on the page contents.
|
||||
*
|
||||
* The CropBox's default value is the page's MediaBox.
|
||||
*
|
||||
* @returns An object defining the lower left corner of the CropBox and its
|
||||
* width & height.
|
||||
*/
|
||||
getCropBox(): {
|
||||
x: number;
|
||||
y: number;
|
||||
width: number;
|
||||
height: number;
|
||||
};
|
||||
/**
|
||||
* Get the rectangle defining this page's BleedBox. For example:
|
||||
* ```js
|
||||
* const { x, y, width, height } = page.getBleedBox()
|
||||
* ```
|
||||
*
|
||||
* The BleedBox of a page defines the region to which the contents of the
|
||||
* page shall be clipped when output in a production environment. This may
|
||||
* include any extra bleed area needed to accommodate the physical
|
||||
* limitations of cutting, folding, and trimming equipment. The actual
|
||||
* printed page may include printing marks that fall outside the BleedBox.
|
||||
*
|
||||
* The BleedBox's default value is the page's CropBox.
|
||||
*
|
||||
* @returns An object defining the lower left corner of the BleedBox and its
|
||||
* width & height.
|
||||
*/
|
||||
getBleedBox(): {
|
||||
x: number;
|
||||
y: number;
|
||||
width: number;
|
||||
height: number;
|
||||
};
|
||||
/**
|
||||
* Get the rectangle defining this page's TrimBox. For example:
|
||||
* ```js
|
||||
* const { x, y, width, height } = page.getTrimBox()
|
||||
* ```
|
||||
*
|
||||
* The TrimBox of a page defines the intended dimensions of the finished
|
||||
* page after trimming. It may be smaller than the MediaBox to allow for
|
||||
* production-related content, such as printing instructions, cut marks, or
|
||||
* color bars.
|
||||
*
|
||||
* The TrimBox's default value is the page's CropBox.
|
||||
*
|
||||
* @returns An object defining the lower left corner of the TrimBox and its
|
||||
* width & height.
|
||||
*/
|
||||
getTrimBox(): {
|
||||
x: number;
|
||||
y: number;
|
||||
width: number;
|
||||
height: number;
|
||||
};
|
||||
/**
|
||||
* Get the rectangle defining this page's ArtBox. For example:
|
||||
* ```js
|
||||
* const { x, y, width, height } = page.getArtBox()
|
||||
* ```
|
||||
*
|
||||
* The ArtBox of a page defines the extent of the page's meaningful content
|
||||
* (including potential white space).
|
||||
*
|
||||
* The ArtBox's default value is the page's CropBox.
|
||||
*
|
||||
* @returns An object defining the lower left corner of the ArtBox and its
|
||||
* width & height.
|
||||
*/
|
||||
getArtBox(): {
|
||||
x: number;
|
||||
y: number;
|
||||
width: number;
|
||||
height: number;
|
||||
};
|
||||
/**
|
||||
* Translate this page's content to a new location on the page. This operation
|
||||
* is often useful after resizing the page with [[setSize]]. For example:
|
||||
* ```js
|
||||
* // Add 50 units of whitespace to the top and right of the page
|
||||
* page.setSize(page.getWidth() + 50, page.getHeight() + 50)
|
||||
*
|
||||
* // Move the page's content from the lower-left corner of the page
|
||||
* // to the top-right corner.
|
||||
* page.translateContent(50, 50)
|
||||
*
|
||||
* // Now there are 50 units of whitespace to the left and bottom of the page
|
||||
* ```
|
||||
* See also: [[resetPosition]]
|
||||
* @param x The new position on the x-axis for this page's content.
|
||||
* @param y The new position on the y-axis for this page's content.
|
||||
*/
|
||||
translateContent(x: number, y: number): void;
|
||||
/**
|
||||
* Scale the size, content, and annotations of a page.
|
||||
*
|
||||
* For example:
|
||||
* ```js
|
||||
* page.scale(0.5, 0.5);
|
||||
* ```
|
||||
*
|
||||
* @param x The factor by which the width for the page should be scaled
|
||||
* (e.g. `0.5` is 50%).
|
||||
* @param y The factor by which the height for the page should be scaled
|
||||
* (e.g. `2.0` is 200%).
|
||||
*/
|
||||
scale(x: number, y: number): void;
|
||||
/**
|
||||
* Scale the content of a page. This is useful after resizing an existing
|
||||
* page. This scales only the content, not the annotations.
|
||||
*
|
||||
* For example:
|
||||
* ```js
|
||||
* // Bisect the size of the page
|
||||
* page.setSize(page.getWidth() / 2, page.getHeight() / 2);
|
||||
*
|
||||
* // Scale the content of the page down by 50% in x and y
|
||||
* page.scaleContent(0.5, 0.5);
|
||||
* ```
|
||||
* See also: [[scaleAnnotations]]
|
||||
* @param x The factor by which the x-axis for the content should be scaled
|
||||
* (e.g. `0.5` is 50%).
|
||||
* @param y The factor by which the y-axis for the content should be scaled
|
||||
* (e.g. `2.0` is 200%).
|
||||
*/
|
||||
scaleContent(x: number, y: number): void;
|
||||
/**
|
||||
* Scale the annotations of a page. This is useful if you want to scale a
|
||||
* page with comments or other annotations.
|
||||
* ```js
|
||||
* // Scale the content of the page down by 50% in x and y
|
||||
* page.scaleContent(0.5, 0.5);
|
||||
*
|
||||
* // Scale the content of the page down by 50% in x and y
|
||||
* page.scaleAnnotations(0.5, 0.5);
|
||||
* ```
|
||||
* See also: [[scaleContent]]
|
||||
* @param x The factor by which the x-axis for the annotations should be
|
||||
* scaled (e.g. `0.5` is 50%).
|
||||
* @param y The factor by which the y-axis for the annotations should be
|
||||
* scaled (e.g. `2.0` is 200%).
|
||||
*/
|
||||
scaleAnnotations(x: number, y: number): void;
|
||||
/**
|
||||
* Reset the x and y coordinates of this page to `(0, 0)`. This operation is
|
||||
* often useful after calling [[translateContent]]. For example:
|
||||
* ```js
|
||||
* // Shift the page's contents up and to the right by 50 units
|
||||
* page.translateContent(50, 50)
|
||||
*
|
||||
* // This text will shifted - it will be drawn at (50, 50)
|
||||
* page.drawText('I am shifted')
|
||||
*
|
||||
* // Move back to (0, 0)
|
||||
* page.resetPosition()
|
||||
*
|
||||
* // This text will not be shifted - it will be drawn at (0, 0)
|
||||
* page.drawText('I am not shifted')
|
||||
* ```
|
||||
*/
|
||||
resetPosition(): void;
|
||||
/**
|
||||
* Choose a default font for this page. The default font will be used whenever
|
||||
* text is drawn on this page and no font is specified. For example:
|
||||
* ```js
|
||||
* import { StandardFonts } from 'pdf-lib'
|
||||
*
|
||||
* const timesRomanFont = await pdfDoc.embedFont(StandardFonts.TimesRoman)
|
||||
* const helveticaFont = await pdfDoc.embedFont(StandardFonts.Helvetica)
|
||||
* const courierFont = await pdfDoc.embedFont(StandardFonts.Courier)
|
||||
*
|
||||
* const page = pdfDoc.addPage()
|
||||
*
|
||||
* page.setFont(helveticaFont)
|
||||
* page.drawText('I will be drawn in Helvetica')
|
||||
*
|
||||
* page.setFont(timesRomanFont)
|
||||
* page.drawText('I will be drawn in Courier', { font: courierFont })
|
||||
* ```
|
||||
* @param font The default font to be used when drawing text on this page.
|
||||
*/
|
||||
setFont(font: PDFFont): void;
|
||||
/**
|
||||
* Choose a default font size for this page. The default font size will be
|
||||
* used whenever text is drawn on this page and no font size is specified.
|
||||
* For example:
|
||||
* ```js
|
||||
* page.setFontSize(12)
|
||||
* page.drawText('I will be drawn in size 12')
|
||||
*
|
||||
* page.setFontSize(36)
|
||||
* page.drawText('I will be drawn in size 24', { fontSize: 24 })
|
||||
* ```
|
||||
* @param fontSize The default font size to be used when drawing text on this
|
||||
* page.
|
||||
*/
|
||||
setFontSize(fontSize: number): void;
|
||||
/**
|
||||
* Choose a default font color for this page. The default font color will be
|
||||
* used whenever text is drawn on this page and no font color is specified.
|
||||
* For example:
|
||||
* ```js
|
||||
* import { rgb, cmyk, grayscale } from 'pdf-lib'
|
||||
*
|
||||
* page.setFontColor(rgb(0.97, 0.02, 0.97))
|
||||
* page.drawText('I will be drawn in pink')
|
||||
*
|
||||
* page.setFontColor(cmyk(0.4, 0.7, 0.39, 0.15))
|
||||
* page.drawText('I will be drawn in gray', { color: grayscale(0.5) })
|
||||
* ```
|
||||
* @param fontColor The default font color to be used when drawing text on
|
||||
* this page.
|
||||
*/
|
||||
setFontColor(fontColor: Color): void;
|
||||
/**
|
||||
* Choose a default line height for this page. The default line height will be
|
||||
* used whenever text is drawn on this page and no line height is specified.
|
||||
* For example:
|
||||
* ```js
|
||||
* page.setLineHeight(12);
|
||||
* page.drawText('These lines will be vertically \n separated by 12 units')
|
||||
*
|
||||
* page.setLineHeight(36);
|
||||
* page.drawText('These lines will be vertically \n separated by 24 units', {
|
||||
* lineHeight: 24
|
||||
* })
|
||||
* ```
|
||||
* @param lineHeight The default line height to be used when drawing text on
|
||||
* this page.
|
||||
*/
|
||||
setLineHeight(lineHeight: number): void;
|
||||
/**
|
||||
* Get the default position of this page. For example:
|
||||
* ```js
|
||||
* const { x, y } = page.getPosition()
|
||||
* ```
|
||||
* @returns The default position of the page.
|
||||
*/
|
||||
getPosition(): {
|
||||
x: number;
|
||||
y: number;
|
||||
};
|
||||
/**
|
||||
* Get the default x coordinate of this page. For example:
|
||||
* ```js
|
||||
* const x = page.getX()
|
||||
* ```
|
||||
* @returns The default x coordinate of the page.
|
||||
*/
|
||||
getX(): number;
|
||||
/**
|
||||
* Get the default y coordinate of this page. For example:
|
||||
* ```js
|
||||
* const y = page.getY()
|
||||
* ```
|
||||
* @returns The default y coordinate of the page.
|
||||
*/
|
||||
getY(): number;
|
||||
/**
|
||||
* Change the default position of this page. For example:
|
||||
* ```js
|
||||
* page.moveTo(0, 0)
|
||||
* page.drawText('I will be drawn at the origin')
|
||||
*
|
||||
* page.moveTo(0, 25)
|
||||
* page.drawText('I will be drawn 25 units up')
|
||||
*
|
||||
* page.moveTo(25, 25)
|
||||
* page.drawText('I will be drawn 25 units up and 25 units to the right')
|
||||
* ```
|
||||
* @param x The new default position on the x-axis for this page.
|
||||
* @param y The new default position on the y-axis for this page.
|
||||
*/
|
||||
moveTo(x: number, y: number): void;
|
||||
/**
|
||||
* Change the default position of this page to be further down the y-axis.
|
||||
* For example:
|
||||
* ```js
|
||||
* page.moveTo(50, 50)
|
||||
* page.drawText('I will be drawn at (50, 50)')
|
||||
*
|
||||
* page.moveDown(10)
|
||||
* page.drawText('I will be drawn at (50, 40)')
|
||||
* ```
|
||||
* @param yDecrease The amount by which the page's default position along the
|
||||
* y-axis should be decreased.
|
||||
*/
|
||||
moveDown(yDecrease: number): void;
|
||||
/**
|
||||
* Change the default position of this page to be further up the y-axis.
|
||||
* For example:
|
||||
* ```js
|
||||
* page.moveTo(50, 50)
|
||||
* page.drawText('I will be drawn at (50, 50)')
|
||||
*
|
||||
* page.moveUp(10)
|
||||
* page.drawText('I will be drawn at (50, 60)')
|
||||
* ```
|
||||
* @param yIncrease The amount by which the page's default position along the
|
||||
* y-axis should be increased.
|
||||
*/
|
||||
moveUp(yIncrease: number): void;
|
||||
/**
|
||||
* Change the default position of this page to be further left on the x-axis.
|
||||
* For example:
|
||||
* ```js
|
||||
* page.moveTo(50, 50)
|
||||
* page.drawText('I will be drawn at (50, 50)')
|
||||
*
|
||||
* page.moveLeft(10)
|
||||
* page.drawText('I will be drawn at (40, 50)')
|
||||
* ```
|
||||
* @param xDecrease The amount by which the page's default position along the
|
||||
* x-axis should be decreased.
|
||||
*/
|
||||
moveLeft(xDecrease: number): void;
|
||||
/**
|
||||
* Change the default position of this page to be further right on the y-axis.
|
||||
* For example:
|
||||
* ```js
|
||||
* page.moveTo(50, 50)
|
||||
* page.drawText('I will be drawn at (50, 50)')
|
||||
*
|
||||
* page.moveRight(10)
|
||||
* page.drawText('I will be drawn at (60, 50)')
|
||||
* ```
|
||||
* @param xIncrease The amount by which the page's default position along the
|
||||
* x-axis should be increased.
|
||||
*/
|
||||
moveRight(xIncrease: number): void;
|
||||
/**
|
||||
* Push one or more operators to the end of this page's current content
|
||||
* stream. For example:
|
||||
* ```js
|
||||
* import {
|
||||
* pushGraphicsState,
|
||||
* moveTo,
|
||||
* lineTo,
|
||||
* closePath,
|
||||
* setFillingColor,
|
||||
* rgb,
|
||||
* fill,
|
||||
* popGraphicsState,
|
||||
* } from 'pdf-lib'
|
||||
*
|
||||
* // Draw a green triangle in the lower-left corner of the page
|
||||
* page.pushOperators(
|
||||
* pushGraphicsState(),
|
||||
* moveTo(0, 0),
|
||||
* lineTo(100, 0),
|
||||
* lineTo(50, 100),
|
||||
* closePath(),
|
||||
* setFillingColor(rgb(0.0, 1.0, 0.0)),
|
||||
* fill(),
|
||||
* popGraphicsState(),
|
||||
* )
|
||||
* ```
|
||||
* @param operator The operators to be pushed.
|
||||
*/
|
||||
pushOperators(...operator: PDFOperator[]): void;
|
||||
/**
|
||||
* Draw one or more lines of text on this page. For example:
|
||||
* ```js
|
||||
* import { StandardFonts, rgb } from 'pdf-lib'
|
||||
*
|
||||
* const helveticaFont = await pdfDoc.embedFont(StandardFonts.Helvetica)
|
||||
* const timesRomanFont = await pdfDoc.embedFont(StandardFonts.TimesRoman)
|
||||
*
|
||||
* const page = pdfDoc.addPage()
|
||||
*
|
||||
* page.setFont(helveticaFont)
|
||||
*
|
||||
* page.moveTo(5, 200)
|
||||
* page.drawText('The Life of an Egg', { size: 36 })
|
||||
*
|
||||
* page.moveDown(36)
|
||||
* page.drawText('An Epic Tale of Woe', { size: 30 })
|
||||
*
|
||||
* page.drawText(
|
||||
* `Humpty Dumpty sat on a wall \n` +
|
||||
* `Humpty Dumpty had a great fall; \n` +
|
||||
* `All the king's horses and all the king's men \n` +
|
||||
* `Couldn't put Humpty together again. \n`,
|
||||
* {
|
||||
* x: 25,
|
||||
* y: 100,
|
||||
* font: timesRomanFont,
|
||||
* size: 24,
|
||||
* color: rgb(1, 0, 0),
|
||||
* lineHeight: 24,
|
||||
* opacity: 0.75,
|
||||
* },
|
||||
* )
|
||||
* ```
|
||||
* @param text The text to be drawn.
|
||||
* @param options The options to be used when drawing the text.
|
||||
*/
|
||||
drawText(text: string, options?: PDFPageDrawTextOptions): void;
|
||||
/**
|
||||
* Draw an image on this page. For example:
|
||||
* ```js
|
||||
* import { degrees } from 'pdf-lib'
|
||||
*
|
||||
* const jpgUrl = 'https://pdf-lib.js.org/assets/cat_riding_unicorn.jpg'
|
||||
* const jpgImageBytes = await fetch(jpgUrl).then((res) => res.arrayBuffer())
|
||||
*
|
||||
* const jpgImage = await pdfDoc.embedJpg(jpgImageBytes)
|
||||
* const jpgDims = jpgImage.scale(0.5)
|
||||
*
|
||||
* const page = pdfDoc.addPage()
|
||||
*
|
||||
* page.drawImage(jpgImage, {
|
||||
* x: 25,
|
||||
* y: 25,
|
||||
* width: jpgDims.width,
|
||||
* height: jpgDims.height,
|
||||
* rotate: degrees(30),
|
||||
* opacity: 0.75,
|
||||
* })
|
||||
* ```
|
||||
* @param image The image to be drawn.
|
||||
* @param options The options to be used when drawing the image.
|
||||
*/
|
||||
drawImage(image: PDFImage, options?: PDFPageDrawImageOptions): void;
|
||||
/**
|
||||
* Draw an embedded PDF page on this page. For example:
|
||||
* ```js
|
||||
* import { degrees } from 'pdf-lib'
|
||||
*
|
||||
* const pdfDoc = await PDFDocument.create()
|
||||
* const page = pdfDoc.addPage()
|
||||
*
|
||||
* const sourcePdfUrl = 'https://pdf-lib.js.org/assets/with_large_page_count.pdf'
|
||||
* const sourcePdf = await fetch(sourcePdfUrl).then((res) => res.arrayBuffer())
|
||||
*
|
||||
* // Embed page 74 from the PDF
|
||||
* const [embeddedPage] = await pdfDoc.embedPdf(sourcePdf, 73)
|
||||
*
|
||||
* page.drawPage(embeddedPage, {
|
||||
* x: 250,
|
||||
* y: 200,
|
||||
* xScale: 0.5,
|
||||
* yScale: 0.5,
|
||||
* rotate: degrees(30),
|
||||
* opacity: 0.75,
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
* The `options` argument accepts both `width`/`height` and `xScale`/`yScale`
|
||||
* as options. Since each of these options defines the size of the drawn page,
|
||||
* if both options are given, `width` and `height` take precedence and the
|
||||
* corresponding scale variants are ignored.
|
||||
*
|
||||
* @param embeddedPage The embedded page to be drawn.
|
||||
* @param options The options to be used when drawing the embedded page.
|
||||
*/
|
||||
drawPage(embeddedPage: PDFEmbeddedPage, options?: PDFPageDrawPageOptions): void;
|
||||
/**
|
||||
* Draw an SVG path on this page. For example:
|
||||
* ```js
|
||||
* import { rgb } from 'pdf-lib'
|
||||
*
|
||||
* const svgPath = 'M 0,20 L 100,160 Q 130,200 150,120 C 190,-40 200,200 300,150 L 400,90'
|
||||
*
|
||||
* // Draw path as black line
|
||||
* page.drawSvgPath(svgPath, { x: 25, y: 75 })
|
||||
*
|
||||
* // Change border style and opacity
|
||||
* page.drawSvgPath(svgPath, {
|
||||
* x: 25,
|
||||
* y: 275,
|
||||
* borderColor: rgb(0.5, 0.5, 0.5),
|
||||
* borderWidth: 2,
|
||||
* borderOpacity: 0.75,
|
||||
* })
|
||||
*
|
||||
* // Set fill color and opacity
|
||||
* page.drawSvgPath(svgPath, {
|
||||
* x: 25,
|
||||
* y: 475,
|
||||
* color: rgb(1.0, 0, 0),
|
||||
* opacity: 0.75,
|
||||
* })
|
||||
*
|
||||
* // Draw 50% of original size
|
||||
* page.drawSvgPath(svgPath, {
|
||||
* x: 25,
|
||||
* y: 675,
|
||||
* scale: 0.5,
|
||||
* })
|
||||
* ```
|
||||
* @param path The SVG path to be drawn.
|
||||
* @param options The options to be used when drawing the SVG path.
|
||||
*/
|
||||
drawSvgPath(path: string, options?: PDFPageDrawSVGOptions): void;
|
||||
/**
|
||||
* Draw a line on this page. For example:
|
||||
* ```js
|
||||
* import { rgb } from 'pdf-lib'
|
||||
*
|
||||
* page.drawLine({
|
||||
* start: { x: 25, y: 75 },
|
||||
* end: { x: 125, y: 175 },
|
||||
* thickness: 2,
|
||||
* color: rgb(0.75, 0.2, 0.2),
|
||||
* opacity: 0.75,
|
||||
* })
|
||||
* ```
|
||||
* @param options The options to be used when drawing the line.
|
||||
*/
|
||||
drawLine(options: PDFPageDrawLineOptions): void;
|
||||
/**
|
||||
* Draw a rectangle on this page. For example:
|
||||
* ```js
|
||||
* import { degrees, grayscale, rgb } from 'pdf-lib'
|
||||
*
|
||||
* page.drawRectangle({
|
||||
* x: 25,
|
||||
* y: 75,
|
||||
* width: 250,
|
||||
* height: 75,
|
||||
* rotate: degrees(-15),
|
||||
* borderWidth: 5,
|
||||
* borderColor: grayscale(0.5),
|
||||
* color: rgb(0.75, 0.2, 0.2),
|
||||
* opacity: 0.5,
|
||||
* borderOpacity: 0.75,
|
||||
* })
|
||||
* ```
|
||||
* @param options The options to be used when drawing the rectangle.
|
||||
*/
|
||||
drawRectangle(options?: PDFPageDrawRectangleOptions): void;
|
||||
/**
|
||||
* Draw a square on this page. For example:
|
||||
* ```js
|
||||
* import { degrees, grayscale, rgb } from 'pdf-lib'
|
||||
*
|
||||
* page.drawSquare({
|
||||
* x: 25,
|
||||
* y: 75,
|
||||
* size: 100,
|
||||
* rotate: degrees(-15),
|
||||
* borderWidth: 5,
|
||||
* borderColor: grayscale(0.5),
|
||||
* color: rgb(0.75, 0.2, 0.2),
|
||||
* opacity: 0.5,
|
||||
* borderOpacity: 0.75,
|
||||
* })
|
||||
* ```
|
||||
* @param options The options to be used when drawing the square.
|
||||
*/
|
||||
drawSquare(options?: PDFPageDrawSquareOptions): void;
|
||||
/**
|
||||
* Draw an ellipse on this page. For example:
|
||||
* ```js
|
||||
* import { grayscale, rgb } from 'pdf-lib'
|
||||
*
|
||||
* page.drawEllipse({
|
||||
* x: 200,
|
||||
* y: 75,
|
||||
* xScale: 100,
|
||||
* yScale: 50,
|
||||
* borderWidth: 5,
|
||||
* borderColor: grayscale(0.5),
|
||||
* color: rgb(0.75, 0.2, 0.2),
|
||||
* opacity: 0.5,
|
||||
* borderOpacity: 0.75,
|
||||
* })
|
||||
* ```
|
||||
* @param options The options to be used when drawing the ellipse.
|
||||
*/
|
||||
drawEllipse(options?: PDFPageDrawEllipseOptions): void;
|
||||
/**
|
||||
* Draw a circle on this page. For example:
|
||||
* ```js
|
||||
* import { grayscale, rgb } from 'pdf-lib'
|
||||
*
|
||||
* page.drawCircle({
|
||||
* x: 200,
|
||||
* y: 150,
|
||||
* size: 100,
|
||||
* borderWidth: 5,
|
||||
* borderColor: grayscale(0.5),
|
||||
* color: rgb(0.75, 0.2, 0.2),
|
||||
* opacity: 0.5,
|
||||
* borderOpacity: 0.75,
|
||||
* })
|
||||
* ```
|
||||
* @param options The options to be used when drawing the ellipse.
|
||||
*/
|
||||
drawCircle(options?: PDFPageDrawCircleOptions): void;
|
||||
private setOrEmbedFont;
|
||||
private getFont;
|
||||
private resetFont;
|
||||
private getContentStream;
|
||||
private createContentStream;
|
||||
private maybeEmbedGraphicsState;
|
||||
private scaleAnnot;
|
||||
}
|
||||
//# sourceMappingURL=PDFPage.d.ts.map
|
||||
1
node_modules/pdf-lib/cjs/api/PDFPage.d.ts.map
generated
vendored
Normal file
1
node_modules/pdf-lib/cjs/api/PDFPage.d.ts.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
1442
node_modules/pdf-lib/cjs/api/PDFPage.js
generated
vendored
Normal file
1442
node_modules/pdf-lib/cjs/api/PDFPage.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1
node_modules/pdf-lib/cjs/api/PDFPage.js.map
generated
vendored
Normal file
1
node_modules/pdf-lib/cjs/api/PDFPage.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
155
node_modules/pdf-lib/cjs/api/PDFPageOptions.d.ts
generated
vendored
Normal file
155
node_modules/pdf-lib/cjs/api/PDFPageOptions.d.ts
generated
vendored
Normal file
@@ -0,0 +1,155 @@
|
||||
import { Color } from "./colors";
|
||||
import PDFFont from "./PDFFont";
|
||||
import { Rotation } from "./rotations";
|
||||
import { LineCapStyle } from "./operators";
|
||||
export declare enum BlendMode {
|
||||
Normal = "Normal",
|
||||
Multiply = "Multiply",
|
||||
Screen = "Screen",
|
||||
Overlay = "Overlay",
|
||||
Darken = "Darken",
|
||||
Lighten = "Lighten",
|
||||
ColorDodge = "ColorDodge",
|
||||
ColorBurn = "ColorBurn",
|
||||
HardLight = "HardLight",
|
||||
SoftLight = "SoftLight",
|
||||
Difference = "Difference",
|
||||
Exclusion = "Exclusion"
|
||||
}
|
||||
export interface PDFPageDrawTextOptions {
|
||||
color?: Color;
|
||||
opacity?: number;
|
||||
blendMode?: BlendMode;
|
||||
font?: PDFFont;
|
||||
size?: number;
|
||||
rotate?: Rotation;
|
||||
xSkew?: Rotation;
|
||||
ySkew?: Rotation;
|
||||
x?: number;
|
||||
y?: number;
|
||||
lineHeight?: number;
|
||||
maxWidth?: number;
|
||||
wordBreaks?: string[];
|
||||
}
|
||||
export interface PDFPageDrawImageOptions {
|
||||
x?: number;
|
||||
y?: number;
|
||||
width?: number;
|
||||
height?: number;
|
||||
rotate?: Rotation;
|
||||
xSkew?: Rotation;
|
||||
ySkew?: Rotation;
|
||||
opacity?: number;
|
||||
blendMode?: BlendMode;
|
||||
}
|
||||
export interface PDFPageDrawPageOptions {
|
||||
x?: number;
|
||||
y?: number;
|
||||
xScale?: number;
|
||||
yScale?: number;
|
||||
width?: number;
|
||||
height?: number;
|
||||
rotate?: Rotation;
|
||||
xSkew?: Rotation;
|
||||
ySkew?: Rotation;
|
||||
opacity?: number;
|
||||
blendMode?: BlendMode;
|
||||
}
|
||||
export interface PDFPageDrawSVGOptions {
|
||||
x?: number;
|
||||
y?: number;
|
||||
scale?: number;
|
||||
rotate?: Rotation;
|
||||
borderWidth?: number;
|
||||
color?: Color;
|
||||
opacity?: number;
|
||||
borderColor?: Color;
|
||||
borderOpacity?: number;
|
||||
borderDashArray?: number[];
|
||||
borderDashPhase?: number;
|
||||
borderLineCap?: LineCapStyle;
|
||||
blendMode?: BlendMode;
|
||||
}
|
||||
export interface PDFPageDrawLineOptions {
|
||||
start: {
|
||||
x: number;
|
||||
y: number;
|
||||
};
|
||||
end: {
|
||||
x: number;
|
||||
y: number;
|
||||
};
|
||||
thickness?: number;
|
||||
color?: Color;
|
||||
opacity?: number;
|
||||
lineCap?: LineCapStyle;
|
||||
dashArray?: number[];
|
||||
dashPhase?: number;
|
||||
blendMode?: BlendMode;
|
||||
}
|
||||
export interface PDFPageDrawRectangleOptions {
|
||||
x?: number;
|
||||
y?: number;
|
||||
width?: number;
|
||||
height?: number;
|
||||
rotate?: Rotation;
|
||||
xSkew?: Rotation;
|
||||
ySkew?: Rotation;
|
||||
borderWidth?: number;
|
||||
color?: Color;
|
||||
opacity?: number;
|
||||
borderColor?: Color;
|
||||
borderOpacity?: number;
|
||||
borderDashArray?: number[];
|
||||
borderDashPhase?: number;
|
||||
borderLineCap?: LineCapStyle;
|
||||
blendMode?: BlendMode;
|
||||
}
|
||||
export interface PDFPageDrawSquareOptions {
|
||||
x?: number;
|
||||
y?: number;
|
||||
size?: number;
|
||||
rotate?: Rotation;
|
||||
xSkew?: Rotation;
|
||||
ySkew?: Rotation;
|
||||
borderWidth?: number;
|
||||
color?: Color;
|
||||
opacity?: number;
|
||||
borderColor?: Color;
|
||||
borderOpacity?: number;
|
||||
borderDashArray?: number[];
|
||||
borderDashPhase?: number;
|
||||
borderLineCap?: LineCapStyle;
|
||||
blendMode?: BlendMode;
|
||||
}
|
||||
export interface PDFPageDrawEllipseOptions {
|
||||
x?: number;
|
||||
y?: number;
|
||||
xScale?: number;
|
||||
yScale?: number;
|
||||
rotate?: Rotation;
|
||||
color?: Color;
|
||||
opacity?: number;
|
||||
borderColor?: Color;
|
||||
borderOpacity?: number;
|
||||
borderWidth?: number;
|
||||
borderDashArray?: number[];
|
||||
borderDashPhase?: number;
|
||||
borderLineCap?: LineCapStyle;
|
||||
blendMode?: BlendMode;
|
||||
}
|
||||
export interface PDFPageDrawCircleOptions {
|
||||
x?: number;
|
||||
y?: number;
|
||||
size?: number;
|
||||
color?: Color;
|
||||
opacity?: number;
|
||||
borderColor?: Color;
|
||||
borderOpacity?: number;
|
||||
borderWidth?: number;
|
||||
borderDashArray?: number[];
|
||||
borderDashPhase?: number;
|
||||
borderLineCap?: LineCapStyle;
|
||||
blendMode?: BlendMode;
|
||||
}
|
||||
//# sourceMappingURL=PDFPageOptions.d.ts.map
|
||||
1
node_modules/pdf-lib/cjs/api/PDFPageOptions.d.ts.map
generated
vendored
Normal file
1
node_modules/pdf-lib/cjs/api/PDFPageOptions.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"PDFPageOptions.d.ts","sourceRoot":"","sources":["../../src/api/PDFPageOptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,iBAAuB;AACvC,OAAO,OAAO,kBAAwB;AACtC,OAAO,EAAE,QAAQ,EAAE,oBAA0B;AAC7C,OAAO,EAAE,YAAY,EAAE,oBAA0B;AAEjD,oBAAY,SAAS;IACnB,MAAM,WAAW;IACjB,QAAQ,aAAa;IACrB,MAAM,WAAW;IACjB,OAAO,YAAY;IACnB,MAAM,WAAW;IACjB,OAAO,YAAY;IACnB,UAAU,eAAe;IACzB,SAAS,cAAc;IACvB,SAAS,cAAc;IACvB,SAAS,cAAc;IACvB,UAAU,eAAe;IACzB,SAAS,cAAc;CACxB;AAED,MAAM,WAAW,sBAAsB;IACrC,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;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EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,aAAa,CAAC,EAAE,YAAY,CAAC;IAC7B,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB;AAED,MAAM,WAAW,wBAAwB;IACvC,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,KAAK,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,aAAa,CAAC,EAAE,YAAY,CAAC;IAC7B,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB"}
|
||||
19
node_modules/pdf-lib/cjs/api/PDFPageOptions.js
generated
vendored
Normal file
19
node_modules/pdf-lib/cjs/api/PDFPageOptions.js
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.BlendMode = void 0;
|
||||
var BlendMode;
|
||||
(function (BlendMode) {
|
||||
BlendMode["Normal"] = "Normal";
|
||||
BlendMode["Multiply"] = "Multiply";
|
||||
BlendMode["Screen"] = "Screen";
|
||||
BlendMode["Overlay"] = "Overlay";
|
||||
BlendMode["Darken"] = "Darken";
|
||||
BlendMode["Lighten"] = "Lighten";
|
||||
BlendMode["ColorDodge"] = "ColorDodge";
|
||||
BlendMode["ColorBurn"] = "ColorBurn";
|
||||
BlendMode["HardLight"] = "HardLight";
|
||||
BlendMode["SoftLight"] = "SoftLight";
|
||||
BlendMode["Difference"] = "Difference";
|
||||
BlendMode["Exclusion"] = "Exclusion";
|
||||
})(BlendMode = exports.BlendMode || (exports.BlendMode = {}));
|
||||
//# sourceMappingURL=PDFPageOptions.js.map
|
||||
1
node_modules/pdf-lib/cjs/api/PDFPageOptions.js.map
generated
vendored
Normal file
1
node_modules/pdf-lib/cjs/api/PDFPageOptions.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"PDFPageOptions.js","sourceRoot":"","sources":["../../src/api/PDFPageOptions.ts"],"names":[],"mappings":";;;AAKA,IAAY,SAaX;AAbD,WAAY,SAAS;IACnB,8BAAiB,CAAA;IACjB,kCAAqB,CAAA;IACrB,8BAAiB,CAAA;IACjB,gCAAmB,CAAA;IACnB,8BAAiB,CAAA;IACjB,gCAAmB,CAAA;IACnB,sCAAyB,CAAA;IACzB,oCAAuB,CAAA;IACvB,oCAAuB,CAAA;IACvB,oCAAuB,CAAA;IACvB,sCAAyB,CAAA;IACzB,oCAAuB,CAAA;AACzB,CAAC,EAbW,SAAS,GAAT,iBAAS,KAAT,iBAAS,QAapB"}
|
||||
17
node_modules/pdf-lib/cjs/api/StandardFonts.d.ts
generated
vendored
Normal file
17
node_modules/pdf-lib/cjs/api/StandardFonts.d.ts
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
export declare enum StandardFonts {
|
||||
Courier = "Courier",
|
||||
CourierBold = "Courier-Bold",
|
||||
CourierOblique = "Courier-Oblique",
|
||||
CourierBoldOblique = "Courier-BoldOblique",
|
||||
Helvetica = "Helvetica",
|
||||
HelveticaBold = "Helvetica-Bold",
|
||||
HelveticaOblique = "Helvetica-Oblique",
|
||||
HelveticaBoldOblique = "Helvetica-BoldOblique",
|
||||
TimesRoman = "Times-Roman",
|
||||
TimesRomanBold = "Times-Bold",
|
||||
TimesRomanItalic = "Times-Italic",
|
||||
TimesRomanBoldItalic = "Times-BoldItalic",
|
||||
Symbol = "Symbol",
|
||||
ZapfDingbats = "ZapfDingbats"
|
||||
}
|
||||
//# sourceMappingURL=StandardFonts.d.ts.map
|
||||
1
node_modules/pdf-lib/cjs/api/StandardFonts.d.ts.map
generated
vendored
Normal file
1
node_modules/pdf-lib/cjs/api/StandardFonts.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"StandardFonts.d.ts","sourceRoot":"","sources":["../../src/api/StandardFonts.ts"],"names":[],"mappings":"AAAA,oBAAY,aAAa;IACvB,OAAO,YAAY;IACnB,WAAW,iBAAiB;IAC5B,cAAc,oBAAoB;IAClC,kBAAkB,wBAAwB;IAC1C,SAAS,cAAc;IACvB,aAAa,mBAAmB;IAChC,gBAAgB,sBAAsB;IACtC,oBAAoB,0BAA0B;IAC9C,UAAU,gBAAgB;IAC1B,cAAc,eAAe;IAC7B,gBAAgB,iBAAiB;IACjC,oBAAoB,qBAAqB;IACzC,MAAM,WAAW;IACjB,YAAY,iBAAiB;CAC9B"}
|
||||
21
node_modules/pdf-lib/cjs/api/StandardFonts.js
generated
vendored
Normal file
21
node_modules/pdf-lib/cjs/api/StandardFonts.js
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.StandardFonts = void 0;
|
||||
var StandardFonts;
|
||||
(function (StandardFonts) {
|
||||
StandardFonts["Courier"] = "Courier";
|
||||
StandardFonts["CourierBold"] = "Courier-Bold";
|
||||
StandardFonts["CourierOblique"] = "Courier-Oblique";
|
||||
StandardFonts["CourierBoldOblique"] = "Courier-BoldOblique";
|
||||
StandardFonts["Helvetica"] = "Helvetica";
|
||||
StandardFonts["HelveticaBold"] = "Helvetica-Bold";
|
||||
StandardFonts["HelveticaOblique"] = "Helvetica-Oblique";
|
||||
StandardFonts["HelveticaBoldOblique"] = "Helvetica-BoldOblique";
|
||||
StandardFonts["TimesRoman"] = "Times-Roman";
|
||||
StandardFonts["TimesRomanBold"] = "Times-Bold";
|
||||
StandardFonts["TimesRomanItalic"] = "Times-Italic";
|
||||
StandardFonts["TimesRomanBoldItalic"] = "Times-BoldItalic";
|
||||
StandardFonts["Symbol"] = "Symbol";
|
||||
StandardFonts["ZapfDingbats"] = "ZapfDingbats";
|
||||
})(StandardFonts = exports.StandardFonts || (exports.StandardFonts = {}));
|
||||
//# sourceMappingURL=StandardFonts.js.map
|
||||
1
node_modules/pdf-lib/cjs/api/StandardFonts.js.map
generated
vendored
Normal file
1
node_modules/pdf-lib/cjs/api/StandardFonts.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"StandardFonts.js","sourceRoot":"","sources":["../../src/api/StandardFonts.ts"],"names":[],"mappings":";;;AAAA,IAAY,aAeX;AAfD,WAAY,aAAa;IACvB,oCAAmB,CAAA;IACnB,6CAA4B,CAAA;IAC5B,mDAAkC,CAAA;IAClC,2DAA0C,CAAA;IAC1C,wCAAuB,CAAA;IACvB,iDAAgC,CAAA;IAChC,uDAAsC,CAAA;IACtC,+DAA8C,CAAA;IAC9C,2CAA0B,CAAA;IAC1B,8CAA6B,CAAA;IAC7B,kDAAiC,CAAA;IACjC,0DAAyC,CAAA;IACzC,kCAAiB,CAAA;IACjB,8CAA6B,CAAA;AAC/B,CAAC,EAfW,aAAa,GAAb,qBAAa,KAAb,qBAAa,QAexB"}
|
||||
31
node_modules/pdf-lib/cjs/api/colors.d.ts
generated
vendored
Normal file
31
node_modules/pdf-lib/cjs/api/colors.d.ts
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
export declare enum ColorTypes {
|
||||
Grayscale = "Grayscale",
|
||||
RGB = "RGB",
|
||||
CMYK = "CMYK"
|
||||
}
|
||||
export interface Grayscale {
|
||||
type: ColorTypes.Grayscale;
|
||||
gray: number;
|
||||
}
|
||||
export interface RGB {
|
||||
type: ColorTypes.RGB;
|
||||
red: number;
|
||||
green: number;
|
||||
blue: number;
|
||||
}
|
||||
export interface CMYK {
|
||||
type: ColorTypes.CMYK;
|
||||
cyan: number;
|
||||
magenta: number;
|
||||
yellow: number;
|
||||
key: number;
|
||||
}
|
||||
export declare type Color = Grayscale | RGB | CMYK;
|
||||
export declare const grayscale: (gray: number) => Grayscale;
|
||||
export declare const rgb: (red: number, green: number, blue: number) => RGB;
|
||||
export declare const cmyk: (cyan: number, magenta: number, yellow: number, key: number) => CMYK;
|
||||
export declare const setFillingColor: (color: Color) => import("../core/operators/PDFOperator").default;
|
||||
export declare const setStrokingColor: (color: Color) => import("../core/operators/PDFOperator").default;
|
||||
export declare const componentsToColor: (comps?: number[] | undefined, scale?: number) => Grayscale | RGB | CMYK | undefined;
|
||||
export declare const colorToComponents: (color: Color) => number[];
|
||||
//# sourceMappingURL=colors.d.ts.map
|
||||
1
node_modules/pdf-lib/cjs/api/colors.d.ts.map
generated
vendored
Normal file
1
node_modules/pdf-lib/cjs/api/colors.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"colors.d.ts","sourceRoot":"","sources":["../../src/api/colors.ts"],"names":[],"mappings":"AAUA,oBAAY,UAAU;IACpB,SAAS,cAAc;IACvB,GAAG,QAAQ;IACX,IAAI,SAAS;CACd;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,UAAU,CAAC,SAAS,CAAC;IAC3B,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,GAAG;IAClB,IAAI,EAAE,UAAU,CAAC,GAAG,CAAC;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,IAAI;IACnB,IAAI,EAAE,UAAU,CAAC,IAAI,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;CACb;AAED,oBAAY,KAAK,GAAG,SAAS,GAAG,GAAG,GAAG,IAAI,CAAC;AAE3C,eAAO,MAAM,SAAS,SAAU,MAAM,cAGrC,CAAC;AAEF,eAAO,MAAM,GAAG,QAAS,MAAM,SAAS,MAAM,QAAQ,MAAM,QAK3D,CAAC;AAEF,eAAO,MAAM,IAAI,SACT,MAAM,WACH,MAAM,UACP,MAAM,OACT,MAAM,SAOZ,CAAC;AAKF,eAAO,MAAM,eAAe,UAAW,KAAK,oDAIQ,CAAC;AAGrD,eAAO,MAAM,gBAAgB,UAAW,KAAK,oDAIO,CAAC;AAGrD,eAAO,MAAM,iBAAiB,sFAgB7B,CAAC;AAGF,eAAO,MAAM,iBAAiB,UAAW,KAAK,aAIM,CAAC"}
|
||||
59
node_modules/pdf-lib/cjs/api/colors.js
generated
vendored
Normal file
59
node_modules/pdf-lib/cjs/api/colors.js
generated
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.colorToComponents = exports.componentsToColor = exports.setStrokingColor = exports.setFillingColor = exports.cmyk = exports.rgb = exports.grayscale = exports.ColorTypes = void 0;
|
||||
var operators_1 = require("./operators");
|
||||
var utils_1 = require("../utils");
|
||||
var ColorTypes;
|
||||
(function (ColorTypes) {
|
||||
ColorTypes["Grayscale"] = "Grayscale";
|
||||
ColorTypes["RGB"] = "RGB";
|
||||
ColorTypes["CMYK"] = "CMYK";
|
||||
})(ColorTypes = exports.ColorTypes || (exports.ColorTypes = {}));
|
||||
exports.grayscale = function (gray) {
|
||||
utils_1.assertRange(gray, 'gray', 0.0, 1.0);
|
||||
return { type: ColorTypes.Grayscale, gray: gray };
|
||||
};
|
||||
exports.rgb = function (red, green, blue) {
|
||||
utils_1.assertRange(red, 'red', 0, 1);
|
||||
utils_1.assertRange(green, 'green', 0, 1);
|
||||
utils_1.assertRange(blue, 'blue', 0, 1);
|
||||
return { type: ColorTypes.RGB, red: red, green: green, blue: blue };
|
||||
};
|
||||
exports.cmyk = function (cyan, magenta, yellow, key) {
|
||||
utils_1.assertRange(cyan, 'cyan', 0, 1);
|
||||
utils_1.assertRange(magenta, 'magenta', 0, 1);
|
||||
utils_1.assertRange(yellow, 'yellow', 0, 1);
|
||||
utils_1.assertRange(key, 'key', 0, 1);
|
||||
return { type: ColorTypes.CMYK, cyan: cyan, magenta: magenta, yellow: yellow, key: key };
|
||||
};
|
||||
var Grayscale = ColorTypes.Grayscale, RGB = ColorTypes.RGB, CMYK = ColorTypes.CMYK;
|
||||
// prettier-ignore
|
||||
exports.setFillingColor = function (color) {
|
||||
return color.type === Grayscale ? operators_1.setFillingGrayscaleColor(color.gray)
|
||||
: color.type === RGB ? operators_1.setFillingRgbColor(color.red, color.green, color.blue)
|
||||
: color.type === CMYK ? operators_1.setFillingCmykColor(color.cyan, color.magenta, color.yellow, color.key)
|
||||
: utils_1.error("Invalid color: " + JSON.stringify(color));
|
||||
};
|
||||
// prettier-ignore
|
||||
exports.setStrokingColor = function (color) {
|
||||
return color.type === Grayscale ? operators_1.setStrokingGrayscaleColor(color.gray)
|
||||
: color.type === RGB ? operators_1.setStrokingRgbColor(color.red, color.green, color.blue)
|
||||
: color.type === CMYK ? operators_1.setStrokingCmykColor(color.cyan, color.magenta, color.yellow, color.key)
|
||||
: utils_1.error("Invalid color: " + JSON.stringify(color));
|
||||
};
|
||||
// prettier-ignore
|
||||
exports.componentsToColor = function (comps, scale) {
|
||||
if (scale === void 0) { scale = 1; }
|
||||
return ((comps === null || comps === void 0 ? void 0 : comps.length) === 1 ? exports.grayscale(comps[0] * scale)
|
||||
: (comps === null || comps === void 0 ? void 0 : comps.length) === 3 ? exports.rgb(comps[0] * scale, comps[1] * scale, comps[2] * scale)
|
||||
: (comps === null || comps === void 0 ? void 0 : comps.length) === 4 ? exports.cmyk(comps[0] * scale, comps[1] * scale, comps[2] * scale, comps[3] * scale)
|
||||
: undefined);
|
||||
};
|
||||
// prettier-ignore
|
||||
exports.colorToComponents = function (color) {
|
||||
return color.type === Grayscale ? [color.gray]
|
||||
: color.type === RGB ? [color.red, color.green, color.blue]
|
||||
: color.type === CMYK ? [color.cyan, color.magenta, color.yellow, color.key]
|
||||
: utils_1.error("Invalid color: " + JSON.stringify(color));
|
||||
};
|
||||
//# sourceMappingURL=colors.js.map
|
||||
1
node_modules/pdf-lib/cjs/api/colors.js.map
generated
vendored
Normal file
1
node_modules/pdf-lib/cjs/api/colors.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"colors.js","sourceRoot":"","sources":["../../src/api/colors.ts"],"names":[],"mappings":";;;AAAA,yCAO2B;AAC3B,kCAA+C;AAE/C,IAAY,UAIX;AAJD,WAAY,UAAU;IACpB,qCAAuB,CAAA;IACvB,yBAAW,CAAA;IACX,2BAAa,CAAA;AACf,CAAC,EAJW,UAAU,GAAV,kBAAU,KAAV,kBAAU,QAIrB;AAwBY,QAAA,SAAS,GAAG,UAAC,IAAY;IACpC,mBAAW,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;IACpC,OAAO,EAAE,IAAI,EAAE,UAAU,CAAC,SAAS,EAAE,IAAI,MAAA,EAAE,CAAC;AAC9C,CAAC,CAAC;AAEW,QAAA,GAAG,GAAG,UAAC,GAAW,EAAE,KAAa,EAAE,IAAY;IAC1D,mBAAW,CAAC,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAC9B,mBAAW,CAAC,KAAK,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAClC,mBAAW,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAChC,OAAO,EAAE,IAAI,EAAE,UAAU,CAAC,GAAG,EAAE,GAAG,KAAA,EAAE,KAAK,OAAA,EAAE,IAAI,MAAA,EAAE,CAAC;AACpD,CAAC,CAAC;AAEW,QAAA,IAAI,GAAG,UAClB,IAAY,EACZ,OAAe,EACf,MAAc,EACd,GAAW;IAEX,mBAAW,CAAC,IAAI,EAAE,MAAM,EAA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AhBiE,CAgBjE,CAAC;AAEF,kBAAkB;AACL,QAAA,iBAAiB,GAAG,UAAC,KAAY;IAC1C,OAAA,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC;QACzC,CAAC,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAO,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC;YACjE,CAAC,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAM,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,CAAC;gBACjF,CAAC,CAAC,aAAK,CAAC,oBAAkB,IAAI,CAAC,SAAS,CAAC,KAAK,CAAG,CAAC;AAHhD,CAGgD,CAAC"}
|
||||
43
node_modules/pdf-lib/cjs/api/errors.d.ts
generated
vendored
Normal file
43
node_modules/pdf-lib/cjs/api/errors.d.ts
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
export declare class EncryptedPDFError extends Error {
|
||||
constructor();
|
||||
}
|
||||
export declare class FontkitNotRegisteredError extends Error {
|
||||
constructor();
|
||||
}
|
||||
export declare class ForeignPageError extends Error {
|
||||
constructor();
|
||||
}
|
||||
export declare class RemovePageFromEmptyDocumentError extends Error {
|
||||
constructor();
|
||||
}
|
||||
export declare class NoSuchFieldError extends Error {
|
||||
constructor(name: string);
|
||||
}
|
||||
export declare class UnexpectedFieldTypeError extends Error {
|
||||
constructor(name: string, expected: any, actual: any);
|
||||
}
|
||||
export declare class MissingOnValueCheckError extends Error {
|
||||
constructor(onValue: any);
|
||||
}
|
||||
export declare class FieldAlreadyExistsError extends Error {
|
||||
constructor(name: string);
|
||||
}
|
||||
export declare class InvalidFieldNamePartError extends Error {
|
||||
constructor(namePart: string);
|
||||
}
|
||||
export declare class FieldExistsAsNonTerminalError extends Error {
|
||||
constructor(name: string);
|
||||
}
|
||||
export declare class RichTextFieldReadError extends Error {
|
||||
constructor(fieldName: string);
|
||||
}
|
||||
export declare class CombedTextLayoutError extends Error {
|
||||
constructor(lineLength: number, cellCount: number);
|
||||
}
|
||||
export declare class ExceededMaxLengthError extends Error {
|
||||
constructor(textLength: number, maxLength: number, name: string);
|
||||
}
|
||||
export declare class InvalidMaxLengthError extends Error {
|
||||
constructor(textLength: number, maxLength: number, name: string);
|
||||
}
|
||||
//# sourceMappingURL=errors.d.ts.map
|
||||
1
node_modules/pdf-lib/cjs/api/errors.d.ts.map
generated
vendored
Normal file
1
node_modules/pdf-lib/cjs/api/errors.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/api/errors.ts"],"names":[],"mappings":"AAGA,qBAAa,iBAAkB,SAAQ,KAAK;;CAM3C;AAGD,qBAAa,yBAA0B,SAAQ,KAAK;;CAMnD;AAGD,qBAAa,gBAAiB,SAAQ,KAAK;;CAM1C;AAGD,qBAAa,gCAAiC,SAAQ,KAAK;;CAM1D;AAED,qBAAa,gBAAiB,SAAQ,KAAK;gBAC7B,IAAI,EAAE,MAAM;CAIzB;AAED,qBAAa,wBAAyB,SAAQ,KAAK;gBACrC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG;CAQrD;AAED,qBAAa,wBAAyB,SAAQ,KAAK;gBACrC,OAAO,EAAE,GAAG;CAIzB;AAED,qBAAa,uBAAwB,SAAQ,KAAK;gBACpC,IAAI,EAAE,MAAM;CAIzB;AAED,qBAAa,yBAA0B,SAAQ,KAAK;gBACtC,QAAQ,EAAE,MAAM;CAI7B;AAED,qBAAa,6BAA8B,SAAQ,KAAK;gBAC1C,IAAI,EAAE,MAAM;CAIzB;AAED,qBAAa,sBAAuB,SAAQ,KAAK;gBACnC,SAAS,EAAE,MAAM;CAI9B;AAED,qBAAa,qBAAsB,SAAQ,KAAK;gBAClC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;CAIlD;AAED,qBAAa,sBAAuB,SAAQ,KAAK;gBACnC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;CAIhE;AAED,qBAAa,qBAAsB,SAAQ,KAAK;gBAClC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;CAIhE"}
|
||||
168
node_modules/pdf-lib/cjs/api/errors.js
generated
vendored
Normal file
168
node_modules/pdf-lib/cjs/api/errors.js
generated
vendored
Normal file
@@ -0,0 +1,168 @@
|
||||
"use strict";
|
||||
// tslint:disable: max-classes-per-file
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.InvalidMaxLengthError = exports.ExceededMaxLengthError = exports.CombedTextLayoutError = exports.RichTextFieldReadError = exports.FieldExistsAsNonTerminalError = exports.InvalidFieldNamePartError = exports.FieldAlreadyExistsError = exports.MissingOnValueCheckError = exports.UnexpectedFieldTypeError = exports.NoSuchFieldError = exports.RemovePageFromEmptyDocumentError = exports.ForeignPageError = exports.FontkitNotRegisteredError = exports.EncryptedPDFError = void 0;
|
||||
var tslib_1 = require("tslib");
|
||||
// TODO: Include link to documentation with example
|
||||
var EncryptedPDFError = /** @class */ (function (_super) {
|
||||
tslib_1.__extends(EncryptedPDFError, _super);
|
||||
function EncryptedPDFError() {
|
||||
var _this = this;
|
||||
var msg = 'Input document to `PDFDocument.load` is encrypted. You can use `PDFDocument.load(..., { ignoreEncryption: true })` if you wish to load the document anyways.';
|
||||
_this = _super.call(this, msg) || this;
|
||||
return _this;
|
||||
}
|
||||
return EncryptedPDFError;
|
||||
}(Error));
|
||||
exports.EncryptedPDFError = EncryptedPDFError;
|
||||
// TODO: Include link to documentation with example
|
||||
var FontkitNotRegisteredError = /** @class */ (function (_super) {
|
||||
tslib_1.__extends(FontkitNotRegisteredError, _super);
|
||||
function FontkitNotRegisteredError() {
|
||||
var _this = this;
|
||||
var msg = 'Input to `PDFDocument.embedFont` was a custom font, but no `fontkit` instance was found. You must register a `fontkit` instance with `PDFDocument.registerFontkit(...)` before embedding custom fonts.';
|
||||
_this = _super.call(this, msg) || this;
|
||||
return _this;
|
||||
}
|
||||
return FontkitNotRegisteredError;
|
||||
}(Error));
|
||||
exports.FontkitNotRegisteredError = FontkitNotRegisteredError;
|
||||
// TODO: Include link to documentation with example
|
||||
var ForeignPageError = /** @class */ (function (_super) {
|
||||
tslib_1.__extends(ForeignPageError, _super);
|
||||
function ForeignPageError() {
|
||||
var _this = this;
|
||||
var msg = 'A `page` passed to `PDFDocument.addPage` or `PDFDocument.insertPage` was from a different (foreign) PDF document. If you want to copy pages from one PDFDocument to another, you must use `PDFDocument.copyPages(...)` to copy the pages before adding or inserting them.';
|
||||
_this = _super.call(this, msg) || this;
|
||||
return _this;
|
||||
}
|
||||
return ForeignPageError;
|
||||
}(Error));
|
||||
exports.ForeignPageError = ForeignPageError;
|
||||
// TODO: Include link to documentation with example
|
||||
var RemovePageFromEmptyDocumentError = /** @class */ (function (_super) {
|
||||
tslib_1.__extends(RemovePageFromEmptyDocumentError, _super);
|
||||
function RemovePageFromEmptyDocumentError() {
|
||||
var _this = this;
|
||||
var msg = 'PDFDocument has no pages so `PDFDocument.removePage` cannot be called';
|
||||
_this = _super.call(this, msg) || this;
|
||||
return _this;
|
||||
}
|
||||
return RemovePageFromEmptyDocumentError;
|
||||
}(Error));
|
||||
exports.RemovePageFromEmptyDocumentError = RemovePageFromEmptyDocumentError;
|
||||
var NoSuchFieldError = /** @class */ (function (_super) {
|
||||
tslib_1.__extends(NoSuchFieldError, _super);
|
||||
function NoSuchFieldError(name) {
|
||||
var _this = this;
|
||||
var msg = "PDFDocument has no form field with the name \"" + name + "\"";
|
||||
_this = _super.call(this, msg) || this;
|
||||
return _this;
|
||||
}
|
||||
return NoSuchFieldError;
|
||||
}(Error));
|
||||
exports.NoSuchFieldError = NoSuchFieldError;
|
||||
var UnexpectedFieldTypeError = /** @class */ (function (_super) {
|
||||
tslib_1.__extends(UnexpectedFieldTypeError, _super);
|
||||
function UnexpectedFieldTypeError(name, expected, actual) {
|
||||
var _a, _b;
|
||||
var _this = this;
|
||||
var expectedType = expected === null || expected === void 0 ? void 0 : expected.name;
|
||||
var actualType = (_b = (_a = actual === null || actual === void 0 ? void 0 : actual.constructor) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : actual;
|
||||
var msg = "Expected field \"" + name + "\" to be of type " + expectedType + ", " +
|
||||
("but it is actually of type " + actualType);
|
||||
_this = _super.call(this, msg) || this;
|
||||
return _this;
|
||||
}
|
||||
return UnexpectedFieldTypeError;
|
||||
}(Error));
|
||||
exports.UnexpectedFieldTypeError = UnexpectedFieldTypeError;
|
||||
var MissingOnValueCheckError = /** @class */ (function (_super) {
|
||||
tslib_1.__extends(MissingOnValueCheckError, _super);
|
||||
function MissingOnValueCheckError(onValue) {
|
||||
var _this = this;
|
||||
var msg = "Failed to select check box due to missing onValue: \"" + onValue + "\"";
|
||||
_this = _super.call(this, msg) || this;
|
||||
return _this;
|
||||
}
|
||||
return MissingOnValueCheckError;
|
||||
}(Error));
|
||||
exports.MissingOnValueCheckError = MissingOnValueCheckError;
|
||||
var FieldAlreadyExistsError = /** @class */ (function (_super) {
|
||||
tslib_1.__extends(FieldAlreadyExistsError, _super);
|
||||
function FieldAlreadyExistsError(name) {
|
||||
var _this = this;
|
||||
var msg = "A field already exists with the specified name: \"" + name + "\"";
|
||||
_this = _super.call(this, msg) || this;
|
||||
return _this;
|
||||
}
|
||||
return FieldAlreadyExistsError;
|
||||
}(Error));
|
||||
exports.FieldAlreadyExistsError = FieldAlreadyExistsError;
|
||||
var InvalidFieldNamePartError = /** @class */ (function (_super) {
|
||||
tslib_1.__extends(InvalidFieldNamePartError, _super);
|
||||
function InvalidFieldNamePartError(namePart) {
|
||||
var _this = this;
|
||||
var msg = "Field name contains invalid component: \"" + namePart + "\"";
|
||||
_this = _super.call(this, msg) || this;
|
||||
return _this;
|
||||
}
|
||||
return InvalidFieldNamePartError;
|
||||
}(Error));
|
||||
exports.InvalidFieldNamePartError = InvalidFieldNamePartError;
|
||||
var FieldExistsAsNonTerminalError = /** @class */ (function (_super) {
|
||||
tslib_1.__extends(FieldExistsAsNonTerminalError, _super);
|
||||
function FieldExistsAsNonTerminalError(name) {
|
||||
var _this = this;
|
||||
var msg = "A non-terminal field already exists with the specified name: \"" + name + "\"";
|
||||
_this = _super.call(this, msg) || this;
|
||||
return _this;
|
||||
}
|
||||
return FieldExistsAsNonTerminalError;
|
||||
}(Error));
|
||||
exports.FieldExistsAsNonTerminalError = FieldExistsAsNonTerminalError;
|
||||
var RichTextFieldReadError = /** @class */ (function (_super) {
|
||||
tslib_1.__extends(RichTextFieldReadError, _super);
|
||||
function RichTextFieldReadError(fieldName) {
|
||||
var _this = this;
|
||||
var msg = "Reading rich text fields is not supported: Attempted to read rich text field: " + fieldName;
|
||||
_this = _super.call(this, msg) || this;
|
||||
return _this;
|
||||
}
|
||||
return RichTextFieldReadError;
|
||||
}(Error));
|
||||
exports.RichTextFieldReadError = RichTextFieldReadError;
|
||||
var CombedTextLayoutError = /** @class */ (function (_super) {
|
||||
tslib_1.__extends(CombedTextLayoutError, _super);
|
||||
function CombedTextLayoutError(lineLength, cellCount) {
|
||||
var _this = this;
|
||||
var msg = "Failed to layout combed text as lineLength=" + lineLength + " is greater than cellCount=" + cellCount;
|
||||
_this = _super.call(this, msg) || this;
|
||||
return _this;
|
||||
}
|
||||
return CombedTextLayoutError;
|
||||
}(Error));
|
||||
exports.CombedTextLayoutError = CombedTextLayoutError;
|
||||
var ExceededMaxLengthError = /** @class */ (function (_super) {
|
||||
tslib_1.__extends(ExceededMaxLengthError, _super);
|
||||
function ExceededMaxLengthError(textLength, maxLength, name) {
|
||||
var _this = this;
|
||||
var msg = "Attempted to set text with length=" + textLength + " for TextField with maxLength=" + maxLength + " and name=" + name;
|
||||
_this = _super.call(this, msg) || this;
|
||||
return _this;
|
||||
}
|
||||
return ExceededMaxLengthError;
|
||||
}(Error));
|
||||
exports.ExceededMaxLengthError = ExceededMaxLengthError;
|
||||
var InvalidMaxLengthError = /** @class */ (function (_super) {
|
||||
tslib_1.__extends(InvalidMaxLengthError, _super);
|
||||
function InvalidMaxLengthError(textLength, maxLength, name) {
|
||||
var _this = this;
|
||||
var msg = "Attempted to set maxLength=" + maxLength + ", which is less than " + textLength + ", the length of this field's current value (name=" + name + ")";
|
||||
_this = _super.call(this, msg) || this;
|
||||
return _this;
|
||||
}
|
||||
return InvalidMaxLengthError;
|
||||
}(Error));
|
||||
exports.InvalidMaxLengthError = InvalidMaxLengthError;
|
||||
//# sourceMappingURL=errors.js.map
|
||||
1
node_modules/pdf-lib/cjs/api/errors.js.map
generated
vendored
Normal file
1
node_modules/pdf-lib/cjs/api/errors.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/api/errors.ts"],"names":[],"mappings":";AAAA,uCAAuC;;;;AAEvC,mDAAmD;AACnD;IAAuC,6CAAK;IAC1C;QAAA,iBAIC;QAHC,IAAM,GAAG,GACP,8JAA8J,CAAC;QACjK,QAAA,kBAAM,GAAG,CAAC,SAAC;;IACb,CAAC;IACH,wBAAC;AAAD,CAAC,AAND,CAAuC,KAAK,GAM3C;AANY,8CAAiB;AAQ9B,mDAAmD;AACnD;IAA+C,qDAAK;IAClD;QAAA,iBAIC;QAHC,IAAM,GAAG,GACP,wMAAwM,CAAC;QAC3M,QAAA,kBAAM,GAAG,CAAC,SAAC;;IACb,CAAC;IACH,gCAAC;AAAD,CAAC,AAND,CAA+C,KAAK,GAMnD;AANY,8DAAyB;AAQtC,mDAAmD;AACnD;IAAsC,4CAAK;IACzC;QAAA,iBAIC;QAHC,IAAM,GAAG,GACP,2QAA2Q,CAAC;QAC9Q,QAAA,kBAAM,GAAG,CAAC,S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BAAM,GAAG,CAAC,SAAC;;IACb,CAAC;IACH,6BAAC;AAAD,CAAC,AALD,CAA4C,KAAK,GAKhD;AALY,wDAAsB;AAOnC;IAA2C,iDAAK;IAC9C,+BAAY,UAAkB,EAAE,SAAiB,EAAE,IAAY;QAA/D,iBAGC;QAFC,IAAM,GAAG,GAAG,gCAA8B,SAAS,6BAAwB,UAAU,yDAAoD,IAAI,MAAG,CAAC;QACjJ,QAAA,kBAAM,GAAG,CAAC,SAAC;;IACb,CAAC;IACH,4BAAC;AAAD,CAAC,AALD,CAA2C,KAAK,GAK/C;AALY,sDAAqB"}
|
||||
138
node_modules/pdf-lib/cjs/api/form/PDFButton.d.ts
generated
vendored
Normal file
138
node_modules/pdf-lib/cjs/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/cjs/api/form/PDFButton.d.ts.map
generated
vendored
Normal file
1
node_modules/pdf-lib/cjs/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"}
|
||||
220
node_modules/pdf-lib/cjs/api/form/PDFButton.js
generated
vendored
Normal file
220
node_modules/pdf-lib/cjs/api/form/PDFButton.js
generated
vendored
Normal file
@@ -0,0 +1,220 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var tslib_1 = require("tslib");
|
||||
var PDFPage_1 = tslib_1.__importDefault(require("../PDFPage"));
|
||||
var PDFFont_1 = tslib_1.__importDefault(require("../PDFFont"));
|
||||
var alignment_1 = require("../image/alignment");
|
||||
var appearances_1 = require("./appearances");
|
||||
var PDFField_1 = tslib_1.__importStar(require("./PDFField"));
|
||||
var colors_1 = require("../colors");
|
||||
var rotations_1 = require("../rotations");
|
||||
var core_1 = require("../../core");
|
||||
var utils_1 = require("../../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) {
|
||||
tslib_1.__extends(PDFButton, _super);
|
||||
function PDFButton(acroPushButton, ref, doc) {
|
||||
var _this = _super.call(this, acroPushButton, ref, doc) || this;
|
||||
utils_1.assertIs(acroPushButton, 'acroButton', [
|
||||
[core_1.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 = alignment_1.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) {
|
||||
utils_1.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;
|
||||
utils_1.assertOrUndefined(text, 'text', ['string']);
|
||||
utils_1.assertOrUndefined(page, 'page', [[PDFPage_1.default, 'PDFPage']]);
|
||||
PDFField_1.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 : colors_1.rgb(0, 0, 0),
|
||||
backgroundColor: (_h = options === null || options === void 0 ? void 0 : options.backgroundColor) !== null && _h !== void 0 ? _h : colors_1.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 : rotations_1.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 core_1.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) {
|
||||
utils_1.assertIs(font, 'font', [[PDFFont_1.default, '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) {
|
||||
utils_1.assertIs(font, 'font', [[PDFFont_1.default, 'PDFFont']]);
|
||||
utils_1.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 : appearances_1.defaultButtonAppearanceProvider;
|
||||
var appearances = appearances_1.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_1.default));
|
||||
exports.default = PDFButton;
|
||||
//# sourceMappingURL=PDFButton.js.map
|
||||
1
node_modules/pdf-lib/cjs/api/form/PDFButton.js.map
generated
vendored
Normal file
1
node_modules/pdf-lib/cjs/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,+DAAsC;AACtC,+DAAsC;AAEtC,gDAAyD;AACzD,6CAIkC;AAClC,6DAG+B;AAC/B,oCAAqC;AACrC,0CAA4C;AAE5C,mCAKkB;AAClB,qCAAwE;AAExE;;;;;;;;GAQG;AACH;IAAuC,qCAAQ;IAqB7C,mBACE,cAAiC,EACjC,GAAW,EACX,GAAgB;QAHlB,YAKE,kBAAM,cAAc,EAAE,GAAG,EAAE,GAAG,CAAC,SAOhC;QALC,gBAAQ,CAAC,cAAc,EAAE,YAAY,EAAE;YACrC,CAAC,wBAAiB,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,0BAAc,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,SA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,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,6CAA+B,CAAC;QAC/D,IAAM,WAAW,GAAG,iCAAmB,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,kBAAQ,GAwO9C;kBAxOoB,SAAS"}
|
||||
143
node_modules/pdf-lib/cjs/api/form/PDFCheckBox.d.ts
generated
vendored
Normal file
143
node_modules/pdf-lib/cjs/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/cjs/api/form/PDFCheckBox.d.ts.map
generated
vendored
Normal file
1
node_modules/pdf-lib/cjs/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"}
|
||||
236
node_modules/pdf-lib/cjs/api/form/PDFCheckBox.js
generated
vendored
Normal file
236
node_modules/pdf-lib/cjs/api/form/PDFCheckBox.js
generated
vendored
Normal file
@@ -0,0 +1,236 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var tslib_1 = require("tslib");
|
||||
var PDFPage_1 = tslib_1.__importDefault(require("../PDFPage"));
|
||||
var appearances_1 = require("./appearances");
|
||||
var colors_1 = require("../colors");
|
||||
var rotations_1 = require("../rotations");
|
||||
var PDFField_1 = tslib_1.__importStar(require("./PDFField"));
|
||||
var core_1 = require("../../core");
|
||||
var utils_1 = require("../../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) {
|
||||
tslib_1.__extends(PDFCheckBox, _super);
|
||||
function PDFCheckBox(acroCheckBox, ref, doc) {
|
||||
var _this = _super.call(this, acroCheckBox, ref, doc) || this;
|
||||
utils_1.assertIs(acroCheckBox, 'acroCheckBox', [
|
||||
[core_1.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 : core_1.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(core_1.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;
|
||||
utils_1.assertIs(page, 'page', [[PDFPage_1.default, 'PDFPage']]);
|
||||
PDFField_1.assertFieldAppearanceOptions(options);
|
||||
if (!options)
|
||||
options = {};
|
||||
if (!('textColor' in options))
|
||||
options.textColor = colors_1.rgb(0, 0, 0);
|
||||
if (!('backgroundColor' in options))
|
||||
options.backgroundColor = colors_1.rgb(1, 1, 1);
|
||||
if (!('borderColor' in options))
|
||||
options.borderColor = colors_1.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 : rotations_1.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(core_1.PDFName.of('Off'));
|
||||
this.updateWidgetAppearance(widget, core_1.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 core_1.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;
|
||||
utils_1.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 : core_1.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 : appearances_1.defaultCheckBoxAppearanceProvider;
|
||||
var appearances = appearances_1.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_1.default));
|
||||
exports.default = PDFCheckBox;
|
||||
//# sourceMappingURL=PDFCheckBox.js.map
|
||||
1
node_modules/pdf-lib/cjs/api/form/PDFCheckBox.js.map
generated
vendored
Normal file
1
node_modules/pdf-lib/cjs/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":";;;AACA,+DAAsC;AACtC,6CAIkC;AAClC,oCAAqC;AACrC,0CAA4C;AAC5C,6DAG+B;AAE/B,mCAMkB;AAClB,qCAAwD;AAExD;;;;;;;;GAQG;AACH;IAAyC,uCAAQ;IAkB/C,qBACE,YAA6B,EAC7B,GAAW,EACX,GAAgB;QAHlB,YAKE,kBAAM,YAAY,EAAE,GAAG,EAAE,GAAG,CAAC,SAO9B;QALC,gBAAQ,CAAC,YAAY,EAAE,cAAc,EAAE;YACrC,CAAC,sBAAe,EAAE,iBAAiB,CAAC;SACrC,CAAC,CAAC;QAEH,KAAI,CAAC,SAAS,GAAG,YAAY,CAAC;;IAChC,CAAC;IAED;;;;;;;;;;;;;;;;;;OAkBG;IACH,2BAAK,GAAL;;QACE,IAAM,OAAO,SAAG,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE,mCAAI,cAAO,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;QACjE,IAAI,CAAC,WAAW,EAAE,CAAC;QACnB,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IACnC,CAAC;IAED;;;;;;;;;;;;;;;OAeG;IACH,6BAAO,GAAP;QACE,IAAI,CAAC,WAAW,EAAE,CAAC;QACnB,IAAI,CAAC,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,IAAI,CAAC,2BAA2B,CAAC,MAAM,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC;IACjE,CAAC;IAnOD;;;;;;;;;;OAUG;IACI,cAAE,GAAG,UAAC,YAA6B,EAAE,GAAW,EAAE,GAAgB;QACvE,OAAA,IAAI,WAAW,CAAC,YAAY,EAAE,GAAG,EAAE,GAAG,CAAC;IAAvC,CAAuC,CAAC;IAwN5C,kBAAC;CAAA,AArOD,CAAyC,kBAAQ,GAqOhD;kBArOoB,WAAW"}
|
||||
403
node_modules/pdf-lib/cjs/api/form/PDFDropdown.d.ts
generated
vendored
Normal file
403
node_modules/pdf-lib/cjs/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/cjs/api/form/PDFDropdown.d.ts.map
generated
vendored
Normal file
1
node_modules/pdf-lib/cjs/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"}
|
||||
580
node_modules/pdf-lib/cjs/api/form/PDFDropdown.js
generated
vendored
Normal file
580
node_modules/pdf-lib/cjs/api/form/PDFDropdown.js
generated
vendored
Normal file
@@ -0,0 +1,580 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var tslib_1 = require("tslib");
|
||||
var PDFPage_1 = tslib_1.__importDefault(require("../PDFPage"));
|
||||
var PDFFont_1 = tslib_1.__importDefault(require("../PDFFont"));
|
||||
var PDFField_1 = tslib_1.__importStar(require("./PDFField"));
|
||||
var appearances_1 = require("./appearances");
|
||||
var colors_1 = require("../colors");
|
||||
var rotations_1 = require("../rotations");
|
||||
var core_1 = require("../../core");
|
||||
var utils_1 = require("../../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) {
|
||||
tslib_1.__extends(PDFDropdown, _super);
|
||||
function PDFDropdown(acroComboBox, ref, doc) {
|
||||
var _this = _super.call(this, acroComboBox, ref, doc) || this;
|
||||
utils_1.assertIs(acroComboBox, 'acroComboBox', [
|
||||
[core_1.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) {
|
||||
utils_1.assertIs(options, 'options', [Array]);
|
||||
var optionObjects = new Array(options.length);
|
||||
for (var idx = 0, len = options.length; idx < len; idx++) {
|
||||
optionObjects[idx] = { value: core_1.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) {
|
||||
utils_1.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: core_1.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; }
|
||||
utils_1.assertIs(options, 'options', ['string', Array]);
|
||||
utils_1.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] = core_1.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) {
|
||||
utils_1.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(core_1.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(core_1.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(core_1.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(core_1.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(core_1.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(core_1.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(core_1.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(core_1.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(core_1.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(core_1.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(core_1.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(core_1.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(core_1.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(core_1.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(core_1.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;
|
||||
utils_1.assertIs(page, 'page', [[PDFPage_1.default, 'PDFPage']]);
|
||||
PDFField_1.assertFieldAppearanceOptions(options);
|
||||
if (!options)
|
||||
options = {};
|
||||
if (!('textColor' in options))
|
||||
options.textColor = colors_1.rgb(0, 0, 0);
|
||||
if (!('backgroundColor' in options))
|
||||
options.backgroundColor = colors_1.rgb(1, 1, 1);
|
||||
if (!('borderColor' in options))
|
||||
options.borderColor = colors_1.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 : rotations_1.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 core_1.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) {
|
||||
utils_1.assertIs(font, 'font', [[PDFFont_1.default, '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) {
|
||||
utils_1.assertIs(font, 'font', [[PDFFont_1.default, 'PDFFont']]);
|
||||
utils_1.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 : appearances_1.defaultDropdownAppearanceProvider;
|
||||
var appearances = appearances_1.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_1.default));
|
||||
exports.default = PDFDropdown;
|
||||
//# sourceMappingURL=PDFDropdown.js.map
|
||||
1
node_modules/pdf-lib/cjs/api/form/PDFDropdown.js.map
generated
vendored
Normal file
1
node_modules/pdf-lib/cjs/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/cjs/api/form/PDFField.d.ts
generated
vendored
Normal file
204
node_modules/pdf-lib/cjs/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/cjs/api/form/PDFField.d.ts.map
generated
vendored
Normal file
1
node_modules/pdf-lib/cjs/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":"AAAA,OAAO,WAAW,uBAA4B;AAC9C,OAAO,OAAO,mBAAwB;AACtC,OAAO,EAAE,iBAAiB,EAAE,sBAAiC;AA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KAAE,CAAC;IAUjE,SAAS,CAAC,uBAAuB,CAC/B,MAAM,EAAE,mBAAmB,EAC3B,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,iBAAiB,CAAC,MAAM,GAAG,OAAO,CAAC;IAgCjE,OAAO,CAAC,sBAAsB;IA0B9B;;;;;;;;OAQG;IACH,SAAS,CAAC,2BAA2B,CACnC,MAAM,EAAE,mBAAmB,EAC3B,KAAK,EAAE,QAAQ,EACf,SAAS,EAAE,cAAc,GACxB,MAAM;IAyDT,OAAO,CAAC,oBAAoB;CAgB7B"}
|
||||
384
node_modules/pdf-lib/cjs/api/form/PDFField.js
generated
vendored
Normal file
384
node_modules/pdf-lib/cjs/api/form/PDFField.js
generated
vendored
Normal file
@@ -0,0 +1,384 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.assertFieldAppearanceOptions = void 0;
|
||||
var tslib_1 = require("tslib");
|
||||
var PDFDocument_1 = tslib_1.__importDefault(require("../PDFDocument"));
|
||||
var colors_1 = require("../colors");
|
||||
var rotations_1 = require("../rotations");
|
||||
var core_1 = require("../../core");
|
||||
var utils_1 = require("../../utils");
|
||||
var image_1 = require("../image");
|
||||
var operations_1 = require("../operations");
|
||||
exports.assertFieldAppearanceOptions = function (options) {
|
||||
utils_1.assertOrUndefined(options === null || options === void 0 ? void 0 : options.x, 'options.x', ['number']);
|
||||
utils_1.assertOrUndefined(options === null || options === void 0 ? void 0 : options.y, 'options.y', ['number']);
|
||||
utils_1.assertOrUndefined(options === null || options === void 0 ? void 0 : options.width, 'options.width', ['number']);
|
||||
utils_1.assertOrUndefined(options === null || options === void 0 ? void 0 : options.height, 'options.height', ['number']);
|
||||
utils_1.assertOrUndefined(options === null || options === void 0 ? void 0 : options.textColor, 'options.textColor', [
|
||||
[Object, 'Color'],
|
||||
]);
|
||||
utils_1.assertOrUndefined(options === null || options === void 0 ? void 0 : options.backgroundColor, 'options.backgroundColor', [
|
||||
[Object, 'Color'],
|
||||
]);
|
||||
utils_1.assertOrUndefined(options === null || options === void 0 ? void 0 : options.borderColor, 'options.borderColor', [
|
||||
[Object, 'Color'],
|
||||
]);
|
||||
utils_1.assertOrUndefined(options === null || options === void 0 ? void 0 : options.borderWidth, 'options.borderWidth', ['number']);
|
||||
utils_1.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) {
|
||||
utils_1.assertIs(acroField, 'acroField', [[core_1.PDFAcroTerminal, 'PDFAcroTerminal']]);
|
||||
utils_1.assertIs(ref, 'ref', [[core_1.PDFRef, 'PDFRef']]);
|
||||
utils_1.assertIs(doc, 'doc', [[PDFDocument_1.default, '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(core_1.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(core_1.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(core_1.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(core_1.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(core_1.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(core_1.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(core_1.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(core_1.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(core_1.AcroFieldFlags.NoExport, true);
|
||||
};
|
||||
/** @ignore */
|
||||
PDFField.prototype.needsAppearancesUpdate = function () {
|
||||
throw new core_1.MethodNotImplementedError(this.constructor.name, 'needsAppearancesUpdate');
|
||||
};
|
||||
/** @ignore */
|
||||
PDFField.prototype.defaultUpdateAppearances = function (_font) {
|
||||
throw new core_1.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 = rotations_1.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;
|
||||
utils_1.assertMultiple(degreesAngle, 'degreesAngle', 90);
|
||||
// Create a widget for this field
|
||||
var widget = core_1.PDFWidgetAnnotation.create(this.doc.context, this.ref);
|
||||
// Set widget properties
|
||||
var rect = rotations_1.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(colors_1.colorToComponents(backgroundColor));
|
||||
}
|
||||
ac.setRotation(degreesAngle);
|
||||
if (caption)
|
||||
ac.setCaptions({ normal: caption });
|
||||
if (borderColor)
|
||||
ac.setBorderColor(colors_1.colorToComponents(borderColor));
|
||||
var bs = widget.getOrCreateBorderStyle();
|
||||
if (borderWidth !== undefined)
|
||||
bs.setWidth(borderWidth);
|
||||
widget.setFlagTo(core_1.AnnotationFlags.Print, true);
|
||||
widget.setFlagTo(core_1.AnnotationFlags.Hidden, hidden);
|
||||
widget.setFlagTo(core_1.AnnotationFlags.Invisible, false);
|
||||
// Set acrofield properties
|
||||
if (textColor) {
|
||||
var da = (_a = this.acroField.getDefaultAppearance()) !== null && _a !== void 0 ? _a : '';
|
||||
var newDa = da + '\n' + colors_1.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 = rotations_1.reduceRotation(ap === null || ap === void 0 ? void 0 : ap.getRotation());
|
||||
var rotate = operations_1.rotateInPlace(tslib_1.__assign(tslib_1.__assign({}, rectangle), { rotation: rotation }));
|
||||
var adj = rotations_1.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: rotations_1.degrees(0),
|
||||
xSkew: rotations_1.degrees(0),
|
||||
ySkew: rotations_1.degrees(0),
|
||||
};
|
||||
if (alignment === image_1.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 === image_1.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 = tslib_1.__spreadArrays(rotate, operations_1.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(core_1.PDFName.of('Off'), offStreamRef);
|
||||
return appearanceDict;
|
||||
};
|
||||
return PDFField;
|
||||
}());
|
||||
exports.default = PDFField;
|
||||
//# sourceMappingURL=PDFField.js.map
|
||||
1
node_modules/pdf-lib/cjs/api/form/PDFField.js.map
generated
vendored
Normal file
1
node_modules/pdf-lib/cjs/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/cjs/api/form/PDFForm.d.ts
generated
vendored
Normal file
412
node_modules/pdf-lib/cjs/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/cjs/api/form/PDFForm.d.ts.map
generated
vendored
Normal file
1
node_modules/pdf-lib/cjs/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":"AAAA,OAAO,WAAW,uBAA4B;AAE9C,OAAO,QAAQ,mBAA8B;AAC7C,OAAO,SAAS,oBAA+B;AAC/C,OAAO,WAAW,sBAAiC;AACnD,OAAO,WAAW,sBAAiC;AACnD,OAAO,aAAa,wBAAmC;AACvD,OAAO,aAAa,wBAAmC;AACvD,OAAO,YAAY,uBAAkC;AACrD,OAAO,YAAY,uBAAkC;AAOrD,OAAO,OAAO,mBAAwB;AAStC,OAAO,EACL,WAAW,EAYX,MAAM,EAIP,mBAAiB;AAGlB,MAAM,WAAW,cAAc;IAC7B,sBAAsB,EAAE,OAAO,CAAC;CACjC;AAED;;;;;;;;;;GAUG;AACH,MAAM,CAAC,OAAO,OAAO,OAAO;IAC1B;;;;;;;;;OASG;IACH,MAAM,CAAC,EAAE,aAAc,WAAW,OAAO,WAAW,aACvB;IAE7B,sDAAsD;IACtD,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC;IAE/B,+CAA+C;IAC/C,QAAQ,CAAC,GAAG,EAAE,WAAW,CAAC;IAE1B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAc;IAC1C,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAiB;IAElD,OAAO;IAWP;;;;;;;;;;;;;OAaG;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AI,EAAE,MAAM,GAAG,YAAY;IAc3C;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,OAAO,CAAC,OAAO,GAAE,cAAiD;IAkClE;;;;;;;;;OASG;IACH,WAAW,CAAC,KAAK,EAAE,QAAQ;IA2B3B;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACH,sBAAsB,CAAC,IAAI,CAAC,EAAE,OAAO;IAerC;;;;;;;;;OASG;IACH,gBAAgB,CAAC,QAAQ,EAAE,MAAM;IAKjC;;;;;;;;;OASG;IACH,gBAAgB,CAAC,QAAQ,EAAE,MAAM;IAKjC;;;;;;;;;OASG;IACH,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAKvC,cAAc;IAId,OAAO,CAAC,cAAc;IAmBtB,OAAO,CAAC,uBAAuB;IA0B/B,OAAO,CAAC,wBAAwB;IAwBhC,OAAO,CAAC,eAAe;IAoBvB,OAAO,CAAC,gBAAgB,CAC8B;CACvD"}
|
||||
726
node_modules/pdf-lib/cjs/api/form/PDFForm.js
generated
vendored
Normal file
726
node_modules/pdf-lib/cjs/api/form/PDFForm.js
generated
vendored
Normal file
@@ -0,0 +1,726 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var tslib_1 = require("tslib");
|
||||
var PDFDocument_1 = tslib_1.__importDefault(require("../PDFDocument"));
|
||||
var PDFButton_1 = tslib_1.__importDefault(require("./PDFButton"));
|
||||
var PDFCheckBox_1 = tslib_1.__importDefault(require("./PDFCheckBox"));
|
||||
var PDFDropdown_1 = tslib_1.__importDefault(require("./PDFDropdown"));
|
||||
var PDFOptionList_1 = tslib_1.__importDefault(require("./PDFOptionList"));
|
||||
var PDFRadioGroup_1 = tslib_1.__importDefault(require("./PDFRadioGroup"));
|
||||
var PDFSignature_1 = tslib_1.__importDefault(require("./PDFSignature"));
|
||||
var PDFTextField_1 = tslib_1.__importDefault(require("./PDFTextField"));
|
||||
var errors_1 = require("../errors");
|
||||
var PDFFont_1 = tslib_1.__importDefault(require("../PDFFont"));
|
||||
var StandardFonts_1 = require("../StandardFonts");
|
||||
var operations_1 = require("../operations");
|
||||
var operators_1 = require("../operators");
|
||||
var core_1 = require("../../core");
|
||||
var utils_1 = require("../../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_1.StandardFonts.Helvetica);
|
||||
};
|
||||
utils_1.assertIs(acroForm, 'acroForm', [[core_1.PDFAcroForm, 'PDFAcroForm']]);
|
||||
utils_1.assertIs(doc, 'doc', [[PDFDocument_1.default, 'PDFDocument']]);
|
||||
this.acroForm = acroForm;
|
||||
this.doc = doc;
|
||||
this.dirtyFields = new Set();
|
||||
this.defaultFontCache = utils_1.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(core_1.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(core_1.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) {
|
||||
utils_1.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) {
|
||||
utils_1.assertIs(name, 'name', ['string']);
|
||||
var field = this.getFieldMaybe(name);
|
||||
if (field)
|
||||
return field;
|
||||
throw new errors_1.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) {
|
||||
utils_1.assertIs(name, 'name', ['string']);
|
||||
var field = this.getField(name);
|
||||
if (field instanceof PDFButton_1.default)
|
||||
return field;
|
||||
throw new errors_1.UnexpectedFieldTypeError(name, PDFButton_1.default, 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) {
|
||||
utils_1.assertIs(name, 'name', ['string']);
|
||||
var field = this.getField(name);
|
||||
if (field instanceof PDFCheckBox_1.default)
|
||||
return field;
|
||||
throw new errors_1.UnexpectedFieldTypeError(name, PDFCheckBox_1.default, 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) {
|
||||
utils_1.assertIs(name, 'name', ['string']);
|
||||
var field = this.getField(name);
|
||||
if (field instanceof PDFDropdown_1.default)
|
||||
return field;
|
||||
throw new errors_1.UnexpectedFieldTypeError(name, PDFDropdown_1.default, 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) {
|
||||
utils_1.assertIs(name, 'name', ['string']);
|
||||
var field = this.getField(name);
|
||||
if (field instanceof PDFOptionList_1.default)
|
||||
return field;
|
||||
throw new errors_1.UnexpectedFieldTypeError(name, PDFOptionList_1.default, 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) {
|
||||
utils_1.assertIs(name, 'name', ['string']);
|
||||
var field = this.getField(name);
|
||||
if (field instanceof PDFRadioGroup_1.default)
|
||||
return field;
|
||||
throw new errors_1.UnexpectedFieldTypeError(name, PDFRadioGroup_1.default, 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) {
|
||||
utils_1.assertIs(name, 'name', ['string']);
|
||||
var field = this.getField(name);
|
||||
if (field instanceof PDFSignature_1.default)
|
||||
return field;
|
||||
throw new errors_1.UnexpectedFieldTypeError(name, PDFSignature_1.default, 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) {
|
||||
utils_1.assertIs(name, 'name', ['string']);
|
||||
var field = this.getField(name);
|
||||
if (field instanceof PDFTextField_1.default)
|
||||
return field;
|
||||
throw new errors_1.UnexpectedFieldTypeError(name, PDFTextField_1.default, 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) {
|
||||
utils_1.assertIs(name, 'name', ['string']);
|
||||
var nameParts = splitFieldName(name);
|
||||
var parent = this.findOrCreateNonTerminals(nameParts.nonTerminal);
|
||||
var button = core_1.PDFAcroPushButton.create(this.doc.context);
|
||||
button.setPartialName(nameParts.terminal);
|
||||
addFieldToParent(parent, [button, button.ref], nameParts.terminal);
|
||||
return PDFButton_1.default.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) {
|
||||
utils_1.assertIs(name, 'name', ['string']);
|
||||
var nameParts = splitFieldName(name);
|
||||
var parent = this.findOrCreateNonTerminals(nameParts.nonTerminal);
|
||||
var checkBox = core_1.PDFAcroCheckBox.create(this.doc.context);
|
||||
checkBox.setPartialName(nameParts.terminal);
|
||||
addFieldToParent(parent, [checkBox, checkBox.ref], nameParts.terminal);
|
||||
return PDFCheckBox_1.default.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) {
|
||||
utils_1.assertIs(name, 'name', ['string']);
|
||||
var nameParts = splitFieldName(name);
|
||||
var parent = this.findOrCreateNonTerminals(nameParts.nonTerminal);
|
||||
var comboBox = core_1.PDFAcroComboBox.create(this.doc.context);
|
||||
comboBox.setPartialName(nameParts.terminal);
|
||||
addFieldToParent(parent, [comboBox, comboBox.ref], nameParts.terminal);
|
||||
return PDFDropdown_1.default.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) {
|
||||
utils_1.assertIs(name, 'name', ['string']);
|
||||
var nameParts = splitFieldName(name);
|
||||
var parent = this.findOrCreateNonTerminals(nameParts.nonTerminal);
|
||||
var listBox = core_1.PDFAcroListBox.create(this.doc.context);
|
||||
listBox.setPartialName(nameParts.terminal);
|
||||
addFieldToParent(parent, [listBox, listBox.ref], nameParts.terminal);
|
||||
return PDFOptionList_1.default.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) {
|
||||
utils_1.assertIs(name, 'name', ['string']);
|
||||
var nameParts = splitFieldName(name);
|
||||
var parent = this.findOrCreateNonTerminals(nameParts.nonTerminal);
|
||||
var radioButton = core_1.PDFAcroRadioButton.create(this.doc.context);
|
||||
radioButton.setPartialName(nameParts.terminal);
|
||||
addFieldToParent(parent, [radioButton, radioButton.ref], nameParts.terminal);
|
||||
return PDFRadioGroup_1.default.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) {
|
||||
utils_1.assertIs(name, 'name', ['string']);
|
||||
var nameParts = splitFieldName(name);
|
||||
var parent = this.findOrCreateNonTerminals(nameParts.nonTerminal);
|
||||
var text = core_1.PDFAcroText.create(this.doc.context);
|
||||
text.setPartialName(nameParts.terminal);
|
||||
addFieldToParent(parent, [text, text.ref], nameParts.terminal);
|
||||
return PDFTextField_1.default.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 = tslib_1.__spreadArrays([
|
||||
operators_1.pushGraphicsState(),
|
||||
operators_1.translate(rectangle.x, rectangle.y)
|
||||
], operations_1.rotateInPlace(tslib_1.__assign(tslib_1.__assign({}, rectangle), { rotation: 0 })), [
|
||||
operators_1.drawObject(xObjectKey),
|
||||
operators_1.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 core_1.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) {
|
||||
utils_1.assertOrUndefined(font, 'font', [[PDFFont_1.default, '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) {
|
||||
utils_1.assertOrUndefined(fieldRef, 'fieldRef', [[core_1.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) {
|
||||
utils_1.assertOrUndefined(fieldRef, 'fieldRef', [[core_1.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) {
|
||||
utils_1.assertOrUndefined(fieldRef, 'fieldRef', [[core_1.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 core_1.PDFDict &&
|
||||
(field instanceof PDFCheckBox_1.default || field instanceof PDFRadioGroup_1.default)) {
|
||||
var value = field.acroField.getValue();
|
||||
var ref = (_a = refOrDict.get(value)) !== null && _a !== void 0 ? _a : refOrDict.get(core_1.PDFName.of('Off'));
|
||||
if (ref instanceof core_1.PDFRef) {
|
||||
refOrDict = ref;
|
||||
}
|
||||
}
|
||||
if (!(refOrDict instanceof core_1.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 errors_1.InvalidFieldNamePartError(namePart);
|
||||
var parent_1 = nonTerminal[0], parentRef = nonTerminal[1];
|
||||
var res = this.findNonTerminal(namePart, parent_1);
|
||||
if (res) {
|
||||
nonTerminal = res;
|
||||
}
|
||||
else {
|
||||
var node = core_1.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 core_1.PDFAcroForm
|
||||
? this.acroForm.getFields()
|
||||
: core_1.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 core_1.PDFAcroNonTerminal)
|
||||
return [field, ref];
|
||||
throw new errors_1.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;
|
||||
}());
|
||||
exports.default = PDFForm;
|
||||
var convertToPDFField = function (field, ref, doc) {
|
||||
if (field instanceof core_1.PDFAcroPushButton)
|
||||
return PDFButton_1.default.of(field, ref, doc);
|
||||
if (field instanceof core_1.PDFAcroCheckBox)
|
||||
return PDFCheckBox_1.default.of(field, ref, doc);
|
||||
if (field instanceof core_1.PDFAcroComboBox)
|
||||
return PDFDropdown_1.default.of(field, ref, doc);
|
||||
if (field instanceof core_1.PDFAcroListBox)
|
||||
return PDFOptionList_1.default.of(field, ref, doc);
|
||||
if (field instanceof core_1.PDFAcroText)
|
||||
return PDFTextField_1.default.of(field, ref, doc);
|
||||
if (field instanceof core_1.PDFAcroRadioButton) {
|
||||
return PDFRadioGroup_1.default.of(field, ref, doc);
|
||||
}
|
||||
if (field instanceof core_1.PDFAcroSignature) {
|
||||
return PDFSignature_1.default.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 = core_1.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 errors_1.FieldAlreadyExistsError(partialName);
|
||||
}
|
||||
}
|
||||
parent.addField(fieldRef);
|
||||
field.setParent(parentRef);
|
||||
};
|
||||
//# sourceMappingURL=PDFForm.js.map
|
||||
1
node_modules/pdf-lib/cjs/api/form/PDFForm.js.map
generated
vendored
Normal file
1
node_modules/pdf-lib/cjs/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/cjs/api/form/PDFOptionList.d.ts
generated
vendored
Normal file
336
node_modules/pdf-lib/cjs/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/cjs/api/form/PDFOptionList.d.ts.map
generated
vendored
Normal file
1
node_modules/pdf-lib/cjs/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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C,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"}
|
||||
499
node_modules/pdf-lib/cjs/api/form/PDFOptionList.js
generated
vendored
Normal file
499
node_modules/pdf-lib/cjs/api/form/PDFOptionList.js
generated
vendored
Normal file
@@ -0,0 +1,499 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var tslib_1 = require("tslib");
|
||||
var PDFPage_1 = tslib_1.__importDefault(require("../PDFPage"));
|
||||
var PDFFont_1 = tslib_1.__importDefault(require("../PDFFont"));
|
||||
var PDFField_1 = tslib_1.__importStar(require("./PDFField"));
|
||||
var appearances_1 = require("./appearances");
|
||||
var colors_1 = require("../colors");
|
||||
var rotations_1 = require("../rotations");
|
||||
var core_1 = require("../../core");
|
||||
var utils_1 = require("../../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) {
|
||||
tslib_1.__extends(PDFOptionList, _super);
|
||||
function PDFOptionList(acroListBox, ref, doc) {
|
||||
var _this = _super.call(this, acroListBox, ref, doc) || this;
|
||||
utils_1.assertIs(acroListBox, 'acroListBox', [[core_1.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) {
|
||||
utils_1.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: core_1.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) {
|
||||
utils_1.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: core_1.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; }
|
||||
utils_1.assertIs(options, 'options', ['string', Array]);
|
||||
utils_1.assertIs(merge, 'merge', ['boolean']);
|
||||
var optionsArr = Array.isArray(options) ? options : [options];
|
||||
var validOptions = this.getOptions();
|
||||
utils_1.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] = core_1.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) {
|
||||
utils_1.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(core_1.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(core_1.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(core_1.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(core_1.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(core_1.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(core_1.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(core_1.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(core_1.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(core_1.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;
|
||||
utils_1.assertIs(page, 'page', [[PDFPage_1.default, 'PDFPage']]);
|
||||
PDFField_1.assertFieldAppearanceOptions(options);
|
||||
if (!options)
|
||||
options = {};
|
||||
if (!('textColor' in options))
|
||||
options.textColor = colors_1.rgb(0, 0, 0);
|
||||
if (!('backgroundColor' in options))
|
||||
options.backgroundColor = colors_1.rgb(1, 1, 1);
|
||||
if (!('borderColor' in options))
|
||||
options.borderColor = colors_1.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 : rotations_1.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 core_1.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) {
|
||||
utils_1.assertIs(font, 'font', [[PDFFont_1.default, '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) {
|
||||
utils_1.assertIs(font, 'font', [[PDFFont_1.default, 'PDFFont']]);
|
||||
utils_1.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 : appearances_1.defaultOptionListAppearanceProvider;
|
||||
var appearances = appearances_1.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_1.default));
|
||||
exports.default = PDFOptionList;
|
||||
//# sourceMappingURL=PDFOptionList.js.map
|
||||
1
node_modules/pdf-lib/cjs/api/form/PDFOptionList.js.map
generated
vendored
Normal file
1
node_modules/pdf-lib/cjs/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/cjs/api/form/PDFRadioGroup.d.ts
generated
vendored
Normal file
253
node_modules/pdf-lib/cjs/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/cjs/api/form/PDFRadioGroup.d.ts.map
generated
vendored
Normal file
1
node_modules/pdf-lib/cjs/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"}
|
||||
415
node_modules/pdf-lib/cjs/api/form/PDFRadioGroup.js
generated
vendored
Normal file
415
node_modules/pdf-lib/cjs/api/form/PDFRadioGroup.js
generated
vendored
Normal file
@@ -0,0 +1,415 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var tslib_1 = require("tslib");
|
||||
var PDFPage_1 = tslib_1.__importDefault(require("../PDFPage"));
|
||||
var PDFField_1 = tslib_1.__importStar(require("./PDFField"));
|
||||
var appearances_1 = require("./appearances");
|
||||
var colors_1 = require("../colors");
|
||||
var rotations_1 = require("../rotations");
|
||||
var core_1 = require("../../core");
|
||||
var utils_1 = require("../../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) {
|
||||
tslib_1.__extends(PDFRadioGroup, _super);
|
||||
function PDFRadioGroup(acroRadioButton, ref, doc) {
|
||||
var _this = _super.call(this, acroRadioButton, ref, doc) || this;
|
||||
utils_1.assertIs(acroRadioButton, 'acroRadioButton', [
|
||||
[core_1.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 === core_1.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) {
|
||||
utils_1.assertIs(option, 'option', ['string']);
|
||||
var validOptions = this.getOptions();
|
||||
utils_1.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(core_1.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(core_1.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(core_1.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(core_1.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(core_1.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(core_1.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(core_1.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;
|
||||
utils_1.assertIs(option, 'option', ['string']);
|
||||
utils_1.assertIs(page, 'page', [[PDFPage_1.default, 'PDFPage']]);
|
||||
PDFField_1.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 : colors_1.rgb(0, 0, 0),
|
||||
backgroundColor: (_f = options === null || options === void 0 ? void 0 : options.backgroundColor) !== null && _f !== void 0 ? _f : colors_1.rgb(1, 1, 1),
|
||||
borderColor: (_g = options === null || options === void 0 ? void 0 : options.borderColor) !== null && _g !== void 0 ? _g : colors_1.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 : rotations_1.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, core_1.PDFHexString.fromText(option), !this.isMutuallyExclusive());
|
||||
// Set appearance streams for widget
|
||||
widget.setAppearanceState(core_1.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 core_1.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) {
|
||||
utils_1.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 : appearances_1.defaultRadioGroupAppearanceProvider;
|
||||
var appearances = appearances_1.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_1.default));
|
||||
exports.default = PDFRadioGroup;
|
||||
//# sourceMappingURL=PDFRadioGroup.js.map
|
||||
1
node_modules/pdf-lib/cjs/api/form/PDFRadioGroup.js.map
generated
vendored
Normal file
1
node_modules/pdf-lib/cjs/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/cjs/api/form/PDFSignature.d.ts
generated
vendored
Normal file
30
node_modules/pdf-lib/cjs/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/cjs/api/form/PDFSignature.d.ts.map
generated
vendored
Normal file
1
node_modules/pdf-lib/cjs/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"}
|
||||
43
node_modules/pdf-lib/cjs/api/form/PDFSignature.js
generated
vendored
Normal file
43
node_modules/pdf-lib/cjs/api/form/PDFSignature.js
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var tslib_1 = require("tslib");
|
||||
var PDFField_1 = tslib_1.__importDefault(require("./PDFField"));
|
||||
var core_1 = require("../../core");
|
||||
var utils_1 = require("../../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) {
|
||||
tslib_1.__extends(PDFSignature, _super);
|
||||
function PDFSignature(acroSignature, ref, doc) {
|
||||
var _this = _super.call(this, acroSignature, ref, doc) || this;
|
||||
utils_1.assertIs(acroSignature, 'acroSignature', [
|
||||
[core_1.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_1.default));
|
||||
exports.default = PDFSignature;
|
||||
//# sourceMappingURL=PDFSignature.js.map
|
||||
1
node_modules/pdf-lib/cjs/api/form/PDFSignature.js.map
generated
vendored
Normal file
1
node_modules/pdf-lib/cjs/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,gEAA6C;AAE7C,mCAAoD;AACpD,qCAAqC;AAErC;;;;;;GAMG;AACH;IAA0C,wCAAQ;IAsBhD,sBACE,aAA+B,EAC/B,GAAW,EACX,GAAgB;QAHlB,YAKE,kBAAM,aAAa,EAAE,GAAG,EAAE,GAAG,CAAC,SAO/B;QALC,gBAAQ,CAAC,aAAa,EAAE,eAAe,EAAE;YACvC,CAAC,uBAAgB,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,kBAAQ,GAuCjD;kBAvCoB,YAAY"}
|
||||
538
node_modules/pdf-lib/cjs/api/form/PDFTextField.d.ts
generated
vendored
Normal file
538
node_modules/pdf-lib/cjs/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/cjs/api/form/PDFTextField.d.ts.map
generated
vendored
Normal file
1
node_modules/pdf-lib/cjs/api/form/PDFTextField.d.ts.map
generated
vendored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-lib/cjs/api/form/PDFTextField.js
generated
vendored
Normal file
739
node_modules/pdf-lib/cjs/api/form/PDFTextField.js
generated
vendored
Normal file
@@ -0,0 +1,739 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var tslib_1 = require("tslib");
|
||||
var PDFPage_1 = tslib_1.__importDefault(require("../PDFPage"));
|
||||
var PDFFont_1 = tslib_1.__importDefault(require("../PDFFont"));
|
||||
var PDFField_1 = tslib_1.__importStar(require("./PDFField"));
|
||||
var appearances_1 = require("./appearances");
|
||||
var colors_1 = require("../colors");
|
||||
var rotations_1 = require("../rotations");
|
||||
var errors_1 = require("../errors");
|
||||
var alignment_1 = require("../image/alignment");
|
||||
var alignment_2 = require("../text/alignment");
|
||||
var core_1 = require("../../core");
|
||||
var utils_1 = require("../../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) {
|
||||
tslib_1.__extends(PDFTextField, _super);
|
||||
function PDFTextField(acroText, ref, doc) {
|
||||
var _this = _super.call(this, acroText, ref, doc) || this;
|
||||
utils_1.assertIs(acroText, 'acroText', [[core_1.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 errors_1.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) {
|
||||
utils_1.assertOrUndefined(text, 'text', ['string']);
|
||||
var maxLength = this.getMaxLength();
|
||||
if (maxLength !== undefined && text && text.length > maxLength) {
|
||||
throw new errors_1.ExceededMaxLengthError(text.length, maxLength, this.getName());
|
||||
}
|
||||
this.markAsDirty();
|
||||
this.disableRichFormatting();
|
||||
if (text) {
|
||||
this.acroField.setValue(core_1.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 ? alignment_2.TextAlignment.Left
|
||||
: quadding === 1 ? alignment_2.TextAlignment.Center
|
||||
: quadding === 2 ? alignment_2.TextAlignment.Right
|
||||
: alignment_2.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) {
|
||||
utils_1.assertIsOneOf(alignment, 'alignment', alignment_2.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) {
|
||||
utils_1.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 errors_1.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 === alignment_2.TextAlignment.Center ? alignment_1.ImageAlignment.Center
|
||||
: fieldAlignment === alignment_2.TextAlignment.Right ? alignment_1.ImageAlignment.Right
|
||||
: alignment_1.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) {
|
||||
utils_1.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(core_1.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(core_1.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(core_1.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(core_1.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(core_1.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(core_1.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(core_1.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(core_1.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(core_1.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(core_1.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(core_1.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(core_1.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(core_1.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(core_1.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(core_1.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(core_1.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(core_1.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(core_1.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(core_1.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(core_1.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(core_1.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;
|
||||
utils_1.assertIs(page, 'page', [[PDFPage_1.default, 'PDFPage']]);
|
||||
PDFField_1.assertFieldAppearanceOptions(options);
|
||||
if (!options)
|
||||
options = {};
|
||||
if (!('textColor' in options))
|
||||
options.textColor = colors_1.rgb(0, 0, 0);
|
||||
if (!('backgroundColor' in options))
|
||||
options.backgroundColor = colors_1.rgb(1, 1, 1);
|
||||
if (!('borderColor' in options))
|
||||
options.borderColor = colors_1.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 : rotations_1.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 core_1.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) {
|
||||
utils_1.assertIs(font, 'font', [[PDFFont_1.default, '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) {
|
||||
utils_1.assertIs(font, 'font', [[PDFFont_1.default, 'PDFFont']]);
|
||||
utils_1.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 : appearances_1.defaultTextFieldAppearanceProvider;
|
||||
var appearances = appearances_1.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_1.default));
|
||||
exports.default = PDFTextField;
|
||||
//# sourceMappingURL=PDFTextField.js.map
|
||||
1
node_modules/pdf-lib/cjs/api/form/PDFTextField.js.map
generated
vendored
Normal file
1
node_modules/pdf-lib/cjs/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/cjs/api/form/appearances.d.ts
generated
vendored
Normal file
42
node_modules/pdf-lib/cjs/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/cjs/api/form/appearances.d.ts.map
generated
vendored
Normal file
1
node_modules/pdf-lib/cjs/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":"AAAA,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,mBAAiB;AAC5D,OAAO,OAAO,mBAAwB;AACtC,OAAO,SAAS,oBAA+B;AAC/C,OAAO,WAAW,sBAAiC;AACnD,OAAO,WAAW,sBAAiC;AACnD,OAAO,QAAQ,mBAA8B;AAC7C,OAAO,aAAa,wBAAmC;AACvD,OAAO,aAAa,wBAAmC;AACvD,OAAO,YAAY,uBAAkC;AACrD,OAAO,YAAY,uBAAkC;AA4BrD,gFAAgF;AAEhF,aAAK,0BAA0B,GAAG,CAChC,QAAQ,EAAE,WAAW,EACrB,MAAM,EAAE,mB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,CAAC,IAAI,CAAC,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAAC;AAGvD,oBAAY,qBAAqB,CAAC,CAAC,SAAS,QAAQ,IAClD,CAAC,SAAS,WAAW,GAAK,0BAA0B,GACpD,CAAC,SAAS,aAAa,GAAG,4BAA4B,GACtD,CAAC,SAAS,SAAS,GAAO,wBAAwB,GAClD,CAAC,SAAS,WAAW,GAAK,0BAA0B,GACpD,CAAC,SAAS,aAAa,GAAG,4BAA4B,GACtD,CAAC,SAAS,YAAY,GAAI,2BAA2B,GACrD,CAAC,SAAS,YAAY,GAAI,2BAA2B,GACrD,KAAK,CAAC;AAER,gFAAgF;AAEhF,eAAO,MAAM,mBAAmB,mEAK/B,CAAC;AAwDF,eAAO,MAAM,iCAAiC,EAAE,qBAAqB,CAAC,WAAW,CAgFhF,CAAC;AAEF,eAAO,MAAM,mCAAmC,EAAE,qBAAqB,CAAC,aAAa,CA+EpF,CAAC;AAEF,eAAO,MAAM,+BAA+B,EAAE,qBAAqB,CAAC,SAAS,CAwF5E,CAAC;AAEF,eAAO,MAAM,kCAAkC,EAAE,qBAAqB,CAAC,YAAY,CA0FlF,CAAC;AAEF,eAAO,MAAM,iCAAiC,EAAE,qBAAqB,CAAC,WAAW,CAiEhF,CAAC;AAEF,eAAO,MAAM,mCAAmC,EAAE,qBAAqB,CAAC,aAAa,CAuFpF,CAAC"}
|
||||
421
node_modules/pdf-lib/cjs/api/form/appearances.js
generated
vendored
Normal file
421
node_modules/pdf-lib/cjs/api/form/appearances.js
generated
vendored
Normal file
@@ -0,0 +1,421 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.defaultOptionListAppearanceProvider = exports.defaultDropdownAppearanceProvider = exports.defaultTextFieldAppearanceProvider = exports.defaultButtonAppearanceProvider = exports.defaultRadioGroupAppearanceProvider = exports.defaultCheckBoxAppearanceProvider = exports.normalizeAppearance = void 0;
|
||||
var tslib_1 = require("tslib");
|
||||
var operations_1 = require("../operations");
|
||||
var colors_1 = require("../colors");
|
||||
var rotations_1 = require("../rotations");
|
||||
var layout_1 = require("../text/layout");
|
||||
var alignment_1 = require("../text/alignment");
|
||||
var operators_1 = require("../operators");
|
||||
var utils_1 = require("../../utils");
|
||||
/********************* Appearance Provider Functions **************************/
|
||||
exports.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 = utils_1.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 = utils_1.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 colors_1.grayscale(Number(c1));
|
||||
}
|
||||
if (colorSpace === 'rg' && c1 && c2 && c3) {
|
||||
return colors_1.rgb(Number(c1), Number(c2), Number(c3));
|
||||
}
|
||||
if (colorSpace === 'k' && c1 && c2 && c3 && c4) {
|
||||
return colors_1.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 = [
|
||||
colors_1.setFillingColor(color).toString(),
|
||||
operators_1.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);
|
||||
};
|
||||
exports.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 = rotations_1.reduceRotation(ap === null || ap === void 0 ? void 0 : ap.getRotation());
|
||||
var _d = rotations_1.adjustDimsForRotation(rectangle, rotation), width = _d.width, height = _d.height;
|
||||
var rotate = operations_1.rotateInPlace(tslib_1.__assign(tslib_1.__assign({}, rectangle), { rotation: rotation }));
|
||||
var black = colors_1.rgb(0, 0, 0);
|
||||
var borderColor = (_b = colors_1.componentsToColor(ap === null || ap === void 0 ? void 0 : ap.getBorderColor())) !== null && _b !== void 0 ? _b : black;
|
||||
var normalBackgroundColor = colors_1.componentsToColor(ap === null || ap === void 0 ? void 0 : ap.getBackgroundColor());
|
||||
var downBackgroundColor = colors_1.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: tslib_1.__spreadArrays(rotate, operations_1.drawCheckBox(tslib_1.__assign(tslib_1.__assign({}, options), { color: normalBackgroundColor, filled: true }))),
|
||||
off: tslib_1.__spreadArrays(rotate, operations_1.drawCheckBox(tslib_1.__assign(tslib_1.__assign({}, options), { color: normalBackgroundColor, filled: false }))),
|
||||
},
|
||||
down: {
|
||||
on: tslib_1.__spreadArrays(rotate, operations_1.drawCheckBox(tslib_1.__assign(tslib_1.__assign({}, options), { color: downBackgroundColor, filled: true }))),
|
||||
off: tslib_1.__spreadArrays(rotate, operations_1.drawCheckBox(tslib_1.__assign(tslib_1.__assign({}, options), { color: downBackgroundColor, filled: false }))),
|
||||
},
|
||||
};
|
||||
};
|
||||
exports.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 = rotations_1.reduceRotation(ap === null || ap === void 0 ? void 0 : ap.getRotation());
|
||||
var _d = rotations_1.adjustDimsForRotation(rectangle, rotation), width = _d.width, height = _d.height;
|
||||
var rotate = operations_1.rotateInPlace(tslib_1.__assign(tslib_1.__assign({}, rectangle), { rotation: rotation }));
|
||||
var black = colors_1.rgb(0, 0, 0);
|
||||
var borderColor = (_b = colors_1.componentsToColor(ap === null || ap === void 0 ? void 0 : ap.getBorderColor())) !== null && _b !== void 0 ? _b : black;
|
||||
var normalBackgroundColor = colors_1.componentsToColor(ap === null || ap === void 0 ? void 0 : ap.getBackgroundColor());
|
||||
var downBackgroundColor = colors_1.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: tslib_1.__spreadArrays(rotate, operations_1.drawRadioButton(tslib_1.__assign(tslib_1.__assign({}, options), { color: normalBackgroundColor, filled: true }))),
|
||||
off: tslib_1.__spreadArrays(rotate, operations_1.drawRadioButton(tslib_1.__assign(tslib_1.__assign({}, options), { color: normalBackgroundColor, filled: false }))),
|
||||
},
|
||||
down: {
|
||||
on: tslib_1.__spreadArrays(rotate, operations_1.drawRadioButton(tslib_1.__assign(tslib_1.__assign({}, options), { color: downBackgroundColor, filled: true }))),
|
||||
off: tslib_1.__spreadArrays(rotate, operations_1.drawRadioButton(tslib_1.__assign(tslib_1.__assign({}, options), { color: downBackgroundColor, filled: false }))),
|
||||
},
|
||||
};
|
||||
};
|
||||
exports.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 = rotations_1.reduceRotation(ap === null || ap === void 0 ? void 0 : ap.getRotation());
|
||||
var _f = rotations_1.adjustDimsForRotation(rectangle, rotation), width = _f.width, height = _f.height;
|
||||
var rotate = operations_1.rotateInPlace(tslib_1.__assign(tslib_1.__assign({}, rectangle), { rotation: rotation }));
|
||||
var black = colors_1.rgb(0, 0, 0);
|
||||
var borderColor = colors_1.componentsToColor(ap === null || ap === void 0 ? void 0 : ap.getBorderColor());
|
||||
var normalBackgroundColor = colors_1.componentsToColor(ap === null || ap === void 0 ? void 0 : ap.getBackgroundColor());
|
||||
var downBackgroundColor = colors_1.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 = layout_1.layoutSinglelineText(normalText, {
|
||||
alignment: alignment_1.TextAlignment.Center,
|
||||
fontSize: widgetFontSize !== null && widgetFontSize !== void 0 ? widgetFontSize : fieldFontSize,
|
||||
font: font,
|
||||
bounds: bounds,
|
||||
});
|
||||
var downLayout = layout_1.layoutSinglelineText(downText, {
|
||||
alignment: alignment_1.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: tslib_1.__spreadArrays(rotate, operations_1.drawButton(tslib_1.__assign(tslib_1.__assign({}, options), { color: normalBackgroundColor, textLines: [normalLayout.line] }))),
|
||||
down: tslib_1.__spreadArrays(rotate, operations_1.drawButton(tslib_1.__assign(tslib_1.__assign({}, options), { color: downBackgroundColor, textLines: [downLayout.line] }))),
|
||||
};
|
||||
};
|
||||
exports.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 = rotations_1.reduceRotation(ap === null || ap === void 0 ? void 0 : ap.getRotation());
|
||||
var _e = rotations_1.adjustDimsForRotation(rectangle, rotation), width = _e.width, height = _e.height;
|
||||
var rotate = operations_1.rotateInPlace(tslib_1.__assign(tslib_1.__assign({}, rectangle), { rotation: rotation }));
|
||||
var black = colors_1.rgb(0, 0, 0);
|
||||
var borderColor = colors_1.componentsToColor(ap === null || ap === void 0 ? void 0 : ap.getBorderColor());
|
||||
var normalBackgroundColor = colors_1.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 = layout_1.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 = layout_1.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 = layout_1.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 tslib_1.__spreadArrays(rotate, operations_1.drawTextField(options));
|
||||
};
|
||||
exports.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 = rotations_1.reduceRotation(ap === null || ap === void 0 ? void 0 : ap.getRotation());
|
||||
var _d = rotations_1.adjustDimsForRotation(rectangle, rotation), width = _d.width, height = _d.height;
|
||||
var rotate = operations_1.rotateInPlace(tslib_1.__assign(tslib_1.__assign({}, rectangle), { rotation: rotation }));
|
||||
var black = colors_1.rgb(0, 0, 0);
|
||||
var borderColor = colors_1.componentsToColor(ap === null || ap === void 0 ? void 0 : ap.getBorderColor());
|
||||
var normalBackgroundColor = colors_1.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 = layout_1.layoutSinglelineText(text, {
|
||||
alignment: alignment_1.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 tslib_1.__spreadArrays(rotate, operations_1.drawTextField(options));
|
||||
};
|
||||
exports.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 = rotations_1.reduceRotation(ap === null || ap === void 0 ? void 0 : ap.getRotation());
|
||||
var _c = rotations_1.adjustDimsForRotation(rectangle, rotation), width = _c.width, height = _c.height;
|
||||
var rotate = operations_1.rotateInPlace(tslib_1.__assign(tslib_1.__assign({}, rectangle), { rotation: rotation }));
|
||||
var black = colors_1.rgb(0, 0, 0);
|
||||
var borderColor = colors_1.componentsToColor(ap === null || ap === void 0 ? void 0 : ap.getBorderColor());
|
||||
var normalBackgroundColor = colors_1.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 = layout_1.layoutMultilineText(text, {
|
||||
alignment: alignment_1.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 = colors_1.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 tslib_1.__spreadArrays(rotate, operations_1.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/cjs/api/form/appearances.js.map
generated
vendored
Normal file
1
node_modules/pdf-lib/cjs/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/cjs/api/form/index.d.ts
generated
vendored
Normal file
11
node_modules/pdf-lib/cjs/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/cjs/api/form/index.d.ts.map
generated
vendored
Normal file
1
node_modules/pdf-lib/cjs/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"}
|
||||
23
node_modules/pdf-lib/cjs/api/form/index.js
generated
vendored
Normal file
23
node_modules/pdf-lib/cjs/api/form/index.js
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var tslib_1 = require("tslib");
|
||||
tslib_1.__exportStar(require("./appearances"), exports);
|
||||
var PDFButton_1 = require("./PDFButton");
|
||||
Object.defineProperty(exports, "PDFButton", { enumerable: true, get: function () { return PDFButton_1.default; } });
|
||||
var PDFCheckBox_1 = require("./PDFCheckBox");
|
||||
Object.defineProperty(exports, "PDFCheckBox", { enumerable: true, get: function () { return PDFCheckBox_1.default; } });
|
||||
var PDFDropdown_1 = require("./PDFDropdown");
|
||||
Object.defineProperty(exports, "PDFDropdown", { enumerable: true, get: function () { return PDFDropdown_1.default; } });
|
||||
var PDFField_1 = require("./PDFField");
|
||||
Object.defineProperty(exports, "PDFField", { enumerable: true, get: function () { return PDFField_1.default; } });
|
||||
var PDFForm_1 = require("./PDFForm");
|
||||
Object.defineProperty(exports, "PDFForm", { enumerable: true, get: function () { return PDFForm_1.default; } });
|
||||
var PDFOptionList_1 = require("./PDFOptionList");
|
||||
Object.defineProperty(exports, "PDFOptionList", { enumerable: true, get: function () { return PDFOptionList_1.default; } });
|
||||
var PDFRadioGroup_1 = require("./PDFRadioGroup");
|
||||
Object.defineProperty(exports, "PDFRadioGroup", { enumerable: true, get: function () { return PDFRadioGroup_1.default; } });
|
||||
var PDFSignature_1 = require("./PDFSignature");
|
||||
Object.defineProperty(exports, "PDFSignature", { enumerable: true, get: function () { return PDFSignature_1.default; } });
|
||||
var PDFTextField_1 = require("./PDFTextField");
|
||||
Object.defineProperty(exports, "PDFTextField", { enumerable: true, get: function () { return PDFTextField_1.default; } });
|
||||
//# sourceMappingURL=index.js.map
|
||||
1
node_modules/pdf-lib/cjs/api/form/index.js.map
generated
vendored
Normal file
1
node_modules/pdf-lib/cjs/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,wDAAyC;AACzC,yCAA8D;AAArD,sGAAA,OAAO,OAAa;AAC7B,6CAAkE;AAAzD,0GAAA,OAAO,OAAe;AAC/B,6CAAkE;AAAzD,0GAAA,OAAO,OAAe;AAC/B,uCAA4D;AAAnD,oGAAA,OAAO,OAAY;AAC5B,qCAA0D;AAAjD,kGAAA,OAAO,OAAW;AAC3B,iDAAsE;AAA7D,8GAAA,OAAO,OAAiB;AACjC,iDAAsE;AAA7D,8GAAA,OAAO,OAAiB;AACjC,+CAAoE;AAA3D,4GAAA,OAAO,OAAgB;AAChC,+CAAoE;AAA3D,4GAAA,OAAO,OAAgB"}
|
||||
6
node_modules/pdf-lib/cjs/api/image/alignment.d.ts
generated
vendored
Normal file
6
node_modules/pdf-lib/cjs/api/image/alignment.d.ts
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
export declare enum ImageAlignment {
|
||||
Left = 0,
|
||||
Center = 1,
|
||||
Right = 2
|
||||
}
|
||||
//# sourceMappingURL=alignment.d.ts.map
|
||||
1
node_modules/pdf-lib/cjs/api/image/alignment.d.ts.map
generated
vendored
Normal file
1
node_modules/pdf-lib/cjs/api/image/alignment.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"alignment.d.ts","sourceRoot":"","sources":["../../../src/api/image/alignment.ts"],"names":[],"mappings":"AAAA,oBAAY,cAAc;IACxB,IAAI,IAAI;IACR,MAAM,IAAI;IACV,KAAK,IAAI;CACV"}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user