class GroupDocs::Document::Annotation

Constants

TYPES

updated in release 1.7.0

Attributes

access[RW]

@attr [Symbol] access

annotationGuid=[RW]

@attr [String] guid

annotationPosition[RW]

@attr [Hash] annotationPosition

backgroundColor[RW]

@attr [Int] penWidth

box[RW]

@attr [GroupDocs::Document::Rectangle] box

createdOn[RW]

@attr [Time] createdOn

creatorEmail[RW]

@attr [Int] creatorEmail

creatorGuid[RW]

@attr [String] creatorGuid

creatorName[RW]

@attr [Int] creatorName

document[RW]

@attr [GroupDocs::Document] document

documentGuid[RW]

@attr [String] documentGuid

fieldText[RW]

@attr [String]TextFieldInfo

fontColor[RW]

@attr [String]Font Color

fontFamily[RW]
fontSize[RW]
guid[RW]

@attr [String] guid

height[RW]
id[RW]

@attr [Integer] id

layerId[RW]

@attr [Long] penColor

pageNumber[RW]

added in release 1.5.8 @attr [Int] pageNumber

penColor[RW]

added in release 1.7.0 @attr [Int] penColor

penStyle[RW]

@attr [Int] penStyle

penWidth[RW]

@attr [Int] penWidth

replies[RW]

@attr [Array<GroupDocs::Document::Annotation::Reply>] replies

replyGuid[RW]

@attr [String] replyGuid

serverTime[RW]

@attr [Long] serverTime

sessionGuid[RW]

@attr [String] sessionGuid

text[RW]

added in release 2.0.0 @attr [String] text

type[RW]

@attr [Symbol] type

width[RW]

@attr [Double] AnnotationSizeInfo

Public Class Methods

new(options = {}, &blk) click to toggle source

Creates new GroupDocs::Document::Annotation.

@raise [ArgumentError] If document is not passed or is not an instance of GroupDocs::Document

Calls superclass method GroupDocs::Api::Entity::new
# File lib/groupdocs/document/annotation.rb, line 107
def initialize(options = {}, &blk)
  super(options, &blk)
  document.is_a?(GroupDocs::Document) or raise ArgumentError,
    "You have to pass GroupDocs::Document object: #{document.inspect}."
end

Public Instance Methods

access=(mode) click to toggle source

Converts access mode to machine-readable format.

@param [Symbol] mode

# File lib/groupdocs/document/annotation.rb, line 142
def access=(mode)
  @access = (mode.is_a?(Symbol) ? parse_access_mode(mode) : mode)
end
add_reply(reply) click to toggle source

Adds reply to annotation.

@param [GroupDocs::Document::Annotation::Reply] reply @raise [ArgumentError] if reply is not GroupDocs::Document::Annotation::Reply object

# File lib/groupdocs/document/annotation.rb, line 198
def add_reply(reply)
  reply.is_a?(GroupDocs::Document::Annotation::Reply) or raise ArgumentError,
    "Reply should be GroupDocs::Document::Annotation::Reply object, received: #{reply.inspect}"

  @replies ||= Array.new
  @replies << reply
end
box=(options) click to toggle source

Coverts passed hash to GroupDocs::Document::Rectangle object.

@param [Hash] options @return [GroupDocs::Document::Rectangle]

# File lib/groupdocs/document/annotation.rb, line 170
def box=(options)
  @box = GroupDocs::Document::Rectangle.new(options)
end
create!(info, access = {}) click to toggle source

Creates new annotation.

@example

document = GroupDocs::Storage::Folder.list!.first.to_document
annotation = GroupDocs::Document::Annotation.new(document: document)
annotation.create!

@param [Hash] info Annotation info @option info [Array] :box @option info [Array] :annotationPosition @param [Hash] access Access credentials @option access [String] :client_id @option access [String] :private_key

# File lib/groupdocs/document/annotation.rb, line 221
def create!(info, access = {})
  json = Api::Request.new do |request|
    request[:access] = access
    request[:method] = :POST
    request[:path] = "/ant/{{client_id}}/files/#{document.file.guid}/annotations"
    request[:request_body] = info
  end.execute!

  json.each do |field, value|
    send(:"#{field}=", value) if respond_to?(:"#{field}=")
  end
end
created_on() click to toggle source

Converts timestamp which is return by API server to Time object.

@return [Time]

# File lib/groupdocs/document/annotation.rb, line 160
def created_on
  Time.at(@createdOn / 1000)
end
move!(x, y, access = {}) click to toggle source

Moves annotation to given coordinates.

@param [Integer, Float] x @param [Integer, Float] y @param [Hash] access Access credentials @option access [String] :client_id @option access [String] :private_key

# File lib/groupdocs/document/annotation.rb, line 298
def move!(x, y, access = {})
  Api::Request.new do |request|
    request[:access] = access
    request[:method] = :PUT
    request[:path] = "/ant/{{client_id}}/annotations/#{guid}/position"
    request[:request_body] = { :x => x, :y => y }
  end.execute!

  self.annotation_position = { :x => x, :y => y }
end
move_marker!(marker, access = {}) click to toggle source

Changed in release 1.5.8

Moves annotation marker to given coordinates.

@param [GroupDocs::Annotation::Marker] marker Marker position @param [Hash] access Access credentials @option access [String] :client_id @option access [String] :private_key

# File lib/groupdocs/document/annotation.rb, line 319
def move_marker!(marker, access = {})
  marker.is_a?(GroupDocs::Document::Annotation::MarkerPosition) or raise ArgumentError,
    "Marker should be GroupDocs::Document::Annotation::MarkerPosition object, received: #{marker.inspect}"
  Api::Request.new do |request|
    request[:access] = access
    request[:method] = :PUT
    request[:path] = "/ant/{{client_id}}/annotations/#{guid}/markerPosition"
    request[:request_body] = marker
  end.execute!

  if box && page_number
    box.x = marker.position[:x]
    box.y = marker.position[:y]
    page_number = marker.page
  else
    self.box = { :x => marker.position[:x], :y => marker.position[:y] }
    self.page_number = marker.page
  end
end
remove!(access = {}) click to toggle source

Removes annotation.

@param [Hash] access Access credentials @option access [String] :client_id @option access [String] :private_key

# File lib/groupdocs/document/annotation.rb, line 242
def remove!(access = {})
  Api::Request.new do |request|
    request[:access] = access
    request[:method] = :DELETE
    request[:path] = "/ant/{{client_id}}/annotations/#{guid}"
  end.execute!
end
remove_annotations!(access = {}) click to toggle source

added in release 1.6.0

@example

document = GroupDocs::Storage::Folder.list!.first.to_document
annotation = GroupDocs::Document::Annotation.new(document: document)
annotation.remove_annotations!

Removes all annotations from document.

@param [Hash] access Access credentials @option access [String] :client_id @option access [String] :private_key

# File lib/groupdocs/document/annotation.rb, line 264
def remove_annotations!(access = {})
  json = Api::Request.new do |request|
    request[:access] = access
    request[:method] = :DELETE
    request[:path] = "/ant/{{client_id}}/files/#{document.file.guid}/annotations"
  end.execute!
    json[:delete_annotation_results]
end
replies!(options = {}, access = {}) click to toggle source

Return an array of replies..

@param [Hash] options @option options [Time] :after @param [Hash] access Access credentials @option access [String] :client_id @option access [String] :private_key @return [Array<GroupDocs::Document::Annotation::Reply>]

@raise [ArgumentError] If :after option is passed but it’s not an instance of Time

# File lib/groupdocs/document/annotation.rb, line 285
def replies!(options = {}, access = {})
  Document::Annotation::Reply.get!(self, options, access)
end
replies=(replies) click to toggle source

Converts each reply to GroupDocs::Document::Annotation::Reply object.

@param [Array<GroupDocs::Document::Annotation::Reply, Hash>] replies

# File lib/groupdocs/document/annotation.rb, line 179
def replies=(replies)
  if replies
    @replies = replies.map do |reply|
      if reply.is_a?(GroupDocs::Document::Annotation::Reply)
        reply
      else
        reply.merge!(:annotation => self)
        Document::Annotation::Reply.new(reply)
      end
    end
  end
end
resize!(x, y, access = {}) click to toggle source

Resize annotation.

@param [Integer, Float] x @param [Integer, Float] y @param [Hash] access Access credentials @option access [String] :client_id @option access [String] :private_key

# File lib/groupdocs/document/annotation.rb, line 367
def resize!(x, y, access = {})
  Api::Request.new do |request|
    request[:access] = access
    request[:method] = :PUT
    request[:path] = "/ant/{{client_id}}/annotations/#{guid}/size"
    request[:request_body] = { :width => x, :height => y }
  end.execute!
    self.box = { :width => x, :height => y }

end
set_access!(mode, access = {}) click to toggle source

Sets access mode.

@param [Symbol] mode @param [Hash] access Access credentials @option access [String] :client_id @option access [String] :private_key

# File lib/groupdocs/document/annotation.rb, line 347
def set_access!(mode, access = {})
  Api::Request.new do |request|
    request[:access] = access
    request[:method] = :PUT
    request[:path] = "/ant/{{client_id}}/annotations/#{guid}/annotationAccess"
    request[:request_body] = %w(public private).index(mode.to_s)
  end.execute!

  self.access = mode
end
text_color!(font_color, access = {}) click to toggle source

Save Text Of Text Color.

@param [Integer, Float] fontColor @param [Hash] access Access credentials @option access [String] :client_id @option access [String] :private_key

# File lib/groupdocs/document/annotation.rb, line 409
def text_color!(font_color, access = {})
  Api::Request.new do |request|
    request[:access] = access
    request[:method] = :PUT
    request[:path] = "/ant/{{client_id}}/annotations/#{guid}/size"
    request[:request_body] = { :fontColor => font_color }
  end.execute!

  self.fontColor = font_color
end
text_info!(fieldText, fontFamily, fontSize, access = {}) click to toggle source

Save Text Of Text Field.

@param [String] fieldText @param [String] fontFamily @param [Integer, Float] fontSize @param [Hash] access Access credentials @option access [String] :client_id @option access [String] :private_key

# File lib/groupdocs/document/annotation.rb, line 388
def text_info!(fieldText, fontFamily, fontSize, access = {})
  Api::Request.new do |request|
    request[:access] = access
    request[:method] = :PUT
    request[:path] = "/ant/{{client_id}}/annotations/#{guid}/size"
    request[:request_body] = { :fieldText => fieldText, :fontFamily => fontFamily, :fontSize => fontSize }
  end.execute!

  self.fieldText = fieldText
  self.fontFamily = fontFamily
  self.fontSize = fontSize
end
type=(type) click to toggle source

Updates type with machine-readable format.

@param [Symbol] type @raise [ArgumentError] if type is unknown

# File lib/groupdocs/document/annotation.rb, line 119
def type=(type)
  if type.is_a?(Symbol)
    type = type.to_s.camelize
    TYPES.include?(type) or raise ArgumentError, "Unknown type: #{type.inspect}"
  end

  @type = type
end