class GroupDocs::Document::Annotation
Constants
- TYPES
updated in release 1.7.0
Attributes
@attr [Symbol] access
@attr [String] guid
@attr [Hash] annotationPosition
@attr [Int] penWidth
@attr [GroupDocs::Document::Rectangle] box
@attr [Time] createdOn
@attr [Int] creatorEmail
@attr [String] creatorGuid
@attr [Int] creatorName
@attr [GroupDocs::Document] document
@attr [String] documentGuid
@attr [String]TextFieldInfo
@attr [String]Font Color
@attr [String] guid
@attr [Integer] id
@attr [Long] penColor
added in release 1.5.8 @attr [Int] pageNumber
added in release 1.7.0 @attr [Int] penColor
@attr [Int] penStyle
@attr [Int] penWidth
@attr [Array<GroupDocs::Document::Annotation::Reply>] replies
@attr [String] replyGuid
@attr [Long] serverTime
@attr [String] sessionGuid
added in release 2.0.0 @attr [String] text
@attr [Symbol] type
@attr [Double] AnnotationSizeInfo
Public Class Methods
Creates new GroupDocs::Document::Annotation
.
@raise [ArgumentError] If document is not passed or is not an instance of GroupDocs::Document
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
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
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
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
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
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
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
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
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
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
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
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 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
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
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
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
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