-
-
Notifications
You must be signed in to change notification settings - Fork 1
PDFProvider.js
PDFProvider module
Author: William Leemans
Copyright: William Leemans 2024
-
PDFProvider
-
.pdfProvider ⇐
baseProvider
- new exports.pdfProvider(actor)
-
.convertHexColorToRgb(hex) ⇒
array
-
.createFile() ⇒
undefined
- .defaultFont(font, size, lineHeight)
- .defaultFontColor(color)
- .embedImage(pdf, imageData)
-
.embedFont(pdf, fileName) ⇒
CustomFontEmbedder
- .embedTextBox(pdf, textBoxData)
- .field(file, name, value, options)
-
.fieldExists(file, name) ⇒
boolean
-
.getField(file, name) ⇒
string
|boolean
|undefined
-
.getFieldValue(file, name, defaultValue) ⇒
string
|boolean
-
.getFieldOptions(file, name, optionName) ⇒
Object
|string
|boolean
|number
- .image(file, page, x, y, path, maxWidth, maxHeight, options)
- .updateFile()
- .parseValue(value, parser) ⇒
- .textBox(reference, file, page, x, y, width, height, text, options)
-
.pdfProvider ⇐
A class to manipulate PDF files. Fills out forms created text boxes and adds images.
You should use:
- pdfProvider.field to add form field text
- pdfProvider.image to add images
- pdfProvider.textBox to add text boxes
Kind: static class of PDFProvider
Extends: baseProvider
Requires: module:pdf-lib
, module:fontkit
-
.pdfProvider ⇐
baseProvider
- new exports.pdfProvider(actor)
-
.convertHexColorToRgb(hex) ⇒
array
-
.createFile() ⇒
undefined
- .defaultFont(font, size, lineHeight)
- .defaultFontColor(color)
- .embedImage(pdf, imageData)
-
.embedFont(pdf, fileName) ⇒
CustomFontEmbedder
- .embedTextBox(pdf, textBoxData)
- .field(file, name, value, options)
-
.fieldExists(file, name) ⇒
boolean
-
.getField(file, name) ⇒
string
|boolean
|undefined
-
.getFieldValue(file, name, defaultValue) ⇒
string
|boolean
-
.getFieldOptions(file, name, optionName) ⇒
Object
|string
|boolean
|number
- .image(file, page, x, y, path, maxWidth, maxHeight, options)
- .updateFile()
- .parseValue(value, parser) ⇒
- .textBox(reference, file, page, x, y, width, height, text, options)
Param | Type | Description |
---|---|---|
actor | Object |
The Foundry VTT actor object. |
Convert Hexadecimal color (HTML) to RGB
Kind: instance method of pdfProvider
Returns: array
- the RGB color code in % for each of the main colors, or the color code for black
Param | Type | Description |
---|---|---|
hex | string |
The hexadecimal value (html color) representing a color |
Create a file when no file is associated with the provider sheet
Kind: instance method of pdfProvider
Set the default font, size and lineheight for text boxes
Kind: instance method of pdfProvider
Param | Type | Description |
---|---|---|
font | string |
The name of the font file |
size | number |
The size of the font, expressed in % of the page height. |
lineHeight | number |
The lineheight of the font, expressed in % of the page height. |
Set the default font color for text boxes
Kind: instance method of pdfProvider
Param | Type | Description |
---|---|---|
color |
string | rgb
|
an HTML or fontkit rgb color. |
Embed an image to the given PDF Object
Kind: instance method of pdfProvider
Param | Type | Description |
---|---|---|
PDFDocument |
The PDFDocument to add the image to | |
imageData | Object |
an Object containing path, (x,y) coordinates, scaling information, etc... |
Embed a fontfile into the given PDF
Kind: instance method of pdfProvider
Returns: CustomFontEmbedder
- The resulted embedded font
Param | Type | Description |
---|---|---|
PDFDocument |
The pdf to embed the font into | |
fileName | string |
the name of the file |
Embed a Text Box to the given PDF Object
Kind: instance method of pdfProvider
Param | Type | Description |
---|---|---|
PDFDocument |
The PDFDocument to add the Text Box to | |
textBoxData | Object |
an Object containing path, (x,y) coordinates, scaling information, etc... |
Store form field information, text for text fields, booleans for checkboxes
Kind: instance method of pdfProvider
Param | Type | Description |
---|---|---|
file | string |
the pdf filename to apply the image to ('all' means all PDFs) |
name | string |
The name of the field to reference |
value |
string | boolean | Promise
|
The value to be applied to the field |
options | Object |
Optional data, functions for the field |
options.parseValue | function |
function to parse the value after resolving the value Promise |
Check if a field is defined
Kind: instance method of pdfProvider
Returns: boolean
- whether the field is defined
Param | Type | Description |
---|---|---|
file | string |
The name of the PDF file a field belongs to |
name | string |
The name of the field to return the value from |
Return a PDF field object definition
Kind: instance method of pdfProvider
Returns: string
| boolean
| undefined
- the requested field data
Param | Type | Description |
---|---|---|
file | string |
The name of the PDF file a field belongs to |
name | string |
The name of the field to return the value from |
Return a PDF field value
Kind: instance method of pdfProvider
Returns: string
| boolean
- - the requested field
Param | Type | Description |
---|---|---|
file | string |
The name of the PDF file a field belongs to |
name | string |
The name of the field to return the value from |
defaultValue |
string | boolean
|
The value to return if the field cannot be found |
Kind: instance method of pdfProvider
Returns: Object
| string
| boolean
| number
- the requested field option(s)
Param | Type | Description |
---|---|---|
file | string |
The name of the PDF file a field belongs to |
name | string |
The name of the field to return the value from |
optionName | string |
Optional name of a field to return |
Store image information
Kind: instance method of pdfProvider
Param | Type | Description |
---|---|---|
file |
string | array
|
the pdf filename(s) to apply the image to ('all' means all PDFs) |
page |
number | array
|
The page(s) to add the image to |
x | number |
The x coordinate for the image |
y | number |
The y coordinate for the image |
path | string |
The url to the image to add |
maxWidth | number |
The maximum width of the Image |
maxHeight | number |
The maximum height of the Image |
options | object |
Additional options |
Parses the provided filedata, fills out pdf form fields, adds images and saves the blob
Kind: instance method of pdfProvider
asynchronously parse a value through a function
Kind: instance method of pdfProvider
Returns: the parsed value
Param | Type | Description |
---|---|---|
value |
any | Promise
|
the value to be parsed |
parser | function |
the parser function, arguments passed are the (awaited) value and this
|
Store pdf text box information
Kind: instance method of pdfProvider
Param | Type | Description |
---|---|---|
reference | string |
a reference for the textBox added (for debugging purposes) |
file |
string | array
|
the pdf filename(s) to apply the text box to ('all' means all PDFs) |
page |
number | array
|
The page(s) to add the text box to |
x | number |
The x coordinate for the text box (in % of the page width) |
y | number |
The y coordinate for the text box (in % of the page height) |
width | number |
The width of the text box to add (in % of the page width) |
height | number |
The height of the text box to add (in % of the page height) |
text |
string | Promise
|
The text to display in the text box |
options | object |
Additional options |
options.color |
string | array
|
either a hexadecimal (html) color, or array of rgb values (in %) |
options.font | string |
The filename of the font used, will be looked for in the provider's font directory or the module's font directory |
options.halign | string |
how to align the text horizontally (left[default], center, right) |
options.lineHeight | number |
The lineheight of the text (in % of the page height) |
options.multiline | boolean |
treat this text as multiline (default: true) |
options.overflow | boolean |
allow the text to overflow the boundaries (default: false) The text will be suffixed with three dots if it is too long |
options.prefix | string |
a text to add at the beginning of @param text |
options.size | number |
The font size |
options.suffix | string |
a text to add at the end of @param text, after any overflow characters. |
options.valign | string |
how to align the text vertically (top, center, bottom[default]) |
options.valueParser | function |
function to parse the value after resolving the value Promise |