asposewordsjavaforruby 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. data/Gempackage +3 -0
  2. data/LICENSE +21 -0
  3. data/README.md +2 -0
  4. data/Rakefile +2 -0
  5. data/asposewordsjavaforruby.gemspec +27 -0
  6. data/config/aspose.yml +5 -0
  7. data/data/Field.RemoveField.doc +0 -0
  8. data/data/LoadTxt.txt +15 -0
  9. data/data/Template.doc +0 -0
  10. data/data/Test.Styles.doc +0 -0
  11. data/data/TestAutofittables.doc +0 -0
  12. data/data/TestComments.doc +0 -0
  13. data/data/TestCompressImages.docx +0 -0
  14. data/data/TestFile.doc +0 -0
  15. data/data/TestWatermark.doc +0 -0
  16. data/data/bookmarks/Template.doc +0 -0
  17. data/data/bookmarks/TestDefect1352.doc +0 -0
  18. data/data/document/TestFile.doc +0 -0
  19. data/data/document/TestRemoveBreaks.doc +0 -0
  20. data/data/joiningandappending/TestFile.Destination.doc +0 -0
  21. data/data/joiningandappending/TestFile.DestinationList.doc +0 -0
  22. data/data/joiningandappending/TestFile.Source.doc +0 -0
  23. data/data/joiningandappending/TestFile.SourceList.doc +0 -0
  24. data/data/joiningandappending/TestFile.SourcePageSetup.doc +0 -0
  25. data/data/mailmerge/Template.doc +0 -0
  26. data/data/mailmerge/TestFile.doc +0 -0
  27. data/data/quickstart/Document.doc +0 -0
  28. data/data/quickstart/HelloWorld.docx +0 -0
  29. data/data/quickstart/MailMerge.doc +0 -0
  30. data/data/quickstart/ReplaceSimple.doc +0 -0
  31. data/data/quickstart/TestFile.Destination.doc +0 -0
  32. data/data/quickstart/TestFile.Source.doc +0 -0
  33. data/jars/aspose-words-15.4.0.jar +0 -0
  34. data/lib/asposewordsjavaforruby.rb +71 -0
  35. data/lib/asposewordsjavaforruby/addwatermark.rb +84 -0
  36. data/lib/asposewordsjavaforruby/appenddoc.rb +24 -0
  37. data/lib/asposewordsjavaforruby/appenddocument.rb +229 -0
  38. data/lib/asposewordsjavaforruby/applylicense.rb +16 -0
  39. data/lib/asposewordsjavaforruby/asposewordsjava.rb +24 -0
  40. data/lib/asposewordsjavaforruby/autofittables.rb +123 -0
  41. data/lib/asposewordsjavaforruby/bookmarks.rb +132 -0
  42. data/lib/asposewordsjavaforruby/checkformat.rb +70 -0
  43. data/lib/asposewordsjavaforruby/compressimages.rb +53 -0
  44. data/lib/asposewordsjavaforruby/doc2pdf.rb +15 -0
  45. data/lib/asposewordsjavaforruby/doctohtml.rb +26 -0
  46. data/lib/asposewordsjavaforruby/extractcontent.rb +395 -0
  47. data/lib/asposewordsjavaforruby/findandreplace.rb +29 -0
  48. data/lib/asposewordsjavaforruby/helloworld.rb +26 -0
  49. data/lib/asposewordsjavaforruby/imagetopdf.rb +71 -0
  50. data/lib/asposewordsjavaforruby/insertnestedfields.rb +39 -0
  51. data/lib/asposewordsjavaforruby/loadandsavetodisk.rb +20 -0
  52. data/lib/asposewordsjavaforruby/loadandsavetostream.rb +32 -0
  53. data/lib/asposewordsjavaforruby/loadtxt.rb +14 -0
  54. data/lib/asposewordsjavaforruby/mergefield.rb +45 -0
  55. data/lib/asposewordsjavaforruby/nodes.rb +29 -0
  56. data/lib/asposewordsjavaforruby/processcomments.rb +72 -0
  57. data/lib/asposewordsjavaforruby/removebreaks.rb +65 -0
  58. data/lib/asposewordsjavaforruby/removefield.rb +23 -0
  59. data/lib/asposewordsjavaforruby/saveasmultipagetiff.rb +26 -0
  60. data/lib/asposewordsjavaforruby/simplemailmerge.rb +23 -0
  61. data/lib/asposewordsjavaforruby/styles.rb +77 -0
  62. data/lib/asposewordsjavaforruby/updatefields.rb +62 -0
  63. data/lib/asposewordsjavaforruby/version.rb +3 -0
  64. metadata +65 -2
data/Gempackage ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +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
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,2 @@
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.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +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
data/config/aspose.yml ADDED
@@ -0,0 +1,5 @@
1
+ jar_dir: ../asposewordsjavaforruby/jars
2
+ license_path: ../asposewordsjavaforruby/license/path
3
+ jvm_args: -Xms512m -Xmx1G
4
+
5
+
Binary file
data/data/LoadTxt.txt ADDED
@@ -0,0 +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, ...).
15
+ 3. Letters (A, B, C, ... or a, b, c, ...).
data/data/Template.doc ADDED
Binary file
Binary file
Binary file
Binary file
Binary file
data/data/TestFile.doc ADDED
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +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
@@ -0,0 +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
@@ -0,0 +1,24 @@
1
+ module Asposewordsjavaforruby
2
+ module AppendDoc
3
+ def initialize()
4
+ # Append document.
5
+ append_documents()
6
+ end
7
+
8
+ def append_documents()
9
+ data_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + '/data/quickstart/'
10
+
11
+ # Load the destination and source documents from disk.
12
+ dst_doc = Rjb::import('com.aspose.words.Document').new(data_dir + "TestFile.Destination.doc")
13
+ src_doc = Rjb::import('com.aspose.words.Document').new(data_dir + "TestFile.Source.doc")
14
+
15
+ importformatmode = Rjb::import('com.aspose.words.ImportFormatMode')
16
+ source_formating = importformatmode.KEEP_SOURCE_FORMATTING
17
+
18
+ # Append the source document to the destination document while keeping the original formatting of the source document.
19
+ dst_doc.appendDocument(src_doc, source_formating)
20
+ dst_doc.save(data_dir + "TestFile Out.docx")
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,229 @@
1
+ module Asposewordsjavaforruby
2
+ module AppendDocument
3
+ def initialize()
4
+ # The path to the documents directory.
5
+ @data_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + '/data/joiningandappending/'
6
+
7
+ simple_append_document()
8
+ keep_source_formatting()
9
+ use_destination_styles()
10
+ join_continuous()
11
+ join_new_page()
12
+ restart_page_numbering()
13
+ link_headers_footers()
14
+ unlink_headers_footers()
15
+ remove_source_headers_footers()
16
+ different_page_setup()
17
+ end
18
+
19
+ =begin
20
+ Shows how to append a document to the end of another document using no additional options.
21
+ =end
22
+ def simple_append_document()
23
+ # Load the documents to join.
24
+ dst_doc = Rjb::import("com.aspose.words.Document").new(@data_dir + "TestFile.Destination.doc")
25
+ src_doc = Rjb::import("com.aspose.words.Document").new(@data_dir + "TestFile.Source.doc")
26
+
27
+ # Append the source document to the destination document using no extra options.
28
+ import_format_mode = Rjb::import("com.aspose.words.ImportFormatMode")
29
+ dst_doc.appendDocument(src_doc, import_format_mode.KEEP_SOURCE_FORMATTING)
30
+
31
+ # Save the document.
32
+ dst_doc.save(@data_dir + "TestFile.SimpleAppendDocument Out.docx")
33
+ end
34
+
35
+ =begin
36
+ Shows how to append a document to another document while keeping the original formatting.
37
+ =end
38
+ def keep_source_formatting()
39
+ # Load the documents to join.
40
+ dst_doc = Rjb::import("com.aspose.words.Document").new(@data_dir + "TestFile.Destination.doc")
41
+ src_doc = Rjb::import("com.aspose.words.Document").new(@data_dir + "TestFile.Source.doc")
42
+
43
+ # Append the source document to the destination document using no extra options.
44
+ import_format_mode = Rjb::import("com.aspose.words.ImportFormatMode")
45
+ dst_doc.appendDocument(src_doc, import_format_mode.KEEP_SOURCE_FORMATTING)
46
+
47
+ # Save the document.
48
+ dst_doc.save(@data_dir + "TestFile.KeepSourceFormatting Out.docx")
49
+ end
50
+
51
+ =begin
52
+ Shows how to append a document to another document using the formatting of the destination document.
53
+ =end
54
+ def use_destination_styles()
55
+ # Load the documents to join.
56
+ dst_doc = Rjb::import("com.aspose.words.Document").new(@data_dir + "TestFile.Destination.doc")
57
+ src_doc = Rjb::import("com.aspose.words.Document").new(@data_dir + "TestFile.Source.doc")
58
+
59
+ # Append the source document to the destination document using no extra options.
60
+ import_format_mode = Rjb::import("com.aspose.words.ImportFormatMode")
61
+ dst_doc.appendDocument(src_doc, import_format_mode.USE_DESTINATION_STYLES)
62
+
63
+ # Save the document.
64
+ dst_doc.save(@data_dir + "TestFile.UseDestinationStyles Out.docx")
65
+ end
66
+
67
+ =begin
68
+ Shows how to append a document to another document so the content flows continuously.
69
+ =end
70
+ def join_continuous()
71
+ # Load the documents to join.
72
+ dst_doc = Rjb::import("com.aspose.words.Document").new(@data_dir + "TestFile.Destination.doc")
73
+ src_doc = Rjb::import("com.aspose.words.Document").new(@data_dir + "TestFile.Source.doc")
74
+
75
+ # Make the document appear straight after the destination documents content.
76
+ section_start = Rjb::import("com.aspose.words.SectionStart")
77
+ src_doc.getFirstSection().getPageSetup().setSectionStart(section_start.CONTINUOUS)
78
+
79
+ # Append the source document using the original styles found in the source document.
80
+ import_format_mode = Rjb::import("com.aspose.words.ImportFormatMode")
81
+ dst_doc.appendDocument(src_doc, import_format_mode.KEEP_SOURCE_FORMATTING)
82
+
83
+ # Save the document.
84
+ dst_doc.save(@data_dir + "TestFile.JoinContinuous Out.docx")
85
+ end
86
+
87
+ =begin
88
+ Shows how to append a document to another document so it starts on a new page.
89
+ =end
90
+ def join_new_page()
91
+ # Load the documents to join.
92
+ dst_doc = Rjb::import("com.aspose.words.Document").new(@data_dir + "TestFile.Destination.doc")
93
+ src_doc = Rjb::import("com.aspose.words.Document").new(@data_dir + "TestFile.Source.doc")
94
+
95
+ # Set the appended document to start on a new page.
96
+ section_start = Rjb::import("com.aspose.words.SectionStart")
97
+ src_doc.getFirstSection().getPageSetup().setSectionStart(section_start.NEW_PAGE)
98
+
99
+ # Append the source document using the original styles found in the source document.
100
+ import_format_mode = Rjb::import("com.aspose.words.ImportFormatMode")
101
+ dst_doc.appendDocument(src_doc, import_format_mode.KEEP_SOURCE_FORMATTING)
102
+
103
+ # Save the document.
104
+ dst_doc.save(@data_dir + "TestFile.JoinNewPage Out.docx")
105
+ end
106
+
107
+ =begin
108
+ Shows how to append a document to another document with page numbering restarted.
109
+ =end
110
+ def restart_page_numbering()
111
+ # Load the documents to join.
112
+ dst_doc = Rjb::import("com.aspose.words.Document").new(@data_dir + "TestFile.Destination.doc")
113
+ src_doc = Rjb::import("com.aspose.words.Document").new(@data_dir + "TestFile.Source.doc")
114
+
115
+ # Set the appended document to start on a new page.
116
+ section_start = Rjb::import("com.aspose.words.SectionStart")
117
+ src_doc.getFirstSection().getPageSetup().setSectionStart(section_start.NEW_PAGE)
118
+
119
+ # Restart the page numbering for the document to be appended.
120
+ src_doc.getFirstSection().getPageSetup().setRestartPageNumbering(true)
121
+
122
+ # Append the source document using the original styles found in the source document.
123
+ import_format_mode = Rjb::import("com.aspose.words.ImportFormatMode")
124
+ dst_doc.appendDocument(src_doc, import_format_mode.KEEP_SOURCE_FORMATTING)
125
+
126
+ # Save the document.
127
+ dst_doc.save(@data_dir + "TestFile.RestartPageNumbering Out.docx")
128
+ end
129
+
130
+ =begin
131
+ Shows how to append a document to another document and continue headers and footers from the destination document.
132
+ =end
133
+ def link_headers_footers()
134
+ # Load the documents to join.
135
+ dst_doc = Rjb::import("com.aspose.words.Document").new(@data_dir + "TestFile.Destination.doc")
136
+ src_doc = Rjb::import("com.aspose.words.Document").new(@data_dir + "TestFile.Source.doc")
137
+
138
+ # Set the appended document to start on a new page.
139
+ section_start = Rjb::import("com.aspose.words.SectionStart")
140
+ src_doc.getFirstSection().getPageSetup().setSectionStart(section_start.NEW_PAGE)
141
+
142
+ # Link the headers and footers in the source document to the previous section.
143
+ # This will override any headers or footers already found in the source document.
144
+ src_doc.getFirstSection().getHeadersFooters().linkToPrevious(true)
145
+
146
+ import_format_mode = Rjb::import("com.aspose.words.ImportFormatMode")
147
+ dst_doc.appendDocument(src_doc, import_format_mode.KEEP_SOURCE_FORMATTING)
148
+
149
+ # Save the document.
150
+ dst_doc.save(@data_dir + "TestFile.LinkHeadersFooters Out.docx")
151
+ end
152
+
153
+ =begin
154
+ Shows how to append a document to another document so headers and footers do not continue from the destination document.
155
+ =end
156
+ def unlink_headers_footers()
157
+ # Load the documents to join.
158
+ dst_doc = Rjb::import("com.aspose.words.Document").new(@data_dir + "TestFile.Destination.doc")
159
+ src_doc = Rjb::import("com.aspose.words.Document").new(@data_dir + "TestFile.Source.doc")
160
+
161
+ # Even a document with no headers or footers can still have the LinkToPrevious setting set to true.
162
+ # Unlink the headers and footers in the source document to stop this from continuing the headers and footers
163
+ # from the destination document.
164
+ src_doc.getFirstSection().getHeadersFooters().linkToPrevious(false)
165
+
166
+ import_format_mode = Rjb::import("com.aspose.words.ImportFormatMode")
167
+ dst_doc.appendDocument(src_doc, import_format_mode.KEEP_SOURCE_FORMATTING)
168
+
169
+ # Save the document.
170
+ dst_doc.save(@data_dir + "TestFile.UnlinkHeadersFooters Out.docx")
171
+ end
172
+
173
+ =begin
174
+ Shows how to append a document to another document so headers and footers do not continue from the destination document.
175
+ =end
176
+ def remove_source_headers_footers()
177
+ # Load the documents to join.
178
+ dst_doc = Rjb::import("com.aspose.words.Document").new(@data_dir + "TestFile.Destination.doc")
179
+ src_doc = Rjb::import("com.aspose.words.Document").new(@data_dir + "TestFile.Source.doc")
180
+
181
+ # Remove the headers and footers from each of the sections in the source document.
182
+ sections = src_doc.getSections().toArray()
183
+ sections.each do |section|
184
+ section.clearHeadersFooters()
185
+ end
186
+
187
+ # Even after the headers and footers are cleared from the source document, the "LinkToPrevious" setting
188
+ # for HeadersFooters can still be set. This will cause the headers and footers to continue from the destination
189
+ # document. This should set to false to avoid this behaviour.
190
+ src_doc.getFirstSection().getHeadersFooters().linkToPrevious(false)
191
+
192
+ import_format_mode = Rjb::import("com.aspose.words.ImportFormatMode")
193
+ dst_doc.appendDocument(src_doc, import_format_mode.KEEP_SOURCE_FORMATTING)
194
+
195
+ # Save the document.
196
+ dst_doc.save(@data_dir + "TestFile.RemoveSourceHeadersFooters Out.docx")
197
+ end
198
+
199
+ =begin
200
+ Shows how to append a document to another document continuously which has different page settings.
201
+ =end
202
+ def different_page_setup()
203
+ # Load the documents to join.
204
+ dst_doc = Rjb::import("com.aspose.words.Document").new(@data_dir + "TestFile.Destination.doc")
205
+ src_doc = Rjb::import("com.aspose.words.Document").new(@data_dir + "TestFile.Source.doc")
206
+
207
+ # Set the source document to continue straight after the end of the destination document.
208
+ # If some page setup settings are different then this may not work and the source document will appear
209
+ # on a new page.
210
+ section_start = Rjb::import("com.aspose.words.SectionStart")
211
+ src_doc.getFirstSection().getPageSetup().setSectionStart(section_start.CONTINUOUS)
212
+
213
+ # To ensure this does not happen when the source document has different page setup settings make sure the
214
+ # settings are identical between the last section of the destination document.
215
+ # If there are further continuous sections that follow on in the source document then this will need to be
216
+ # repeated for those sections as well.
217
+ src_doc.getFirstSection().getPageSetup().setPageWidth(dst_doc.getLastSection().getPageSetup().getPageWidth())
218
+ src_doc.getFirstSection().getPageSetup().setPageHeight(dst_doc.getLastSection().getPageSetup().getPageHeight())
219
+ src_doc.getFirstSection().getPageSetup().setOrientation(dst_doc.getLastSection().getPageSetup().getOrientation())
220
+
221
+ import_format_mode = Rjb::import("com.aspose.words.ImportFormatMode")
222
+ dst_doc.appendDocument(src_doc, import_format_mode.KEEP_SOURCE_FORMATTING)
223
+
224
+ # Save the document.
225
+ dst_doc.save(@data_dir + "TestFile.DifferentPageSetup Out.docx")
226
+ end
227
+
228
+ end
229
+ end