Module: Asposewordsjavaforruby::AppendDocument
- Defined in:
- lib/asposewordsjavaforruby/appenddocument.rb
Instance Method Summary collapse
-
#different_page_setup ⇒ Object
Shows how to append a document to another document continuously which has different page settings.
- #initialize ⇒ Object
-
#join_continuous ⇒ Object
Shows how to append a document to another document so the content flows continuously.
-
#join_new_page ⇒ Object
Shows how to append a document to another document so it starts on a new page.
-
#keep_source_formatting ⇒ Object
Shows how to append a document to another document while keeping the original formatting.
-
#link_headers_footers ⇒ Object
Shows how to append a document to another document and continue headers and footers from the destination document.
-
#remove_source_headers_footers ⇒ Object
Shows how to append a document to another document so headers and footers do not continue from the destination document.
-
#restart_page_numbering ⇒ Object
Shows how to append a document to another document with page numbering restarted.
-
#simple_append_document ⇒ Object
Shows how to append a document to the end of another document using no additional options.
-
#unlink_headers_footers ⇒ Object
Shows how to append a document to another document so headers and footers do not continue from the destination document.
-
#use_destination_styles ⇒ Object
Shows how to append a document to another document using the formatting of the destination document.
Instance Method Details
#different_page_setup ⇒ Object
Shows how to append a document to another document continuously which has different page settings.
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/asposewordsjavaforruby/appenddocument.rb', line 202 def different_page_setup() # Load the documents to join. dst_doc = Rjb::import("com.aspose.words.Document").new(@data_dir + "TestFile.Destination.doc") src_doc = Rjb::import("com.aspose.words.Document").new(@data_dir + "TestFile.Source.doc") # Set the source document to continue straight after the end of the destination document. # If some page setup settings are different then this may not work and the source document will appear # on a new page. section_start = Rjb::import("com.aspose.words.SectionStart") src_doc.getFirstSection().getPageSetup().setSectionStart(section_start.CONTINUOUS) # To ensure this does not happen when the source document has different page setup settings make sure the # settings are identical between the last section of the destination document. # If there are further continuous sections that follow on in the source document then this will need to be # repeated for those sections as well. src_doc.getFirstSection().getPageSetup().setPageWidth(dst_doc.getLastSection().getPageSetup().getPageWidth()) src_doc.getFirstSection().getPageSetup().setPageHeight(dst_doc.getLastSection().getPageSetup().getPageHeight()) src_doc.getFirstSection().getPageSetup().setOrientation(dst_doc.getLastSection().getPageSetup().getOrientation()) import_format_mode = Rjb::import("com.aspose.words.ImportFormatMode") dst_doc.appendDocument(src_doc, import_format_mode.KEEP_SOURCE_FORMATTING) # Save the document. dst_doc.save(@data_dir + "TestFile.DifferentPageSetup Out.docx") end |
#initialize ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/asposewordsjavaforruby/appenddocument.rb', line 3 def initialize() # The path to the documents directory. @data_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + '/data/joiningandappending/' simple_append_document() keep_source_formatting() use_destination_styles() join_continuous() join_new_page() restart_page_numbering() () () () different_page_setup() end |
#join_continuous ⇒ Object
Shows how to append a document to another document so the content flows continuously.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/asposewordsjavaforruby/appenddocument.rb', line 70 def join_continuous() # Load the documents to join. dst_doc = Rjb::import("com.aspose.words.Document").new(@data_dir + "TestFile.Destination.doc") src_doc = Rjb::import("com.aspose.words.Document").new(@data_dir + "TestFile.Source.doc") # Make the document appear straight after the destination documents content. section_start = Rjb::import("com.aspose.words.SectionStart") src_doc.getFirstSection().getPageSetup().setSectionStart(section_start.CONTINUOUS) # Append the source document using the original styles found in the source document. import_format_mode = Rjb::import("com.aspose.words.ImportFormatMode") dst_doc.appendDocument(src_doc, import_format_mode.KEEP_SOURCE_FORMATTING) # Save the document. dst_doc.save(@data_dir + "TestFile.JoinContinuous Out.docx") end |
#join_new_page ⇒ Object
Shows how to append a document to another document so it starts on a new page.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/asposewordsjavaforruby/appenddocument.rb', line 90 def join_new_page() # Load the documents to join. dst_doc = Rjb::import("com.aspose.words.Document").new(@data_dir + "TestFile.Destination.doc") src_doc = Rjb::import("com.aspose.words.Document").new(@data_dir + "TestFile.Source.doc") # Set the appended document to start on a new page. section_start = Rjb::import("com.aspose.words.SectionStart") src_doc.getFirstSection().getPageSetup().setSectionStart(section_start.NEW_PAGE) # Append the source document using the original styles found in the source document. import_format_mode = Rjb::import("com.aspose.words.ImportFormatMode") dst_doc.appendDocument(src_doc, import_format_mode.KEEP_SOURCE_FORMATTING) # Save the document. dst_doc.save(@data_dir + "TestFile.JoinNewPage Out.docx") end |
#keep_source_formatting ⇒ Object
Shows how to append a document to another document while keeping the original formatting.
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/asposewordsjavaforruby/appenddocument.rb', line 38 def keep_source_formatting() # Load the documents to join. dst_doc = Rjb::import("com.aspose.words.Document").new(@data_dir + "TestFile.Destination.doc") src_doc = Rjb::import("com.aspose.words.Document").new(@data_dir + "TestFile.Source.doc") # Append the source document to the destination document using no extra options. import_format_mode = Rjb::import("com.aspose.words.ImportFormatMode") dst_doc.appendDocument(src_doc, import_format_mode.KEEP_SOURCE_FORMATTING) # Save the document. dst_doc.save(@data_dir + "TestFile.KeepSourceFormatting Out.docx") end |
#link_headers_footers ⇒ Object
Shows how to append a document to another document and continue headers and footers from the destination document.
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/asposewordsjavaforruby/appenddocument.rb', line 133 def () # Load the documents to join. dst_doc = Rjb::import("com.aspose.words.Document").new(@data_dir + "TestFile.Destination.doc") src_doc = Rjb::import("com.aspose.words.Document").new(@data_dir + "TestFile.Source.doc") # Set the appended document to start on a new page. section_start = Rjb::import("com.aspose.words.SectionStart") src_doc.getFirstSection().getPageSetup().setSectionStart(section_start.NEW_PAGE) # Link the headers and footers in the source document to the previous section. # This will override any headers or footers already found in the source document. src_doc.getFirstSection().().linkToPrevious(true) import_format_mode = Rjb::import("com.aspose.words.ImportFormatMode") dst_doc.appendDocument(src_doc, import_format_mode.KEEP_SOURCE_FORMATTING) # Save the document. dst_doc.save(@data_dir + "TestFile.LinkHeadersFooters Out.docx") end |
#remove_source_headers_footers ⇒ Object
Shows how to append a document to another document so headers and footers do not continue from the destination document.
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/asposewordsjavaforruby/appenddocument.rb', line 176 def () # Load the documents to join. dst_doc = Rjb::import("com.aspose.words.Document").new(@data_dir + "TestFile.Destination.doc") src_doc = Rjb::import("com.aspose.words.Document").new(@data_dir + "TestFile.Source.doc") # Remove the headers and footers from each of the sections in the source document. sections = src_doc.getSections().toArray() sections.each do |section| section.() end # Even after the headers and footers are cleared from the source document, the "LinkToPrevious" setting # for HeadersFooters can still be set. This will cause the headers and footers to continue from the destination # document. This should set to false to avoid this behaviour. src_doc.getFirstSection().().linkToPrevious(false) import_format_mode = Rjb::import("com.aspose.words.ImportFormatMode") dst_doc.appendDocument(src_doc, import_format_mode.KEEP_SOURCE_FORMATTING) # Save the document. dst_doc.save(@data_dir + "TestFile.RemoveSourceHeadersFooters Out.docx") end |
#restart_page_numbering ⇒ Object
Shows how to append a document to another document with page numbering restarted.
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/asposewordsjavaforruby/appenddocument.rb', line 110 def restart_page_numbering() # Load the documents to join. dst_doc = Rjb::import("com.aspose.words.Document").new(@data_dir + "TestFile.Destination.doc") src_doc = Rjb::import("com.aspose.words.Document").new(@data_dir + "TestFile.Source.doc") # Set the appended document to start on a new page. section_start = Rjb::import("com.aspose.words.SectionStart") src_doc.getFirstSection().getPageSetup().setSectionStart(section_start.NEW_PAGE) # Restart the page numbering for the document to be appended. src_doc.getFirstSection().getPageSetup().setRestartPageNumbering(true) # Append the source document using the original styles found in the source document. import_format_mode = Rjb::import("com.aspose.words.ImportFormatMode") dst_doc.appendDocument(src_doc, import_format_mode.KEEP_SOURCE_FORMATTING) # Save the document. dst_doc.save(@data_dir + "TestFile.RestartPageNumbering Out.docx") end |
#simple_append_document ⇒ Object
Shows how to append a document to the end of another document using no additional options.
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/asposewordsjavaforruby/appenddocument.rb', line 22 def simple_append_document() # Load the documents to join. dst_doc = Rjb::import("com.aspose.words.Document").new(@data_dir + "TestFile.Destination.doc") src_doc = Rjb::import("com.aspose.words.Document").new(@data_dir + "TestFile.Source.doc") # Append the source document to the destination document using no extra options. import_format_mode = Rjb::import("com.aspose.words.ImportFormatMode") dst_doc.appendDocument(src_doc, import_format_mode.KEEP_SOURCE_FORMATTING) # Save the document. dst_doc.save(@data_dir + "TestFile.SimpleAppendDocument Out.docx") end |
#unlink_headers_footers ⇒ Object
Shows how to append a document to another document so headers and footers do not continue from the destination document.
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/asposewordsjavaforruby/appenddocument.rb', line 156 def () # Load the documents to join. dst_doc = Rjb::import("com.aspose.words.Document").new(@data_dir + "TestFile.Destination.doc") src_doc = Rjb::import("com.aspose.words.Document").new(@data_dir + "TestFile.Source.doc") # Even a document with no headers or footers can still have the LinkToPrevious setting set to true. # Unlink the headers and footers in the source document to stop this from continuing the headers and footers # from the destination document. src_doc.getFirstSection().().linkToPrevious(false) import_format_mode = Rjb::import("com.aspose.words.ImportFormatMode") dst_doc.appendDocument(src_doc, import_format_mode.KEEP_SOURCE_FORMATTING) # Save the document. dst_doc.save(@data_dir + "TestFile.UnlinkHeadersFooters Out.docx") end |
#use_destination_styles ⇒ Object
Shows how to append a document to another document using the formatting of the destination document.
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/asposewordsjavaforruby/appenddocument.rb', line 54 def use_destination_styles() # Load the documents to join. dst_doc = Rjb::import("com.aspose.words.Document").new(@data_dir + "TestFile.Destination.doc") src_doc = Rjb::import("com.aspose.words.Document").new(@data_dir + "TestFile.Source.doc") # Append the source document to the destination document using no extra options. import_format_mode = Rjb::import("com.aspose.words.ImportFormatMode") dst_doc.appendDocument(src_doc, import_format_mode.USE_DESTINATION_STYLES) # Save the document. dst_doc.save(@data_dir + "TestFile.UseDestinationStyles Out.docx") end |