asposewordsjavaforruby 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +7 -0
  2. data/Gempackage +2 -2
  3. data/LICENSE +20 -20
  4. data/README.md +28 -2
  5. data/Rakefile +2 -2
  6. data/asposewordsjavaforruby.gemspec +27 -27
  7. data/config/aspose.yml +5 -5
  8. data/data/LoadTxt.txt +14 -14
  9. data/lib/asposewordsjavaforruby.rb +71 -71
  10. data/lib/asposewordsjavaforruby/addwatermark.rb +84 -84
  11. data/lib/asposewordsjavaforruby/appenddoc.rb +24 -24
  12. data/lib/asposewordsjavaforruby/appenddocument.rb +229 -229
  13. data/lib/asposewordsjavaforruby/applylicense.rb +16 -16
  14. data/lib/asposewordsjavaforruby/asposewordsjava.rb +23 -23
  15. data/lib/asposewordsjavaforruby/autofittables.rb +123 -123
  16. data/lib/asposewordsjavaforruby/bookmarks.rb +132 -132
  17. data/lib/asposewordsjavaforruby/checkformat.rb +70 -70
  18. data/lib/asposewordsjavaforruby/compressimages.rb +53 -53
  19. data/lib/asposewordsjavaforruby/doc2pdf.rb +15 -15
  20. data/lib/asposewordsjavaforruby/doctohtml.rb +26 -26
  21. data/lib/asposewordsjavaforruby/extractcontent.rb +395 -395
  22. data/lib/asposewordsjavaforruby/findandreplace.rb +29 -29
  23. data/lib/asposewordsjavaforruby/helloworld.rb +26 -26
  24. data/lib/asposewordsjavaforruby/imagetopdf.rb +71 -71
  25. data/lib/asposewordsjavaforruby/insertnestedfields.rb +39 -39
  26. data/lib/asposewordsjavaforruby/loadandsavetodisk.rb +20 -20
  27. data/lib/asposewordsjavaforruby/loadandsavetostream.rb +32 -32
  28. data/lib/asposewordsjavaforruby/loadtxt.rb +14 -14
  29. data/lib/asposewordsjavaforruby/mergefield.rb +45 -45
  30. data/lib/asposewordsjavaforruby/nodes.rb +29 -29
  31. data/lib/asposewordsjavaforruby/processcomments.rb +72 -72
  32. data/lib/asposewordsjavaforruby/removebreaks.rb +65 -65
  33. data/lib/asposewordsjavaforruby/removefield.rb +23 -23
  34. data/lib/asposewordsjavaforruby/saveasmultipagetiff.rb +26 -26
  35. data/lib/asposewordsjavaforruby/simplemailmerge.rb +23 -23
  36. data/lib/asposewordsjavaforruby/styles.rb +77 -77
  37. data/lib/asposewordsjavaforruby/updatefields.rb +62 -62
  38. data/lib/asposewordsjavaforruby/version.rb +3 -3
  39. metadata +18 -28
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9077a2e9c0d2731526811b4c0145f7ede95357dc
4
+ data.tar.gz: 99c52f2cd9b4aab564285d237375dbfe35c96060
5
+ SHA512:
6
+ metadata.gz: 8ad07ce40bb60f9cf53c6c6ee7f798e78a2d77784a718a2eda85f5d6c869a4aa30b9edc44389cff652b30f78c2ba17b15417bcf7254add05cbef4062baf43236
7
+ data.tar.gz: 0aee220fe447b9f137d78dc2f420ed9de3ade4f032acd0523fc20a252146109d2b6ae544fd3a91ef0f5afecf31e201a3d26e84663cccee8bb16fe41924c6a164
data/Gempackage CHANGED
@@ -1,3 +1,3 @@
1
- source 'https://rubygems.org'
2
-
1
+ source 'https://rubygems.org'
2
+
3
3
  gemspec
data/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2001-2015 Aspose Pty Ltd
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2001-2015 Aspose Pty Ltd
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  SOFTWARE.
data/README.md CHANGED
@@ -1,2 +1,28 @@
1
- # Aspose_Words_Java_for_Ruby
2
- Aspose Words Java for Ruby is a gem that demonstrates / provides the Aspose.Words for Java API usage examples in Ruby by using Rjb - Ruby Java Bridge.
1
+ # Aspose_Words_Java_for_Ruby
2
+ Aspose Words Java for Ruby is a gem that demonstrates / provides the Aspose.Words for Java API usage examples in Ruby by using Rjb - Ruby Java Bridge.
3
+
4
+ ## Installation
5
+
6
+ Add this line to your application's Gemfile:
7
+
8
+ ```ruby
9
+ gem 'asposewordsjavaforruby'
10
+ ```
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install asposewordsjavaforruby
19
+
20
+ To download Aspose.Words for Java API to be used with these examples through RJB, Please navigate to:
21
+
22
+ http://www.aspose.com/community/files/72/java-components/aspose.words-for-java/
23
+
24
+ For most complete documentation of the project, check Aspose.Words Java for Ruby confluence wiki link:
25
+
26
+ http://www.aspose.com/docs/display/wordsjava/4.+Aspose.Words+Java+For+Ruby
27
+
28
+
data/Rakefile CHANGED
@@ -1,2 +1,2 @@
1
- require "bundler/gem_tasks"
2
-
1
+ require "bundler/gem_tasks"
2
+
@@ -1,27 +1,27 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'asposewordsjavaforruby/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = 'asposewordsjavaforruby'
8
- spec.version = Asposewordsjavaforruby::VERSION
9
- spec.authors = ['Aspose Marketplace']
10
- spec.email = ['marketplace@aspose.com']
11
- spec.summary = %q{A Ruby gem to work with aspose.words libraries}
12
- spec.description = %q{AsposeWordsJavaforRuby is a Ruby gem that can help working with aspose.words libraries}
13
- spec.homepage = 'https://github.com/asposemarketplace/Aspose_Words_Java_for_Ruby'
14
- spec.license = 'MIT'
15
-
16
- spec.files = `git ls-files`.split($/)
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ['lib']
20
-
21
- spec.add_development_dependency 'bundler', '~> 1.7'
22
- spec.add_development_dependency 'rake', '~> 10.0'
23
- spec.add_development_dependency 'rspec'
24
-
25
- spec.add_dependency 'rjb', '~> 1.5.3'
26
-
27
- end
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'asposewordsjavaforruby/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'asposewordsjavaforruby'
8
+ spec.version = Asposewordsjavaforruby::VERSION
9
+ spec.authors = ['Aspose Marketplace']
10
+ spec.email = ['marketplace@aspose.com']
11
+ spec.summary = %q{A Ruby gem to work with aspose.words libraries}
12
+ spec.description = %q{AsposeWordsJavaforRuby is a Ruby gem that helps working with Microsoft Word and OpenOffice documents using Aspose.Words for Java libraries}
13
+ spec.homepage = 'https://github.com/asposewords/Aspose_Words_Java/tree/master/Plugins/Aspose_Words_Java_for_Ruby'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.7'
22
+ spec.add_development_dependency 'rake', '~> 10.0'
23
+ spec.add_development_dependency 'rspec'
24
+
25
+ spec.add_dependency 'rjb', '~> 1.5.3'
26
+
27
+ end
@@ -1,5 +1,5 @@
1
- jar_dir: ../asposewordsjavaforruby/jars
2
- license_path: ../asposewordsjavaforruby/license/path
3
- jvm_args: -Xms512m -Xmx1G
4
-
5
-
1
+ jar_dir: ../asposewordsjavaforruby/jars
2
+ license_path: ../asposewordsjavaforruby/license/path
3
+ jvm_args: -Xms512m -Xmx1G
4
+
5
+
@@ -1,15 +1,15 @@
1
- Despite the fact txt format itself provides us with only "text" features for document lay-out, an ordinary txt file may contains many different pieces of formatting.
2
- One of the text features is using "Tab" key to make indented paragraphs.
3
- Paragraphs also may be nested within one another by using multiple "Tab" to increase the indent.
4
-
5
- Many txt files aslo contain lists formatted with bullets. The bullet symbol may take any of a variety of shapes, such as:
6
- - circular.
7
- - square.
8
- - diamond.
9
- - arrow.
10
- - etc.
11
-
12
- An alternative method to format data is to use a numbered list. Here is some examples of using numbers and characters for making numbered list:
13
- 1. Arabic numerals (1, 2, 3, ...).
14
- 2. Roman numerals (I, II, III, ... or i, ii, iii, ...).
1
+ Despite the fact txt format itself provides us with only "text" features for document lay-out, an ordinary txt file may contains many different pieces of formatting.
2
+ One of the text features is using "Tab" key to make indented paragraphs.
3
+ Paragraphs also may be nested within one another by using multiple "Tab" to increase the indent.
4
+
5
+ Many txt files aslo contain lists formatted with bullets. The bullet symbol may take any of a variety of shapes, such as:
6
+ - circular.
7
+ - square.
8
+ - diamond.
9
+ - arrow.
10
+ - etc.
11
+
12
+ An alternative method to format data is to use a numbered list. Here is some examples of using numbers and characters for making numbered list:
13
+ 1. Arabic numerals (1, 2, 3, ...).
14
+ 2. Roman numerals (I, II, III, ... or i, ii, iii, ...).
15
15
  3. Letters (A, B, C, ... or a, b, c, ...).
@@ -1,71 +1,71 @@
1
- require_relative 'asposewordsjavaforruby/version'
2
- require_relative 'asposewordsjavaforruby/asposewordsjava'
3
- require 'logger'
4
- require 'rjb'
5
-
6
- module Asposewordsjavaforruby
7
-
8
- class << self
9
- attr_accessor :aspose_words_config
10
- end
11
-
12
- def initialize_aspose_words
13
- aspose_jars_dir = Asposewordsjavaforruby.aspose_words_config ? Asposewordsjavaforruby.aspose_words_config['jar_dir'] : nil
14
- aspose_license_path = Asposewordsjavaforruby.aspose_words_config ? Asposewordsjavaforruby.aspose_words_config['license_path'] : nil
15
- jvm_args = Asposewordsjavaforruby.aspose_words_config ? Asposewordsjavaforruby.aspose_words_config['jvm_args'] : nil
16
-
17
- load_aspose_jars(aspose_jars_dir, jvm_args)
18
- load_aspose_license(aspose_license_path)
19
- end
20
-
21
- def load_aspose_license(aspose_license_path)
22
- if aspose_license_path && File.exist?(aspose_license_path)
23
- set_license(File.join(aspose_license_path))
24
- else
25
- logger = Logger.new(STDOUT)
26
- logger.level = Logger::WARN
27
- logger.warn('Using the non licensed aspose jar. Please specify path to your aspose license directory in config/aspose.yml file!')
28
- end
29
- end
30
-
31
- def load_aspose_jars(aspose_jars_dir, jvm_args)
32
- if aspose_jars_dir && File.exist?(aspose_jars_dir)
33
- jardir = File.join(aspose_jars_dir, '**', '*.jar')
34
- else
35
- jardir = File.join(File.dirname(File.dirname(__FILE__)), 'jars', '**', '*.jar')
36
- end
37
-
38
- if jvm_args
39
- args = jvm_args.split(' ') << '-Djava.awt.headless=true'
40
- logger = Logger.new(STDOUT)
41
- logger.level = Logger::DEBUG
42
- logger.debug("JVM args : #{args}")
43
- Rjb::load(classpath = Dir.glob(jardir).join(':'), jvmargs=args)
44
- else
45
- Rjb::load(classpath = Dir.glob(jardir).join(':'), jvmargs=['-Djava.awt.headless=true'])
46
- end
47
-
48
- end
49
-
50
- def input_file(file)
51
- Rjb::import('java.io.FileInputStream').new(file)
52
- end
53
-
54
- def set_license(aspose_license_file)
55
- begin
56
- fstream = input_file(aspose_license_file)
57
- license = Rjb::import('com.aspose.api.License').new()
58
- license.setLicense(fstream)
59
- rescue Exception => ex
60
- logger = Logger.new(STDOUT)
61
- logger.level = Logger::ERROR
62
- logger.error("Could not load the license file : #{ex}")
63
- fstream.close() if fstream
64
- end
65
- end
66
-
67
- def self.configure_aspose_words config
68
- Asposewordsjavaforruby.aspose_words_config = config
69
- end
70
-
71
- end
1
+ require_relative 'asposewordsjavaforruby/version'
2
+ require_relative 'asposewordsjavaforruby/asposewordsjava'
3
+ require 'logger'
4
+ require 'rjb'
5
+
6
+ module Asposewordsjavaforruby
7
+
8
+ class << self
9
+ attr_accessor :aspose_words_config
10
+ end
11
+
12
+ def initialize_aspose_words
13
+ aspose_jars_dir = Asposewordsjavaforruby.aspose_words_config ? Asposewordsjavaforruby.aspose_words_config['jar_dir'] : nil
14
+ aspose_license_path = Asposewordsjavaforruby.aspose_words_config ? Asposewordsjavaforruby.aspose_words_config['license_path'] : nil
15
+ jvm_args = Asposewordsjavaforruby.aspose_words_config ? Asposewordsjavaforruby.aspose_words_config['jvm_args'] : nil
16
+
17
+ load_aspose_jars(aspose_jars_dir, jvm_args)
18
+ load_aspose_license(aspose_license_path)
19
+ end
20
+
21
+ def load_aspose_license(aspose_license_path)
22
+ if aspose_license_path && File.exist?(aspose_license_path)
23
+ set_license(File.join(aspose_license_path))
24
+ else
25
+ logger = Logger.new(STDOUT)
26
+ logger.level = Logger::WARN
27
+ logger.warn('Using the non licensed aspose jar. Please specify path to your aspose license directory in config/aspose.yml file!')
28
+ end
29
+ end
30
+
31
+ def load_aspose_jars(aspose_jars_dir, jvm_args)
32
+ if aspose_jars_dir && File.exist?(aspose_jars_dir)
33
+ jardir = File.join(aspose_jars_dir, '**', '*.jar')
34
+ else
35
+ jardir = File.join(File.dirname(File.dirname(__FILE__)), 'jars', '**', '*.jar')
36
+ end
37
+
38
+ if jvm_args
39
+ args = jvm_args.split(' ') << '-Djava.awt.headless=true'
40
+ logger = Logger.new(STDOUT)
41
+ logger.level = Logger::DEBUG
42
+ logger.debug("JVM args : #{args}")
43
+ Rjb::load(classpath = Dir.glob(jardir).join(':'), jvmargs=args)
44
+ else
45
+ Rjb::load(classpath = Dir.glob(jardir).join(':'), jvmargs=['-Djava.awt.headless=true'])
46
+ end
47
+
48
+ end
49
+
50
+ def input_file(file)
51
+ Rjb::import('java.io.FileInputStream').new(file)
52
+ end
53
+
54
+ def set_license(aspose_license_file)
55
+ begin
56
+ fstream = input_file(aspose_license_file)
57
+ license = Rjb::import('com.aspose.api.License').new()
58
+ license.setLicense(fstream)
59
+ rescue Exception => ex
60
+ logger = Logger.new(STDOUT)
61
+ logger.level = Logger::ERROR
62
+ logger.error("Could not load the license file : #{ex}")
63
+ fstream.close() if fstream
64
+ end
65
+ end
66
+
67
+ def self.configure_aspose_words config
68
+ Asposewordsjavaforruby.aspose_words_config = config
69
+ end
70
+
71
+ end
@@ -1,84 +1,84 @@
1
- module Asposewordsjavaforruby
2
- module AddWatermark
3
- def initialize()
4
- # The path to the documents directory.
5
- data_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + '/data/'
6
-
7
- doc = Rjb::import('com.aspose.words.Document').new(data_dir + "TestWatermark.doc")
8
-
9
- insert_watermark_text(doc, "CONFIDENTIAL")
10
-
11
- doc.save(data_dir + "TestWatermark Out.doc")
12
- end
13
-
14
- =begin
15
- Inserts a watermark into a document.
16
-
17
- @param doc The input document.
18
- @param watermarkText Text of the watermark.
19
- =end
20
- def insert_watermark_text(doc, watermark_text)
21
- # Create a watermark shape. This will be a WordArt shape.
22
- # You are free to try other shape types as watermarks.
23
- shape_type = Rjb::import("com.aspose.words.ShapeType")
24
- watermark = Rjb::import("com.aspose.words.Shape").new(doc, shape_type.TEXT_PLAIN_TEXT)
25
-
26
- # Set up the text of the watermark.
27
- watermark.getTextPath().setText(watermark_text)
28
- watermark.getTextPath().setFontFamily("Arial")
29
- watermark.setWidth(500)
30
- watermark.setHeight(100)
31
-
32
- # Text will be directed from the bottom-left to the top-right corner.
33
- watermark.setRotation(-40)
34
-
35
- # Remove the following three lines if you need a solid black text.
36
- color = Rjb::import("java.awt.Color")
37
- watermark.getFill().setColor(color.GRAY) # Try LightGray to get more Word-style watermark
38
- watermark.setStrokeColor(color.GRAY) # Try LightGray to get more Word-style watermark
39
-
40
- # Place the watermark in the page center.
41
- relativeHorizontalPosition = Rjb::import("com.aspose.words.RelativeHorizontalPosition")
42
- watermark.setRelativeHorizontalPosition(relativeHorizontalPosition.PAGE)
43
- watermark.setRelativeVerticalPosition(relativeHorizontalPosition.PAGE)
44
-
45
- wrapType = Rjb::import("com.aspose.words.WrapType")
46
- watermark.setWrapType(wrapType.NONE)
47
-
48
- verticalAlignment = Rjb::import("com.aspose.words.VerticalAlignment")
49
- watermark.setVerticalAlignment(verticalAlignment.CENTER)
50
-
51
- horizontalAlignment = Rjb::import("com.aspose.words.HorizontalAlignment")
52
- watermark.setHorizontalAlignment(horizontalAlignment.CENTER)
53
-
54
- # Create a new paragraph and append the watermark to this paragraph.
55
- watermarkPara = Rjb::import("com.aspose.words.Paragraph").new(doc)
56
- watermarkPara.appendChild(watermark)
57
- sects = doc.getSections().toArray()
58
-
59
- # Insert the watermark into all headers of each document section.
60
- sects.each do |sect|
61
- headerFooterType = Rjb::import("com.aspose.words.HeaderFooterType")
62
- # There could be up to three different headers in each section, since we want
63
- # the watermark to appear on all pages, insert into all headers.
64
- insert_watermark_into_header(watermarkPara, sect, headerFooterType.HEADER_PRIMARY)
65
- insert_watermark_into_header(watermarkPara, sect, headerFooterType.HEADER_FIRST)
66
- insert_watermark_into_header(watermarkPara, sect, headerFooterType.HEADER_EVEN)
67
- end
68
- end
69
-
70
- def insert_watermark_into_header(watermarkPara, sect, headerType)
71
- header = sect.getHeadersFooters().getByHeaderFooterType(headerType)
72
-
73
- if header.nil? then
74
- # There is no header of the specified type in the current section, create it.
75
- header = Rjb::import("com.aspose.words.HeaderFooter").new(sect.getDocument(), headerType)
76
- sect.getHeadersFooters().add(header)
77
- end
78
-
79
- # Insert a clone of the watermark into the header.
80
- header.appendChild(watermarkPara.deepClone(true))
81
- end
82
-
83
- end
84
- end
1
+ module Asposewordsjavaforruby
2
+ module AddWatermark
3
+ def initialize()
4
+ # The path to the documents directory.
5
+ data_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + '/data/'
6
+
7
+ doc = Rjb::import('com.aspose.words.Document').new(data_dir + "TestWatermark.doc")
8
+
9
+ insert_watermark_text(doc, "CONFIDENTIAL")
10
+
11
+ doc.save(data_dir + "TestWatermark Out.doc")
12
+ end
13
+
14
+ =begin
15
+ Inserts a watermark into a document.
16
+
17
+ @param doc The input document.
18
+ @param watermarkText Text of the watermark.
19
+ =end
20
+ def insert_watermark_text(doc, watermark_text)
21
+ # Create a watermark shape. This will be a WordArt shape.
22
+ # You are free to try other shape types as watermarks.
23
+ shape_type = Rjb::import("com.aspose.words.ShapeType")
24
+ watermark = Rjb::import("com.aspose.words.Shape").new(doc, shape_type.TEXT_PLAIN_TEXT)
25
+
26
+ # Set up the text of the watermark.
27
+ watermark.getTextPath().setText(watermark_text)
28
+ watermark.getTextPath().setFontFamily("Arial")
29
+ watermark.setWidth(500)
30
+ watermark.setHeight(100)
31
+
32
+ # Text will be directed from the bottom-left to the top-right corner.
33
+ watermark.setRotation(-40)
34
+
35
+ # Remove the following three lines if you need a solid black text.
36
+ color = Rjb::import("java.awt.Color")
37
+ watermark.getFill().setColor(color.GRAY) # Try LightGray to get more Word-style watermark
38
+ watermark.setStrokeColor(color.GRAY) # Try LightGray to get more Word-style watermark
39
+
40
+ # Place the watermark in the page center.
41
+ relativeHorizontalPosition = Rjb::import("com.aspose.words.RelativeHorizontalPosition")
42
+ watermark.setRelativeHorizontalPosition(relativeHorizontalPosition.PAGE)
43
+ watermark.setRelativeVerticalPosition(relativeHorizontalPosition.PAGE)
44
+
45
+ wrapType = Rjb::import("com.aspose.words.WrapType")
46
+ watermark.setWrapType(wrapType.NONE)
47
+
48
+ verticalAlignment = Rjb::import("com.aspose.words.VerticalAlignment")
49
+ watermark.setVerticalAlignment(verticalAlignment.CENTER)
50
+
51
+ horizontalAlignment = Rjb::import("com.aspose.words.HorizontalAlignment")
52
+ watermark.setHorizontalAlignment(horizontalAlignment.CENTER)
53
+
54
+ # Create a new paragraph and append the watermark to this paragraph.
55
+ watermarkPara = Rjb::import("com.aspose.words.Paragraph").new(doc)
56
+ watermarkPara.appendChild(watermark)
57
+ sects = doc.getSections().toArray()
58
+
59
+ # Insert the watermark into all headers of each document section.
60
+ sects.each do |sect|
61
+ headerFooterType = Rjb::import("com.aspose.words.HeaderFooterType")
62
+ # There could be up to three different headers in each section, since we want
63
+ # the watermark to appear on all pages, insert into all headers.
64
+ insert_watermark_into_header(watermarkPara, sect, headerFooterType.HEADER_PRIMARY)
65
+ insert_watermark_into_header(watermarkPara, sect, headerFooterType.HEADER_FIRST)
66
+ insert_watermark_into_header(watermarkPara, sect, headerFooterType.HEADER_EVEN)
67
+ end
68
+ end
69
+
70
+ def insert_watermark_into_header(watermarkPara, sect, headerType)
71
+ header = sect.getHeadersFooters().getByHeaderFooterType(headerType)
72
+
73
+ if header.nil? then
74
+ # There is no header of the specified type in the current section, create it.
75
+ header = Rjb::import("com.aspose.words.HeaderFooter").new(sect.getDocument(), headerType)
76
+ sect.getHeadersFooters().add(header)
77
+ end
78
+
79
+ # Insert a clone of the watermark into the header.
80
+ header.appendChild(watermarkPara.deepClone(true))
81
+ end
82
+
83
+ end
84
+ end