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

NameTypeAccessDescription
DocumentDocumentReadGets the document.
MediaBoxnumber[]Read/WriteGets the media box.
CropBoxnumber[]Read/WriteGets the crop box.
BleedBoxnumber[]Read/WriteGets the bleed box.
TrimBoxnumber[]Read/WriteGets the trim box.
ArtBoxnumber[]Read/WriteGets the art box.
Rectnumber[]ReadGets the rect.
RotatenumberRead/WriteGets the rotate.
ResourcesPdfDict | undefinedReadGets the resources.
ContentsUint8ArrayReadGets the contents.
AnnotationsAnnotation[]ReadGets the annotations.
ImagesImageInfo[]ReadGets the images.
InlineImagesInlineImageInfo[]ReadGets the inline images.
shape: booleanReadGets the shape.
dir: 'auto' | 'ltr' | 'rtl'ReadGets the dir.
script: stringReadGets the script.
language: stringReadGets the language.
paragraphSpacing: numberReadGap between consecutive blocks, on top of the style’s own spacing.
structParent: StructElementReadGrouping element the content tags under.

Methods

SignatureDescription
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)TextAnnotationAdd a /Text (sticky-note) annotation to this page.
AddStamp(opts: StampAnnotationOptions)StampAnnotationAdd a /Stamp (rubber-stamp) annotation to this page.
AddHighlight(opts: MarkupOptions)MarkupAnnotationAdd a /Highlight markup annotation over the given /QuadPoints.
AddUnderline(opts: MarkupOptions)MarkupAnnotationAdd an /Underline markup annotation over the given /QuadPoints.
AddStrikeOut(opts: MarkupOptions)MarkupAnnotationAdd a /StrikeOut markup annotation over the given /QuadPoints.
AddSquiggly(opts: MarkupOptions)MarkupAnnotationAdd a /Squiggly markup annotation over the given /QuadPoints.
AddLink(opts: LinkOptions)LinkAnnotationAdd a /Link annotation with an internal GoTo or external URI action.
AddTextField(init: Omit<TextFieldInit, 'page'>)TextFieldCreate a single-line AcroForm text field whose widget lands on this page.
AddCheckbox(init: Omit<CheckboxInit, 'page'>)CheckboxFieldCreate an AcroForm checkbox whose widget lands on this page.
AddComboBox(init: Omit<ComboBoxInit, 'page'>)ChoiceFieldCreate an AcroForm combo box whose widget lands on this page.
AddListBox(init: Omit<ListBoxInit, 'page'>)ChoiceFieldCreate an AcroForm list box whose widget lands on this page.
AddPushButton(init: Omit<PushButtonInit, 'page'>)ButtonFieldCreate an AcroForm push button whose widget lands on this page.
AddFileAttachment(opts: FileAttachmentOptions)FileAttachmentAnnotationEmbed a file and place a /FileAttachment icon annotation on this page.
AddSquare(opts: SquareCircleOptions)SquareCircleAnnotationAdd a /Square rectangle annotation (border + optional interior fill).
AddCircle(opts: SquareCircleOptions)SquareCircleAnnotationAdd a /Circle ellipse annotation (border + optional interior fill).
AddRedact(opts: RedactAnnotationOptions)RedactAnnotationMark a region for redaction with a /Redact annotation.
MarkRedactText(find: string | RegExp, opts: MarkRedactTextOptions)numberMark every occurrence of find (a literal string or RegExp) for redaction with a /Redact annotation, via the same search as Search.
AddLine(opts: LineOptions)LineAnnotationAdd a /Line annotation between two points, with optional end arrowheads.
AddPolygon(opts: PolygonOptions)PolyAnnotationAdd a closed /Polygon annotation (border + optional interior fill).
AddPolyline(opts: PolylineOptions)PolyAnnotationAdd an open /PolyLine annotation, with optional end arrowheads.
AddInk(opts: InkOptions)InkAnnotationAdd an /Ink annotation: one or more freehand strokes.
AddFreeText(opts: FreeTextOptions)FreeTextAnnotationAdd a /FreeText annotation: text drawn on the page, optionally with a callout.
AddCaret(opts: CaretOptions)CaretAnnotationAdd a /Caret annotation: a text-insertion mark, optionally with a paragraph sign.
AddPopup(opts: PopupOptions)PopupAnnotationAdd a /Popup window bound to an existing markup annotation on this page.
GetText()stringExtract 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)numberReplace 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 })numberRendered 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 | nullFlow 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[] | nullCalls AddTextBlock(runs, rect, options) on this Page instance.
AddTextBlock(content: string | TextRun[], rect: [number, number, number, number], options: TextBlockOptions)string | TextRun[] | nullCalls 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()PageGraphicsStart a buffered vector-drawing session on this page.
ToSvg(options: SvgOptions)stringRender this page to a standalone SVG document string.
ToHtml(options: HtmlOptions)stringRender this page to a standalone HTML document.
ToMarkdown(options: MarkdownExportOptions)stringRender this page to GFM Markdown.
ToDocx(options: DocxOptions)Uint8ArrayRender this page to a .docx.
ToMarkdownAssets(options: MarkdownExportOptions)MarkdownExportResultRender this page to Markdown plus the image files it references.
ToImage(options: ImageOptions)Uint8ArrayRender 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)AddSVGResultParse 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)AddTableResultLay 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)AddTOCResultRender 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)numberRedact 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)numberApply 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()numberFlatten this page’s annotations: bake each visible annotation’s /AP /N appearance into the page content at its /Rect, then remove it from /Annots.