ts-visio - v1.16.27
    Preparing search index...

    Class Page

    Represents a single page (tab) inside a Visio document.

    Obtain a Page instance from VisioDocument.pages, VisioDocument.addPage, or VisioDocument.getPage.

    const doc  = await VisioDocument.create();
    const page = doc.pages[0];
    await page.addShape({ text: 'Hello', x: 1, y: 1, width: 2, height: 1 });
    Index

    Constructors

    • Parameters

      • internalPage: VisioPage
      • pkg: VisioPackage
      • Optionalmedia: MediaManager
      • Optionalrels: RelsManager
      • Optionalmodifier: ShapeModifier

      Returns Page

    Accessors

    • get id(): string

      Returns string

    • get name(): string

      Returns string

    • get pageHeight(): number

      Height of the page canvas in inches.

      Returns number

    • get pageWidth(): number

      Width of the page canvas in inches.

      Returns number

    Methods

    • Embed an image on the page and return the resulting Foreign shape.

      Parameters

      • data: Buffer

        Raw image bytes (PNG, JPEG, GIF, BMP, or TIFF).

      • name: string

        Filename used to store the image inside the archive (e.g. 'logo.png').

      • x: number

        Horizontal pin position in inches.

      • y: number

        Vertical pin position in inches.

      • width: number

        Display width in inches.

      • height: number

        Display height in inches.

      Returns Promise<Shape>

      import fs from 'fs';
      const imgBuffer = fs.readFileSync('./logo.png');
      await page.addImage(imgBuffer, 'logo.png', 1, 1, 2, 1);
    • Parameters

      • name: string
      • Optionaloptions: { lock?: boolean; print?: boolean; visible?: boolean }

      Returns Promise<Layer>

    • Add a new shape to the page and return a Shape handle to it.

      Parameters

      • props: NewShapeProps

        Visual and text properties for the new shape. All geometry fields (x, y, width, height) are in inches.

      • OptionalparentId: string

        Optional ID of an existing group shape to nest the new shape inside.

      Returns Promise<Shape>

      // Plain rectangle
      const box = await page.addShape({ text: 'Server', x: 2, y: 3, width: 2, height: 1 });

      // Ellipse with styling
      await page.addShape({
      text: 'Start', x: 1, y: 1, width: 1.5, height: 1.5,
      geometry: 'ellipse', fillColor: '#4472C4', fontColor: '#ffffff',
      });

      // Master instance (shape defined by a reusable master)
      const m = doc.createMaster('Router', 'ellipse');
      await page.addShape({ text: '', x: 4, y: 2, width: 1, height: 1, masterId: m.id });
    • Parameters

      • x: number
      • y: number
      • title: string
      • columns: string[]

      Returns Promise<Shape>

    • Remove any custom drawing scale, reverting the page to a 1:1 ratio.

      Returns this

    • Draw a connector (line/arrow) between two shapes on this page.

      Parameters

      • fromShape: Shape

        Source shape.

      • toShape: Shape

        Target shape.

      • OptionalbeginArrow: string

        Arrow head at the source end (use ArrowHeads constants).

      • OptionalendArrow: string

        Arrow head at the target end (use ArrowHeads constants).

      • Optionalstyle: ConnectorStyle

        Line color, weight, pattern, and routing style.

      • OptionalfromPort: ConnectionTarget

        Named connection point on the source shape (e.g. 'Right').

      • OptionaltoPort: ConnectionTarget

        Named connection point on the target shape (e.g. 'Left').

      Returns Promise<void>

      import { ArrowHeads } from 'ts-visio';
      const a = await page.addShape({ text: 'A', x: 1, y: 1, width: 1, height: 1 });
      const b = await page.addShape({ text: 'B', x: 4, y: 1, width: 1, height: 1 });
      await page.connectShapes(a, b, ArrowHeads.None, ArrowHeads.OpenArrow,
      { lineColor: '#333333', routing: 'orthogonal' });
    • Return all shapes on the page (including nested group children) that satisfy the predicate. Equivalent to getAllShapes().filter(predicate).

      Parameters

      • predicate: (shape: Shape) => boolean

      Returns Shape[]

    • Return all connector shapes on the page. Each Connector exposes the from/to shape IDs, port targets, line style, arrows, and a delete() method to remove the connector.

      Returns Connector[]

    • Return the current drawing scale, or null if no custom scale is set (1:1).

      Returns DrawingScaleInfo | null

      const scale = page.getDrawingScale();
      // { pageScale: 1, pageUnit: 'in', drawingScale: 10, drawingUnit: 'ft' }
    • Return all layers defined on this page, ordered by index. Works for both newly created documents and loaded .vsdx files.

      Returns Layer[]

      const layers = page.getLayers();
      // [{ name: 'Background', index: 0, visible: true, locked: false }, ...]
    • Find a shape by its ID anywhere on the page, including shapes nested inside groups. Returns undefined if no shape with that ID exists.

      Parameters

      • id: string

      Returns Shape | undefined

    • Return all top-level shapes on the page. Group children are not included; use findShapes to search the entire shape tree.

      Returns Shape[]

    • Set a custom drawing scale for the page. One pageScale pageUnit on paper equals drawingScale drawingUnit in the real world.

      Parameters

      Returns this

      // 1 inch on paper = 10 feet in the real world
      page.setDrawingScale(1, 'in', 10, 'ft');

      // 1:100 metric
      page.setDrawingScale(1, 'cm', 100, 'cm');
    • Convenience: change the page to a named standard size (portrait by default).

      Parameters

      • sizeName: "Letter" | "Legal" | "Tabloid" | "A3" | "A4" | "A5"
      • orientation: PageOrientation = 'portrait'

      Returns this

      page.setNamedSize('A4')
      
    • Rotate the canvas between portrait and landscape without changing the paper size. Swaps width and height when the current orientation does not match the requested one.

      Parameters

      Returns this

    • Set the page canvas size in inches.

      Parameters

      • width: number
      • height: number

      Returns this

      page.setSize(11, 8.5)  // landscape letter