PDFImage
Represents an image that has been embedded in a PDFDocument.
Hierarchy
- PDFImage
Implements
Index
Properties
Methods
Properties
doc
• doc: PDFDocument
Defined in api/PDFImage.ts:30
The document to which this image belongs.
height
• height: number
Defined in api/PDFImage.ts:36
The height of this image in pixels.
ref
• ref: PDFRef
Defined in api/PDFImage.ts:27
The unique reference assigned to this image within the document.
width
• width: number
Defined in api/PDFImage.ts:33
The width of this image in pixels.
Methods
embed
▸ embed(): Promise‹void›
Defined in api/PDFImage.ts:127
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: Promise‹void›
Resolves when the embedding is complete.
scale
▸ scale(factor
: number): object
Defined in api/PDFImage.ts:73
Compute the width and height of this image after being scaled by the
given factor
. For example:
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.
Parameters:
Name | Type | Description |
---|---|---|
factor | number | The factor by which this image should be scaled. |
Returns: object
The width and height of the image after being scaled.
height: number = this.height * factor
width: number = this.width * factor
scaleToFit
▸ scaleToFit(width
: number, height
: number): object
Defined in api/PDFImage.ts:96
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.
Parameters:
Name | Type | Description |
---|---|---|
width | number | The bounding box's width. |
height | number | The bounding box's height. |
Returns: object
The width and height of the image after being scaled.
height: number = this.height * factor
width: number = this.width * factor
size
▸ size(): object
Defined in api/PDFImage.ts:114
Get the width and height of this image. For example:
const { width, height } = image.size()
Returns: object
The width and height of the image.
height: number = this.height * factor
width: number = this.width * factor
Static
of
▸ of(ref
: PDFRef, doc
: PDFDocument, embedder
: ImageEmbedder): PDFImage‹›
Defined in api/PDFImage.ts:23
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
Parameters:
Name | Type | Description |
---|---|---|
ref | PDFRef | The unique reference for this image. |
doc | PDFDocument | The document to which the image will belong. |
embedder | ImageEmbedder | The embedder that will be used to embed the image. |
Returns: PDFImage‹›