Back to Jspdf

addImage

docs/module-addImage.html

4.2.15.7 KB
Original Source

Methods

(inner) addImage(imageData, format, x, y, width, height, alias, compression, rotation)

Source:

Adds an Image to the PDF.

Parameters:
NameTypeDescription
imageDatastringHTMLImageElement

imageData as base64 encoded DataUrl or Image-HTMLElement or Canvas-HTMLElement or object containing RGBA array (like output from canvas.getImageData).

| | format | string |

format of file if filetype-recognition fails or in case of a Canvas-Element needs to be specified (default for Canvas is JPEG), e.g. 'JPEG', 'PNG', 'WEBP'

| | x | number |

x Coordinate (in units declared at inception of PDF document) against left edge of the page

| | y | number |

y Coordinate (in units declared at inception of PDF document) against upper edge of the page

| | width | number |

width of the image (in units declared at inception of PDF document)

| | height | number |

height of the Image (in units declared at inception of PDF document)

| | alias | string |

alias of the image (if used multiple times)

| | compression | string |

compression of the generated JPEG, can have the values 'NONE', 'FAST', 'MEDIUM' and 'SLOW'

| | rotation | number |

rotation of the image in degrees (0-359)

|

Throws:

if the input is invalid, such as invalid image data.

Type Error

Returns:

jsPDF

(inner) arrayBufferToBinaryString(ArrayBuffer) → {String}

Source:

Convert the Buffer to a Binary String

Parameters:
NameTypeDescription
ArrayBufferArrayBufferArrayBufferView

buffer or bufferView with ImageData

|

Returns:

Type String

(inner) binaryStringToUint8Array(BinaryString) → {Uint8Array}

Source:

Convert Binary String to ArrayBuffer

Parameters:
NameTypeDescription
BinaryStringstring

with ImageData

|

Returns:

Type Uint8Array

(inner) convertBase64ToBinaryString(stringData) → {string}

Source:

Parameters:
NameTypeDescription
stringDatastring
Returns:

binary string

Type string

(inner) extractImageFromDataUrl(dataUrl) → {string}

Source:

Strips out and returns info from a valid base64 data URI

Parameters:
NameTypeDescription
dataUrlstring

a valid data URI of format 'data:[][;base64],'

|

Returns:

The raw Base64-encoded data.

Type string

(inner) getImageFileTypeByImageData(imageData, format) → {string}

Source:

Recognize filetype of Image by magic-bytes

https://en.wikipedia.org/wiki/List\_of\_file\_signatures

Parameters:
NameTypeDescription
imageDatastringarraybuffer

imageData as binary String or arraybuffer

| | format | string |

format of file if filetype-recognition fails, e.g. 'JPEG'

|

Returns:

filetype of Image

Type string

(inner) getImageProperties(imageData) → {Object}

Source:

Parameters:
NameTypeDescription
imageDataObject
Returns:

Type Object

(inner) isArrayBuffer(object) → {boolean}

Source:

Tests supplied object to determine if ArrayBuffer

Parameters:
NameTypeDescription
objectObject

an Object

|

Returns:

Type boolean

(inner) isArrayBufferView(object) → {boolean}

Source:

Tests supplied object to determine if it implements the ArrayBufferView (TypedArray) interface

Parameters:
NameTypeDescription
objectObject

an Object

|

Returns:

Type boolean

(inner) sHashCode(data) → {string}

Source:

Parameters:
NameTypeDescription
datastring
Returns:

Type string

(inner) validateStringAsBase64(possible) → {boolean}

Source:

Validates if given String is a valid Base64-String

Parameters:
NameTypeDescription
possibleString

Base64-String

|

Returns:

Type boolean

Type Definitions

RGBAData

Source:

Properties:
NameTypeDescription
dataUint8ClampedArray

Single dimensional array of RGBA values. For example from canvas getImageData.

| | width | number |

Image width as the data does not carry this information in itself.

| | height | number |

Image height as the data does not carry this information in itself.

|

Possible parameter for addImage, an RGBA buffer with size.

Type:
  • Object