Skip to content

happypdf / PdfAsset

Type Alias: PdfAsset

ts
type PdfAsset = 
  | {
  fontFamily: string;
  fontSize: number;
  getText: string;
  kind: "text";
  x: number;
  y: number;
}
  | {
  drawHeight: number;
  drawWidth: number;
  getBytes: Uint8Array;
  height: number;
  kind: "image";
  mimeType: "image/jpeg" | "image/png";
  width: number;
  x: number;
  y: number;
}
  | {
  getSvg: string;
  height: number;
  kind: "graphics";
  width: number;
  x: number;
  y: number;
};

Defined in: src/api/extraction/types.ts:12

A content asset extracted from a PDF page.

Text comes from show-text operators (Tj / TJ / …), decoded via ToUnicode or a simple font encoding when available. Path-outlined “text” is not included.

Images come from Image XObjects painted with Do, converted to usable file bytes.

Coordinates are in PDF user space (origin bottom-left of the page MediaBox, unless a crop/transform applies).

Union Members

Type Literal

ts
{
  fontFamily: string;
  fontSize: number;
  getText: string;
  kind: "text";
  x: number;
  y: number;
}

fontFamily

ts
fontFamily: string;

Font name from /BaseFont (subset prefix stripped when present)

fontSize

ts
fontSize: number;

getText()

ts
getText(): string;
Returns

string

kind

ts
kind: "text";

x

ts
x: number;

Baseline origin x in page user space

y

ts
y: number;

Baseline origin y in page user space


Type Literal

ts
{
  drawHeight: number;
  drawWidth: number;
  getBytes: Uint8Array;
  height: number;
  kind: "image";
  mimeType: "image/jpeg" | "image/png";
  width: number;
  x: number;
  y: number;
}

drawHeight

ts
drawHeight: number;

Drawn height in page user space (from CTM)

drawWidth

ts
drawWidth: number;

Drawn width in page user space (from CTM)

getBytes()

ts
getBytes(): Uint8Array;
Returns

Uint8Array

height

ts
height: number;

Intrinsic pixel height

kind

ts
kind: "image";

mimeType

ts
mimeType: "image/jpeg" | "image/png";

width

ts
width: number;

Intrinsic pixel width

x

ts
x: number;

Lower-left x of the image’s unit square after CTM

y

ts
y: number;

Lower-left y of the image’s unit square after CTM


Type Literal

ts
{
  getSvg: string;
  height: number;
  kind: "graphics";
  width: number;
  x: number;
  y: number;
}

getSvg()

ts
getSvg(): string;

Approximate SVG markup for this painted path (fill/stroke/colors). Path numbers are in PDF user space; the SVG flips Y for normal viewing.

Returns

string

height

ts
height: number;

kind

ts
kind: "graphics";

width

ts
width: number;

x

ts
x: number;

Bounding-box min x in page user space

y

ts
y: number;

Bounding-box min y in page user space

MIT Licensed. A fork of pdf-lib.