Class: XFDFUtils

Core.Annotations. XFDFUtils


new XFDFUtils()

The namespace for utility functions for XFDF serialization and deserialization.

Methods


<static> deserializeFringeRect(rectString, pageMatrix [, separator])

Deserializes a fringe rect string into a rect object
Parameters:
Name Type Argument Default Description
rectString string Rect in string format
pageMatrix Core.Math.Matrix Object representing the transformation matrix for the page
separator string <optional>
',' Separator used for coordinates
Returns:
New Rect with x1, y1, x2, y2 coordinates
Type
Core.Math.Rect

<static> deserializeMeasure(measureDictionary)

Deserializes the measure XML element into a measure dictionary
Parameters:
Name Type Description
measureDictionary Element Measure element
Returns:
Measure dictionary
Type
Core.Annotations.XFDFUtils.MeasureDictionary

<static> deserializePoint(pointString, pageMatrix [, coordinateSeparator])

Deserializes a point string into a point object
Parameters:
Name Type Argument Default Description
pointString string Point in string format
pageMatrix Core.Math.Matrix Transformation matrix for the page
coordinateSeparator string <optional>
',' Separator used for coordinates
Returns:
New Point with an x and y coordinate, or null if pointString is not a string or has invalid format
Type
Core.Math.Point | null

<static> deserializePointArray(pointArrayText, pageMatrix [, coordinateSeparator] [, pointSeparator])

Deserializes a list of points in string format into a point array.
Parameters:
Name Type Argument Default Description
pointArrayText string Array of points in string (delimited by pointSeparator)
pageMatrix Core.Math.Matrix Object representing the transformation matrix for the page
coordinateSeparator string <optional>
',' Separator used for coordinates
pointSeparator string <optional>
';' Separator used for points
Returns:
Array of Points
Type
Array.<Core.Math.Point>

<static> deserializeRect(pageMatrix [, rectString] [, separator])

Deserializes a rect string into a rect object
Parameters:
Name Type Argument Default Description
pageMatrix Core.Math.Matrix Object representing the transformation matrix for the page
rectString string <optional>
'0,0,0,0' Rect in string format
separator string <optional>
',' Separator used for coordinates
Returns:
New Rect with x1, y1, x2, y2 coordinates
Type
Core.Math.Rect

<static> parseDefaultAppearance(da)

Parses a default appearance string from an XFDF file and returns an object representing the appearance
Parameters:
Name Type Description
da string Appearance information in string format
Returns:
Appearance information
Type
Core.Annotations.XFDFUtils.Appearance
Example
const data = "0 0 0 rg /Helvetica 40 Tf";
const response = Annotations.XFDFUtils.parseDefaultAppearance(data);

Output:
{
   color: "#000000",
   font: {
      name: "Arial",
      rawName: "Helvetica",
      size: "40pt",
   },
   str: "0 0 0 rg /Helvetica 40 Tf",
}

<static> serializeFringeRect(rect, pageMatrix, separator)

Serializes a fringe rect object into a string suitable for an XFDF file
Parameters:
Name Type Description
rect Core.Math.Rect Rect with the x and y coordinates
pageMatrix Core.Math.Matrix Object representing the transformation matrix for the page
separator string Separator used for coordinates. Defaults to ',' if not defined
Returns:
Rect in string format
Type
string

<static> serializeMeasure(measureDictionary)

Serializes the measure dictionary into a measure XML element
Parameters:
Name Type Description
measureDictionary Core.Annotations.XFDFUtils.MeasureDictionary Measure dictionary
Returns:
Measure XML element
Type
Element

<static> serializePoint(point, pageMatrix [, coordinateSeparator])

Serializes the point into a string suitable for an XFDF file
Parameters:
Name Type Argument Default Description
point Core.Math.Point Point with an x and y coordinate
pageMatrix Core.Math.Matrix Object representing the transformation matrix for the page
coordinateSeparator string <optional>
',' Separator used for coordinates
Returns:
Point in string format, or null if the point parameter is not a Point instance
Type
string | null

<static> serializePointArray(pointArray, pageMatrix [, coordinateSeparator] [, pointSeparator])

Serialize the array of points into a string suitable for an XFDF file
Parameters:
Name Type Argument Default Description
pointArray Array.<Core.Math.Point> Array of points
pageMatrix Core.Math.Matrix Object representing the transformation matrix for the page
coordinateSeparator string <optional>
',' Separator used for coordinates
pointSeparator string <optional>
';' Separator used for points
Returns:
Stringified array of points
Type
string

<static> serializeRect(rect, pageMatrix [, separator])

Serializes a rect object into a string suitable for an XFDF file
Parameters:
Name Type Argument Default Description
rect Core.Math.Rect Rect with x and y coordinates
pageMatrix Core.Math.Matrix Object representing the transformation matrix for the page
separator string <optional>
',' Separator used for coordinates
Returns:
Rect in string format
Type
string

<static> toXMLDate(date)

Convert a JavaScript date object into a string date that can be used in XFDF
Parameters:
Name Type Description
date Date Date object.
Returns:
Date in string format.
Type
string

Type Definitions


Appearance

Default appearance information parsed from a string
Type:
  • Object
Properties:
Name Type Argument Description
color string <optional>
Hex RGB color e.g. #RRGGBB
font Object <optional>
Font details
Properties
Name Type Description
name string Display font name
rawName string Raw font name from the string
size string Font size with unit (pt)
str string Original appearance string

MeasureDictionary

Measurement dictionary containing arrays of number format entries
Type:
  • Object
Properties:
Name Type Argument Description
area Array.<Core.Annotations.XFDFUtils.NumberFormat> <optional>
Area number formats
axis Array.<Core.Annotations.XFDFUtils.NumberFormat> <optional>
Axis number formats
distance Array.<Core.Annotations.XFDFUtils.NumberFormat> <optional>
Distance number formats
scale string <optional>
Scale value

NumberFormat

A number format entry used in measurement dictionaries
Type:
  • Object
Properties:
Name Type Argument Description
factor number <optional>
Conversion factor
unit string <optional>
Unit name
decimalSymbol string <optional>
Decimal separator character
thousandsSymbol string <optional>
Thousands separator character
display string <optional>
Display mode code
precision number <optional>
Number of decimal digits
unitPrefix string <optional>
Unit prefix string
unitSuffix string <optional>
Unit suffix string
unitPosition string <optional>
Position of unit relative to value