Rasterex APINPM Package/docs/capabilities/styles/api

API Reference

Technical API reference for global and annotation-level styles using the SDK.

Overview

Use viewer.styles to set default appearance for new markup and to inspect or update properties for an existing annotation by GUID.

Style commands are available after the viewer is mounted, Canvas is ready, and a document is open.

typescript
import { createViewer } from "@rasterex/viewer";

const viewer = createViewer({
  container: "#viewer"
});

await viewer.mount();
await viewer.ready();

await viewer.documents.open({
  url: "https://files.example.com/floor-plan.pdf",
  displayName: "Floor Plan.pdf"
});
Overview

Set Global Appearance

Apply default fallback settings for all subsequent annotations drawn on the canvas:

typescript
viewer.styles.setGlobalAppearance({
  strokeColor: "#FF0000",
  fillColor: "#FFCCCC",
  textColor: "#000000",
  lineWidth: 3,
  lineStyle: 0,
  transparency: 50
});
Set Global Appearance

Read Annotation Properties

Inspect the style properties of a drawn markup:

typescript
const result = await viewer.styles.getAnnotationProperties({
  guid: "550e8400-e29b-41d4-a716-446655440000",
  timeoutMs: 10000
});

if (result.success && result.props) {
  console.log(result.props.strokeColor);
}
Read Annotation Properties

Update Annotation Properties

Apply dynamic properties styling overrides directly to an annotation by GUID:

typescript
viewer.styles.setAnnotationProperties({
  guid: "550e8400-e29b-41d4-a716-446655440000",
  props: {
    strokeColor: "#38BDF8",
    lineWidth: 4,
    transparency: 30
  }
});
Update Annotation Properties

Properties and Result Structures

Supported configuration payloads and returned schemas:

typescript
type AnnotationProperties = {
  strokeColor?: string;
  fillColor?: string;
  textColor?: string;
  lineWidth?: number;
  lineStyle?: number;
  transparency?: number;
  locked?: boolean;
  text?: string;
  countType?: number;
  arrowType?: number;
  measureType?: number;
};

type AnnotationPropertiesResult = {
  guid: string;
  success: boolean;
  props?: AnnotationProperties;
  error?: string;
  [key: string]: unknown;
};
Properties and Result Structures

Validation and Errors

In SDK 2.2.3, style commands check broker readiness and forward values without runtime GUID, timeout, color, line-width, or transparency validation. Required TypeScript fields do not establish runtime validation.

  • guid is a required TypeScript field for annotation-specific functions; select an existing annotation in the host before requesting its properties.
  • getAnnotationProperties() uses per-call timeoutMs when supplied, otherwise the viewer configuration commandTimeoutMs, whose default is 30000 ms.
  • The examples passing timeoutMs: 10000 use an explicit override, not the default.
  • Validate host inputs before sending them. This reference does not establish Canvas-side validation or accepted ranges.

Vanilla Example

Complete integration code setup for Vanilla HTML/JS environments:

<div id="viewer" style="height: 640px"></div>

<div>
  <button type="button" id="text-tool">Text</button>
  <button type="button" id="set-global">Set Red Defaults</button>
  <button type="button" id="read-selected">Read Selected Style</button>
  <button type="button" id="update-selected">Update Selected Style</button>
</div>

<p id="status"></p>
Vanilla Example

Canvas Broker Mapping

Broker message mappings for styling methods:

  • viewer.styles.setGlobalAppearance(...) maps to setGlobalAppearance.
  • viewer.styles.getAnnotationProperties(...) maps to getAnnotationProperties.
  • viewer.styles.setAnnotationProperties(...) maps to setAnnotationProperties.