addImage

Methods

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

Source:

向PDF文档中添加图片。

Parameters:
Name Type Description
imageData string | HTMLImageElement | HTMLCanvasElement | Uint8Array | RGBAData

imageData 作为 base64 编码的 DataUrl 或 Image-HTMLElement 或 Canvas-HTMLElement 或包含 RGBA 数组的对象(如 canvas.getImageData 的输出)。

format string

如果文件类型识别失败或 Canvas-Element 需要指定(Canvas 的默认格式为 JPEG),则指定文件格式,例如 'JPEG', 'PNG', 'WEBP'

x number

x 坐标(在 PDF 文档创建时声明的单位),相对于页面左边缘

y number

y 坐标(在 PDF 文档创建时声明的单位),相对于页面顶部边缘

width number

图像的宽度(在 PDF 文档创建时声明的单位)

height number

图像的高度(在 PDF 文档创建时声明的单位)

alias string

图像的别名(如果多次使用)

compression string

生成的 JPEG 的压缩,可以有 'NONE', 'FAST', 'MEDIUM' 和 'SLOW' 的值

rotation number

图像的旋转角度(0-359 度)

Returns:

jsPDF

(inner) arrayBufferToBinaryString(ArrayBuffer) → {String}

Source:

将 Buffer 转换为二进制字符串

参数:
Name Type Description
ArrayBuffer ArrayBuffer | ArrayBufferView

buffer 或 bufferView 包含 ImageData

Returns:
Type
String

(inner) binaryStringToUint8Array(BinaryString) → {Uint8Array}

Source:

将二进制字符串转换为 ArrayBuffer

参数:
Name Type Description
BinaryString string

包含 ImageData 的二进制字符串

Returns:
Type
Uint8Array

(inner) convertBase64ToBinaryString(stringData) → {string}

Source:
参数:
Name Type Description
stringData string
返回:

二进制字符串

Type
string

(inner) extractImageFromDataUrl(dataUrl) → {Array}

Source:

从有效的 base64 data URI 中提取并返回信息

参数:
Name Type Description
dataUrl string

格式为 'data:[][;base64],' 的有效 data URI

Returns:

包含以下内容的数组: [0] 完整的 data URI [1] [2] format - 第二个 MIME 类型部分,例如 'png' 在 'image/png' 中 [4]

Type
Array

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

Source:

通过 magic-bytes 识别图像文件类型

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

参数:
Name Type Description
imageData string | arraybuffer

imageData 作为二进制字符串或 arraybuffer

format string

如果文件类型识别失败,例如 'JPEG'

Returns:

图像的文件类型

Type
string

(inner) getImageProperties(imageData) → {Object}

Source:
参数:
Name Type Description
imageData Object
Returns:
Type
Object

(inner) isArrayBuffer(object) → {boolean}

Source:

测试提供的对象以确定是否为 ArrayBuffer

参数:
Name Type Description
object Object

一个对象

Returns:
Type
boolean

(inner) isArrayBufferView(object) → {boolean}

Source:

测试提供的对象以确定它是否实现了 ArrayBufferView (TypedArray) 接口

参数:
Name Type Description
object Object

一个对象

Returns:
Type
boolean

(inner) sHashCode(data) → {string}

Source:
参数:
Name Type Description
data string
Returns:
Type
string

(inner) supportsArrayBuffer() → {boolean}

Source:

检查 ArrayBuffer 是否受支持

返回:
Type
boolean

(inner) validateStringAsBase64(possible) → {boolean}

Source:

验证给定的字符串是否为有效的 Base64 字符串

参数:
Name Type Description
possible String

Base64 字符串

返回:
Type
boolean

类型定义

RGBAData

Source:
属性:
Name Type Description
data Uint8ClampedArray

单维 RGBA 值数组。例如从 canvas getImageData 中获取。

width number

图像宽度,因为数据本身不携带此信息。

height number

图像高度,因为数据本身不携带此信息。

addImage 的可能参数,一个带有尺寸的 RGBA 缓冲区。

类型:
  • Object