Class: GroupDocs::Document::Annotation

Inherits:
Api::Entity show all
Includes:
Api::Helpers::AccessMode
Defined in:
lib/groupdocs/document/annotation.rb

Defined Under Namespace

Classes: MarkerPosition, Reply, Reviewer

Constant Summary collapse

TYPES =

AnnotationType = { Text: 0, Area: 1, Point: 2, TextStrikeout: 3, Polyline: 4, TextField: 5, Watermark: 6 }

%w(Text Area Point TextStrikeout Polyline)

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Api::Entity

#inspect, #to_hash

Methods included from Api::Helpers::Accessor

#alias_accessor

Constructor Details

#initialize(options = {}, &blk) ⇒ Annotation

Creates new GroupDocs::Document::Annotation.

Raises:

  • (ArgumentError)

    If document is not passed or is not an instance of GroupDocs::Document



76
77
78
79
80
# File 'lib/groupdocs/document/annotation.rb', line 76

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

Instance Attribute Details

#accessSymbol

Converts access mode to human-readable format.

Returns:

  • (Symbol)


32
33
34
# File 'lib/groupdocs/document/annotation.rb', line 32

def access
  @access
end

#annotationPositionObject



38
39
40
# File 'lib/groupdocs/document/annotation.rb', line 38

def annotationPosition
  @annotationPosition
end

#boxObject



34
35
36
# File 'lib/groupdocs/document/annotation.rb', line 34

def box
  @box
end

#createdOnObject



28
29
30
# File 'lib/groupdocs/document/annotation.rb', line 28

def createdOn
  @createdOn
end

#creatorGuidObject



24
25
26
# File 'lib/groupdocs/document/annotation.rb', line 24

def creatorGuid
  @creatorGuid
end

#documentObject



14
15
16
# File 'lib/groupdocs/document/annotation.rb', line 14

def document
  @document
end

#documentGuidObject



22
23
24
# File 'lib/groupdocs/document/annotation.rb', line 22

def documentGuid
  @documentGuid
end

#fieldTextObject



43
44
45
# File 'lib/groupdocs/document/annotation.rb', line 43

def fieldText
  @fieldText
end

#fontColorObject



47
48
49
# File 'lib/groupdocs/document/annotation.rb', line 47

def fontColor
  @fontColor
end

#fontFamilyObject

Returns the value of attribute fontFamily.



44
45
46
# File 'lib/groupdocs/document/annotation.rb', line 44

def fontFamily
  @fontFamily
end

#fontSizeObject

Returns the value of attribute fontSize.



45
46
47
# File 'lib/groupdocs/document/annotation.rb', line 45

def fontSize
  @fontSize
end

#guidObject



18
19
20
# File 'lib/groupdocs/document/annotation.rb', line 18

def guid
  @guid
end

#heightObject

Returns the value of attribute height.



41
42
43
# File 'lib/groupdocs/document/annotation.rb', line 41

def height
  @height
end

#idObject



16
17
18
# File 'lib/groupdocs/document/annotation.rb', line 16

def id
  @id
end

#pageNumberObject

added in release 1.5.8



51
52
53
# File 'lib/groupdocs/document/annotation.rb', line 51

def pageNumber
  @pageNumber
end

#repliesObject



36
37
38
# File 'lib/groupdocs/document/annotation.rb', line 36

def replies
  @replies
end

#replyGuidObject



26
27
28
# File 'lib/groupdocs/document/annotation.rb', line 26

def replyGuid
  @replyGuid
end

#serverTimeObject



53
54
55
# File 'lib/groupdocs/document/annotation.rb', line 53

def serverTime
  @serverTime
end

#sessionGuidObject



20
21
22
# File 'lib/groupdocs/document/annotation.rb', line 20

def sessionGuid
  @sessionGuid
end

#typeSymbol

Returns type in human-readable format.

Returns:

  • (Symbol)


30
31
32
# File 'lib/groupdocs/document/annotation.rb', line 30

def type
  @type
end

#widthObject



40
41
42
# File 'lib/groupdocs/document/annotation.rb', line 40

def width
  @width
end

Instance Method Details

#add_reply(reply) ⇒ Object

Adds reply to annotation.

Parameters:

Raises:

  • (ArgumentError)

    if reply is not GroupDocs::Document::Annotation::Reply object



167
168
169
170
171
172
173
# File 'lib/groupdocs/document/annotation.rb', line 167

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

#create!(info, access = {}) ⇒ Object

Creates new annotation.

Examples:

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

Parameters:

  • info (Hash)

    Annotation info

  • access (Hash) (defaults to: {})

    Access credentials

Options Hash (info):

  • :box (Array)
  • :annotationPosition (Array)

Options Hash (access):

  • :client_id (String)
  • :private_key (String)


190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/groupdocs/document/annotation.rb', line 190

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_onTime

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

Returns:

  • (Time)


129
130
131
# File 'lib/groupdocs/document/annotation.rb', line 129

def created_on
  Time.at(@createdOn / 1000)
end

#move!(x, y, access = {}) ⇒ Object

Moves annotation to given coordinates.

Parameters:

  • x (Integer, Float)
  • y (Integer, Float)
  • access (Hash) (defaults to: {})

    Access credentials

Options Hash (access):

  • :client_id (String)
  • :private_key (String)


243
244
245
246
247
248
249
250
251
252
# File 'lib/groupdocs/document/annotation.rb', line 243

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 = {}) ⇒ Object

Changed in release 1.5.8

Moves annotation marker to given coordinates.

Parameters:

  • marker (GroupDocs::Annotation::Marker)

    Marker position

  • access (Hash) (defaults to: {})

    Access credentials

Options Hash (access):

  • :client_id (String)
  • :private_key (String)


264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# File 'lib/groupdocs/document/annotation.rb', line 264

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 = {}) ⇒ Object

Removes annotation.

Parameters:

  • access (Hash) (defaults to: {})

    Access credentials

Options Hash (access):

  • :client_id (String)
  • :private_key (String)


210
211
212
213
214
215
216
# File 'lib/groupdocs/document/annotation.rb', line 210

def remove!(access = {})
  Api::Request.new do |request|
    request[:access] = access
    request[:method] = :DELETE
    request[:path] = "/ant/{{client_id}}/annotations/#{guid}"
  end.execute!
end

#replies!(options = {}, access = {}) ⇒ Array<GroupDocs::Document::Annotation::Reply>

Return an array of replies..

Parameters:

  • options (Hash) (defaults to: {})
  • access (Hash) (defaults to: {})

    Access credentials

Options Hash (options):

  • :after (Time)

Options Hash (access):

  • :client_id (String)
  • :private_key (String)

Returns:

Raises:

  • (ArgumentError)

    If :after option is passed but it’s not an instance of Time



230
231
232
# File 'lib/groupdocs/document/annotation.rb', line 230

def replies!(options = {}, access = {})
  Document::Annotation::Reply.get!(self, options, access)
end

#resize!(x, y, access = {}) ⇒ Object

Resize annotation.

Parameters:

  • x (Integer, Float)
  • y (Integer, Float)
  • access (Hash) (defaults to: {})

    Access credentials

Options Hash (access):

  • :client_id (String)
  • :private_key (String)


312
313
314
315
316
317
318
319
320
321
# File 'lib/groupdocs/document/annotation.rb', line 312

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 = {}) ⇒ Object

Sets access mode.

Parameters:

  • mode (Symbol)
  • access (Hash) (defaults to: {})

    Access credentials

Options Hash (access):

  • :client_id (String)
  • :private_key (String)


292
293
294
295
296
297
298
299
300
301
# File 'lib/groupdocs/document/annotation.rb', line 292

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 = {}) ⇒ Object

Save Text Of Text Color.

Parameters:

  • fontColor (Integer, Float)
  • access (Hash) (defaults to: {})

    Access credentials

Options Hash (access):

  • :client_id (String)
  • :private_key (String)


354
355
356
357
358
359
360
361
362
363
# File 'lib/groupdocs/document/annotation.rb', line 354

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 = {}) ⇒ Object

Save Text Of Text Field.

Parameters:

  • fieldText (String)
  • fontFamily (String)
  • fontSize (Integer, Float)
  • access (Hash) (defaults to: {})

    Access credentials

Options Hash (access):

  • :client_id (String)
  • :private_key (String)


333
334
335
336
337
338
339
340
341
342
343
344
# File 'lib/groupdocs/document/annotation.rb', line 333

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