addImage

Methods

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

Source:

Adds an Image to the PDF.

Parameters:
Name Type Description
imageData string/Image-Element/Canvas-Element/Uint8Array

imageData as base64 encoded DataUrl or Image-HTMLElement or Canvas-HTMLElement

format string

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

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)

Returns:

jsPDF

(inner) arrayBufferToBase64(arrayBuffer) → {string}

Source:

Converts an ArrayBuffer directly to base64

Taken from http://jsperf.com/encoding-xhr-image-data/31

Need to test if this is a better solution for larger files

Parameters:
Name Type Description
arrayBuffer arraybuffer
Returns:
Type
string

(inner) arrayBufferToBinaryString(ArrayBuffer) → {String}

Source:

Convert the Buffer to a Binary String

Parameters:
Name Type Description
ArrayBuffer ArrayBuffer

with ImageData

Returns:
Type
String

(inner) binaryStringToUint8Array(BinaryString) → {Uint8Array}

Source:

Convert the Buffer to a Binary String

Parameters:
Name Type Description
BinaryString ArrayBuffer

with ImageData

Returns:
Type
Uint8Array

(inner) convertStringToImageData(stringData) → {string}

Source:
Parameters:
Name Type Description
stringData string
Returns:

binary data

Type
string

(inner) createImageInfo(data, wd, ht, cs, bpc, f, imageIndex, alias, dp, trns, pal, smask, p) → {Object}

Source:
Parameters:
Name Type Description
data Object
wd number

width

ht number

height

cs Object

colorSpace

bpc number

bits per channel

f any
imageIndex number
alias string
dp any
trns any
pal any
smask any
p any
Returns:
Type
Object

(inner) extractInfoFromBase64DataURI(dataUrl) → {Array}

Source:

Strips out and returns info from a valid base64 data URI

Parameters:
Name Type Description
dataUrl string

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

Returns:

an Array containing the following [0] the complete data URI [1] [2] format - the second part of the mime-type i.e 'png' in 'image/png' [4]

Type
Array

(inner) extractInfoFromBase64DataURI(dataUrl) → {Array}

Source:

Strips out and returns info from a valid base64 data URI

Parameters:
Name Type Description
dataUrl string

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

Returns:

an Array containing the following [0] the complete data URI [1] [2] format - the second part of the mime-type i.e 'png' in 'image/png' [4]

Type
Array

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

Source:

Recognize filetype of Image by magic-bytes

https://en.wikipedia.org/wiki/List_of_file_signatures

Parameters:
Name Type Description
imageData string | arraybuffer

imageData as base64 encoded DataUrl 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:
Name Type Description
imageData Object
Returns:
Type
Object

(inner) isArrayBuffer(object) → {boolean}

Source:

Tests supplied object to determine if ArrayBuffer

Parameters:
Name Type Description
object Object

an Object

Returns:
Type
boolean

(inner) isArrayBufferView(object) → {boolean}

Source:

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

Parameters:
Name Type Description
object Object

an Object

Returns:
Type
boolean

(inner) isString(object) → {boolean}

Source:
Parameters:
Name Type Description
object any
Returns:
Type
boolean

(inner) loadImageFile(path, sync, callback)

Source:
Parameters:
Name Type Description
path string
sync boolean
callback function

(inner) sHashCode(str) → {string}

Source:
Parameters:
Name Type Description
str string
Returns:
Type
string

(inner) supportsArrayBuffer() → {boolean}

Source:

Check to see if ArrayBuffer is supported

Returns:
Type
boolean

(inner) validateStringAsBase64(possible) → {boolean}

Source:

Validates if given String is a valid Base64-String

Parameters:
Name Type Description
possible String

Base64-String

Returns:
Type
boolean