Page
Overview
Page is a class in Aspose.PDF FOSS for TypeScript.
A single PDF page: a live, mutable handle over its real page dict.
This class declares 60 methods for Page objects in TypeScript programs.
Available methods include: AddBarcode, AddCaret, AddCheckbox, AddCircle, AddComboBox, AddFileAttachment, AddFreeText, AddHighlight, AddImage, AddInk, AddLine, AddLink, and 46 additional methods.
All public members are accessible to any TypeScript application after installing the Aspose.PDF FOSS for TypeScript package.
Properties: Annotations, ArtBox, BleedBox, Contents, CropBox, Document, and 13 more.
Properties
| Name | Type | Access | Description |
|---|---|---|---|
Document | Document | Read | Gets the document. |
MediaBox | number[] | Read/Write | Gets the media box. |
CropBox | number[] | Read/Write | Gets the crop box. |
BleedBox | number[] | Read/Write | Gets the bleed box. |
TrimBox | number[] | Read/Write | Gets the trim box. |
ArtBox | number[] | Read/Write | Gets the art box. |
Rect | number[] | Read | Gets the rect. |
Rotate | number | Read/Write | Gets the rotate. |
Resources | PdfDict | undefined | Read | Gets the resources. |
Contents | Uint8Array | Read | Gets the contents. |
Annotations | Annotation[] | Read | Gets the annotations. |
Images | ImageInfo[] | Read | Gets the images. |
InlineImages | InlineImageInfo[] | Read | Gets the inline images. |
shape | : boolean | Read | Gets the shape. |
dir | : 'auto' | 'ltr' | 'rtl' | Read | Gets the dir. |
script | : string | Read | Gets the script. |
language | : string | Read | Gets the language. |
paragraphSpacing | : number | Read | Gap between consecutive blocks, on top of the style’s own spacing. |
structParent | : StructElement | Read | Grouping element the content tags under. |
Methods
| Signature | Description |
|---|---|
constructor(doc: Document, Dict: PdfDict, Number: number) | Calls constructor(doc, Dict, Number) on this Page instance. |
RemoveAnnotation(a: Annotation | PdfDict) | Remove an annotation from this page’s /Annots. |
AddTextNote(opts: TextNoteOptions) → TextAnnotation | Add a /Text (sticky-note) annotation to this page. |
AddStamp(opts: StampAnnotationOptions) → StampAnnotation | Add a /Stamp (rubber-stamp) annotation to this page. |
AddHighlight(opts: MarkupOptions) → MarkupAnnotation | Add a /Highlight markup annotation over the given /QuadPoints. |
AddUnderline(opts: MarkupOptions) → MarkupAnnotation | Add an /Underline markup annotation over the given /QuadPoints. |
AddStrikeOut(opts: MarkupOptions) → MarkupAnnotation | Add a /StrikeOut markup annotation over the given /QuadPoints. |
AddSquiggly(opts: MarkupOptions) → MarkupAnnotation | Add a /Squiggly markup annotation over the given /QuadPoints. |
AddLink(opts: LinkOptions) → LinkAnnotation | Add a /Link annotation with an internal GoTo or external URI action. |
AddTextField(init: Omit<TextFieldInit, 'page'>) → TextField | Create a single-line AcroForm text field whose widget lands on this page. |
AddCheckbox(init: Omit<CheckboxInit, 'page'>) → CheckboxField | Create an AcroForm checkbox whose widget lands on this page. |
AddComboBox(init: Omit<ComboBoxInit, 'page'>) → ChoiceField | Create an AcroForm combo box whose widget lands on this page. |
AddListBox(init: Omit<ListBoxInit, 'page'>) → ChoiceField | Create an AcroForm list box whose widget lands on this page. |
AddPushButton(init: Omit<PushButtonInit, 'page'>) → ButtonField | Create an AcroForm push button whose widget lands on this page. |
AddFileAttachment(opts: FileAttachmentOptions) → FileAttachmentAnnotation | Embed a file and place a /FileAttachment icon annotation on this page. |
AddSquare(opts: SquareCircleOptions) → SquareCircleAnnotation | Add a /Square rectangle annotation (border + optional interior fill). |
AddCircle(opts: SquareCircleOptions) → SquareCircleAnnotation | Add a /Circle ellipse annotation (border + optional interior fill). |
AddRedact(opts: RedactAnnotationOptions) → RedactAnnotation | Mark a region for redaction with a /Redact annotation. |
MarkRedactText(find: string | RegExp, opts: MarkRedactTextOptions) → number | Mark every occurrence of find (a literal string or RegExp) for redaction with a /Redact annotation, via the same search as Search. |
AddLine(opts: LineOptions) → LineAnnotation | Add a /Line annotation between two points, with optional end arrowheads. |
AddPolygon(opts: PolygonOptions) → PolyAnnotation | Add a closed /Polygon annotation (border + optional interior fill). |
AddPolyline(opts: PolylineOptions) → PolyAnnotation | Add an open /PolyLine annotation, with optional end arrowheads. |
AddInk(opts: InkOptions) → InkAnnotation | Add an /Ink annotation: one or more freehand strokes. |
AddFreeText(opts: FreeTextOptions) → FreeTextAnnotation | Add a /FreeText annotation: text drawn on the page, optionally with a callout. |
AddCaret(opts: CaretOptions) → CaretAnnotation | Add a /Caret annotation: a text-insertion mark, optionally with a paragraph sign. |
AddPopup(opts: PopupOptions) → PopupAnnotation | Add a /Popup window bound to an existing markup annotation on this page. |
GetText() → string | Extract visible text from the page with reasonable word/line ordering. |
GetTextFragments() → TextFragment[] | Extract positioned text fragments: consecutive glyphs sharing a font, size, and baseline grouped into runs (in content order), each carrying its page-space quad, fontSize, and fontName. |
GetStructuredText() → TextBlock[] | Extract structured text: positioned fragments grouped into lines (by baseline) and paragraph-like blocks (by vertical gap and left-edge alignment), ordered top-to-bottom. |
GetTables(options: TableExtractOptions) → Table[] | Reconstruct tables on the page. |
GetPaths() → PagePath[] | Extract painted vector paths (fills/strokes/clips) as positioned shapes: each carries its subpaths in user space, the CTM at paint time, a device-space bounding box, resolved fill/stroke color + colorspace family, fill rule, stroke line width, and clip usage. |
Search(find: string | RegExp, options: SearchOptions) → TextMatch[] | Find every occurrence of find (a literal string or RegExp) in the page’s text, using the same word/line assembly as GetText. |
SearchAnnotations(find: string | RegExp, options: SearchOptions) → AnnotationMatch[] | Find every occurrence of find (a literal string or RegExp) in the text the page’s annotations DRAW — a /FreeText’s visible words, a filled form field’s value — which Search does not see, because it walks page content streams only. |
SearchAnnotationText(find: string | RegExp) → AnnotationTextMatch[] | Find every occurrence of find (a literal string or RegExp) in the text the page’s annotations CARRY rather than draw: a note’s body (/Contents), its author (/T) and its subject (/Subj). |
ReplaceText(find: string | RegExp, replacement: string, options: SearchOptions) → number | Replace every occurrence of find (a literal string or RegExp) with replacement, re-encoded in the matched text’s own font and written in place. |
MeasureText(text: string, fontSize, font: AuthoringFont, opts: { shape?: boolean; dir?: 'auto' | 'ltr' | 'rtl'; script?: string; language?: string }) → number | Rendered width of text in points at fontSize (default 12) for font: one of the 12 Latin Standard-14 faces (default Helvetica) or an embedded font handle from {@link Document.AddFont}. |
AddText(text: string, x: number, y: number, options: StampOptions) | Stamp text at (x, y) in PDF user space. |
AddTextBlock(text: string, rect: [number, number, number, number], options: TextBlockOptions) → string | null | Flow text into the rectangle [x, y, w, h] (PDF user space), wrapping to the box width and clipping to its height. |
AddTextBlock(runs: TextRun[], rect: [number, number, number, number], options: TextBlockOptions) → TextRun[] | null | Calls AddTextBlock(runs, rect, options) on this Page instance. |
AddTextBlock(content: string | TextRun[], rect: [number, number, number, number], options: TextBlockOptions) → string | TextRun[] | null | Calls AddTextBlock(content, rect, options) on this Page instance. |
| `AddMarkdown(src: string | MdDocument, rect: [number, number, number, number], options: MarkdownFlowOptions & { | |
| /** Gap between consecutive blocks, on top of the style’s own spacing. | |
| * Default 0. */ | |
| paragraphSpacing?: number; | |
| /** Grouping element the content tags under. Omit for untagged output. */ | |
| structParent?: StructElement; | |
})→AddMarkdownResult` | Lay a Markdown document into the rectangle [x, y, w, h] (PDF user space, y the bottom edge) on this page. |
Graphics() → PageGraphics | Start a buffered vector-drawing session on this page. |
ToSvg(options: SvgOptions) → string | Render this page to a standalone SVG document string. |
ToHtml(options: HtmlOptions) → string | Render this page to a standalone HTML document. |
ToMarkdown(options: MarkdownExportOptions) → string | Render this page to GFM Markdown. |
ToDocx(options: DocxOptions) → Uint8Array | Render this page to a .docx. |
ToMarkdownAssets(options: MarkdownExportOptions) → MarkdownExportResult | Render this page to Markdown plus the image files it references. |
ToImage(options: ImageOptions) → Uint8Array | Render this page to PNG bytes with a pure-TypeScript software rasterizer. |
AddImage(data: Uint8Array, rect: [number, number, number, number], opts: AddImageOptions) | Embed data (JPEG or PNG) as an Image XObject and paint it into the rectangle [x, y, w, h] (PDF user space). |
AddBarcode(spec: BarcodeSpec, rect: [number, number, number, number], opts: AddBarcodeOptions) | Generate a barcode and place it in the rectangle [x, y, w, h] (PDF user space). |
AddSVGObject(data: Uint8Array, rect: [number, number, number, number], opts: AddSVGOptions) → AddSVGResult | Parse data as SVG and draw its geometry and paint into rect = [x, y, w, h] as a Form XObject. |
AddTable(table: TableBuilder, x: number, top: number, opts: AddTableOptions) → AddTableResult | Lay out a built table (see {@link createTable}) with its top-left corner at (x, top) in PDF user space and draw its backgrounds, cell text (aligned), and borders into this page’s /Contents. |
AddTOC(entries: TOCEntry[], rect: [number, number, number, number], opts: TOCOptions) → AddTOCResult | Render entries as a table of contents into rect = [x, y, w, h]: wrapped titles indented by level, dot leaders, right-aligned page labels (defaulting to each target page’s logical /PageLabels label), and a borderless GoTo link over each row. |
StampWith(src: Page, opts: StampWithOptions) | Stamp another page’s content onto this one as a shared Form XObject. |
Resize(box: [number, number, number, number], opts: ResizeOptions) | Set this page’s MediaBox and CropBox to box ([x0, y0, x1, y1]). |
Scale(factor: number) | Uniformly scale this page (content and every present boundary box) by factor > 0. |
Redact(rects: Rect[], opts: RedactOptions) | Redact every region in rects (each [x0, y0, x1, y1] in PDF user space): truly remove covered text and images, prune the resources they leave orphaned, then paint an opaque marker box over each region. |
RedactText(find: string | RegExp, opts: RedactOptions) → number | Redact by content: find every occurrence of find (a literal string or RegExp) via the same search as Search, then remove and mark each matched region through the Redact pipeline. |
ApplyRedactions(opts: ApplyRedactionsOptions) → number | Apply every /Redact mark on this page: truly remove the marked content, paint each mark’s overlay (/RO, else its /IC fill and /OverlayText), then remove the marks. |
FlattenAnnotations() → number | Flatten this page’s annotations: bake each visible annotation’s /AP /N appearance into the page content at its /Rect, then remove it from /Annots. |