asposewordsjavaforruby 0.0.4 → 0.0.5

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 (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
@@ -1,45 +1,45 @@
1
- module Asposewordsjavaforruby
2
- module HandleMergeField
3
- def initialize()
4
- # The path to the documents directory.
5
- data_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + '/data/mailmerge/'
6
-
7
- # Open the document.
8
- doc = Rjb::import('com.aspose.words.Document').new(data_dir + "Template.doc")
9
- #$doc->getMailMerge()->setFieldMergingCallback(new HandleMergeField())
10
-
11
- fieldNames = Array["RecipientName","SenderName","FaxNumber","PhoneNumber","Subject","Body","Urgent","ForReview","PleaseComment"]
12
- fieldValues = Array["Josh","Jenny","123456789","","Hello","Test Pakistan 1", true, false, true]
13
- doc.getMailMerge().execute(fieldNames,fieldValues)
14
-
15
- # Save the document.
16
- doc.save(data_dir + "Template Out.doc")
17
-
18
- remove_empty_regions()
19
- end
20
-
21
- def remove_empty_regions()
22
- # The path to the documents directory.
23
- data_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + '/data/mailmerge/'
24
-
25
- # Open the document.
26
- doc = Rjb::import('com.aspose.words.Document').new(data_dir + "TestFile.doc")
27
-
28
- # Create a dummy data source containing no data.
29
- data = Rjb::import('com.aspose.words.DataSet').new
30
- #DataSet data = new DataSet()
31
-
32
- # Set the appropriate mail merge clean up options to remove any unused regions from the document.
33
- mailmerge_cleanup_options = Rjb::import('com.aspose.words.MailMergeCleanupOptions')
34
- doc.getMailMerge().setCleanupOptions(mailmerge_cleanup_options.REMOVE_UNUSED_REGIONS)
35
-
36
- # Execute mail merge which will have no effect as there is no data. However the regions found in the document will be removed
37
- # automatically as they are unused.
38
- doc.getMailMerge().executeWithRegions(data)
39
-
40
- # Save the output document to disk.
41
- doc.save(data_dir + "TestFile.RemoveEmptyRegions Out.doc")
42
- end
43
-
44
- end
45
- end
1
+ module Asposewordsjavaforruby
2
+ module HandleMergeField
3
+ def initialize()
4
+ # The path to the documents directory.
5
+ data_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + '/data/mailmerge/'
6
+
7
+ # Open the document.
8
+ doc = Rjb::import('com.aspose.words.Document').new(data_dir + "Template.doc")
9
+ #$doc->getMailMerge()->setFieldMergingCallback(new HandleMergeField())
10
+
11
+ fieldNames = Array["RecipientName","SenderName","FaxNumber","PhoneNumber","Subject","Body","Urgent","ForReview","PleaseComment"]
12
+ fieldValues = Array["Josh","Jenny","123456789","","Hello","Test Pakistan 1", true, false, true]
13
+ doc.getMailMerge().execute(fieldNames,fieldValues)
14
+
15
+ # Save the document.
16
+ doc.save(data_dir + "Template Out.doc")
17
+
18
+ remove_empty_regions()
19
+ end
20
+
21
+ def remove_empty_regions()
22
+ # The path to the documents directory.
23
+ data_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + '/data/mailmerge/'
24
+
25
+ # Open the document.
26
+ doc = Rjb::import('com.aspose.words.Document').new(data_dir + "TestFile.doc")
27
+
28
+ # Create a dummy data source containing no data.
29
+ data = Rjb::import('com.aspose.words.DataSet').new
30
+ #DataSet data = new DataSet()
31
+
32
+ # Set the appropriate mail merge clean up options to remove any unused regions from the document.
33
+ mailmerge_cleanup_options = Rjb::import('com.aspose.words.MailMergeCleanupOptions')
34
+ doc.getMailMerge().setCleanupOptions(mailmerge_cleanup_options.REMOVE_UNUSED_REGIONS)
35
+
36
+ # Execute mail merge which will have no effect as there is no data. However the regions found in the document will be removed
37
+ # automatically as they are unused.
38
+ doc.getMailMerge().executeWithRegions(data)
39
+
40
+ # Save the output document to disk.
41
+ doc.save(data_dir + "TestFile.RemoveEmptyRegions Out.doc")
42
+ end
43
+
44
+ end
45
+ end
@@ -1,29 +1,29 @@
1
- module Asposewordsjavaforruby
2
- module Nodes
3
- def initialize()
4
- # get nodes
5
- get_nodes()
6
- end
7
-
8
- def get_nodes()
9
- # The path to the documents directory.
10
- data_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + '/data/quickstart/'
11
-
12
- # Create a new document.
13
- doc = Rjb::import('com.aspose.words.Document').new()
14
-
15
- # Creates and adds a paragraph node to the document.
16
- para = Rjb::import("com.aspose.words.Paragraph").new(doc)
17
-
18
- # Typed access to the last section of the document.
19
- section = doc.getLastSection()
20
- section.getBody().appendChild(para)
21
-
22
- # Next print the node type of one of the nodes in the document.
23
- node_type = doc.getFirstSection().getBody().getNodeType()
24
- node = Rjb::import("com.aspose.words.Node")
25
- puts "NodeType: " + node.nodeTypeToString(node_type)
26
- end
27
-
28
- end
29
- end
1
+ module Asposewordsjavaforruby
2
+ module Nodes
3
+ def initialize()
4
+ # get nodes
5
+ get_nodes()
6
+ end
7
+
8
+ def get_nodes()
9
+ # The path to the documents directory.
10
+ data_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + '/data/quickstart/'
11
+
12
+ # Create a new document.
13
+ doc = Rjb::import('com.aspose.words.Document').new()
14
+
15
+ # Creates and adds a paragraph node to the document.
16
+ para = Rjb::import("com.aspose.words.Paragraph").new(doc)
17
+
18
+ # Typed access to the last section of the document.
19
+ section = doc.getLastSection()
20
+ section.getBody().appendChild(para)
21
+
22
+ # Next print the node type of one of the nodes in the document.
23
+ node_type = doc.getFirstSection().getBody().getNodeType()
24
+ node = Rjb::import("com.aspose.words.Node")
25
+ puts "NodeType: " + node.nodeTypeToString(node_type)
26
+ end
27
+
28
+ end
29
+ end
@@ -1,72 +1,72 @@
1
- module Asposewordsjavaforruby
2
- module ProcessComments
3
- def initialize()
4
- # The path to the documents directory.
5
- data_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + '/data/'
6
-
7
- # Open the document.
8
- doc = Rjb::import('com.aspose.words.Document').new(data_dir + 'TestComments.doc')
9
-
10
- # Get all comments from document
11
- extract_comments(doc)
12
-
13
- # Remove comments by the "pm" author.
14
- remove_comment($doc, "pm");
15
- puts "Comments from 'pm' are removed!"
16
-
17
- # Remove all comments.
18
- remove_comments(doc)
19
- puts "All comments are removed!"
20
-
21
- # Save the document.
22
- doc.save(data_dir + "TestComments Out.doc")
23
- end
24
-
25
- def extract_comments(doc)
26
- # Call method
27
- collected_comments = Rjb::import('java.util.ArrayList').new
28
-
29
- # Collect all comments in the document
30
- node_type = Rjb::import('com.aspose.words.NodeType')
31
- comments = doc.getChildNodes(node_type.COMMENT, true).toArray()
32
-
33
- save_format = Rjb::import('com.aspose.words.SaveFormat')
34
-
35
- comments.each do |comment|
36
- author = comment.getAuthor()
37
- date_time = comment.getDateTime()
38
- format = comment.toString(save_format.TEXT)
39
- puts "Author:" + author.to_s + " DateTime:" + date_time.to_string + " Comment:" + format.to_s
40
- end
41
- end
42
-
43
- def remove_comment(doc, author_name)
44
- raise 'author_name not specified.' if author_name.empty?
45
-
46
- # Collect all comments in the document
47
- node_type = Rjb::import('com.aspose.words.NodeType')
48
- comments = doc.getChildNodes(node_type.COMMENT, true)
49
- comments_count = comments.getCount()
50
-
51
- # Look through all comments and remove those written by the authorName author.
52
- i = comments_count
53
- i = i - 1
54
- while (i >= 0) do
55
- comment = comments.get(i)
56
- author = comment.getAuthor().chomp('"').reverse.chomp('"').reverse
57
- if (author == author_name) then
58
- comment.remove()
59
- end
60
- i = i - 1
61
- end
62
- end
63
-
64
- def remove_comments(doc)
65
- # Collect all comments in the document
66
- node_type = Rjb::import('com.aspose.words.NodeType')
67
- comments = doc.getChildNodes(node_type.COMMENT, true)
68
- comments.clear()
69
- end
70
-
71
- end
72
- end
1
+ module Asposewordsjavaforruby
2
+ module ProcessComments
3
+ def initialize()
4
+ # The path to the documents directory.
5
+ data_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + '/data/'
6
+
7
+ # Open the document.
8
+ doc = Rjb::import('com.aspose.words.Document').new(data_dir + 'TestComments.doc')
9
+
10
+ # Get all comments from document
11
+ extract_comments(doc)
12
+
13
+ # Remove comments by the "pm" author.
14
+ remove_comment($doc, "pm");
15
+ puts "Comments from 'pm' are removed!"
16
+
17
+ # Remove all comments.
18
+ remove_comments(doc)
19
+ puts "All comments are removed!"
20
+
21
+ # Save the document.
22
+ doc.save(data_dir + "TestComments Out.doc")
23
+ end
24
+
25
+ def extract_comments(doc)
26
+ # Call method
27
+ collected_comments = Rjb::import('java.util.ArrayList').new
28
+
29
+ # Collect all comments in the document
30
+ node_type = Rjb::import('com.aspose.words.NodeType')
31
+ comments = doc.getChildNodes(node_type.COMMENT, true).toArray()
32
+
33
+ save_format = Rjb::import('com.aspose.words.SaveFormat')
34
+
35
+ comments.each do |comment|
36
+ author = comment.getAuthor()
37
+ date_time = comment.getDateTime()
38
+ format = comment.toString(save_format.TEXT)
39
+ puts "Author:" + author.to_s + " DateTime:" + date_time.to_string + " Comment:" + format.to_s
40
+ end
41
+ end
42
+
43
+ def remove_comment(doc, author_name)
44
+ raise 'author_name not specified.' if author_name.empty?
45
+
46
+ # Collect all comments in the document
47
+ node_type = Rjb::import('com.aspose.words.NodeType')
48
+ comments = doc.getChildNodes(node_type.COMMENT, true)
49
+ comments_count = comments.getCount()
50
+
51
+ # Look through all comments and remove those written by the authorName author.
52
+ i = comments_count
53
+ i = i - 1
54
+ while (i >= 0) do
55
+ comment = comments.get(i)
56
+ author = comment.getAuthor().chomp('"').reverse.chomp('"').reverse
57
+ if (author == author_name) then
58
+ comment.remove()
59
+ end
60
+ i = i - 1
61
+ end
62
+ end
63
+
64
+ def remove_comments(doc)
65
+ # Collect all comments in the document
66
+ node_type = Rjb::import('com.aspose.words.NodeType')
67
+ comments = doc.getChildNodes(node_type.COMMENT, true)
68
+ comments.clear()
69
+ end
70
+
71
+ end
72
+ end
@@ -1,65 +1,65 @@
1
- module Asposewordsjavaforruby
2
- module RemoveBreaks
3
- def initialize()
4
- # The path to the documents directory.
5
- data_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + '/data/document/'
6
-
7
- # Open the document.
8
- doc = Rjb::import('com.aspose.words.Document').new(data_dir + "TestRemoveBreaks.doc")
9
-
10
- # Remove the page and section breaks from the document.
11
- # In Aspose.Words section breaks are represented as separate Section nodes in the document.
12
- # To remove these separate sections the sections are combined.
13
- remove_page_breaks(doc)
14
- #remove_section_breaks(doc)
15
-
16
- # Save the document.
17
- doc.save(data_dir + "TestRemoveBreaks Out.doc")
18
- end
19
-
20
- def remove_page_breaks(doc)
21
- # Retrieve all paragraphs in the document.
22
- node_type = Rjb::import("com.aspose.words.NodeType")
23
- paragraphs = doc.getChildNodes(node_type.PARAGRAPH, true)
24
- paragraphs_count = paragraphs.getCount()
25
-
26
- i = 0
27
- while (i < paragraphs_count) do
28
- paragraphs = doc.getChildNodes(node_type.PARAGRAPH, true)
29
- para = paragraphs.get(i)
30
-
31
- if (para.getParagraphFormat().getPageBreakBefore()) then
32
- para.getParagraphFormat().setPageBreakBefore(false)
33
- end
34
-
35
- runs = para.getRuns().toArray()
36
- runs.each do |run|
37
- control_char = Rjb::import("com.aspose.words.ControlChar")
38
- p run.getText().contains(control_char.PAGE_BREAK)
39
- abort()
40
- #if (run.getText().contains(control_char.PAGE_BREAK)) then
41
- run_text = run.getText()
42
- run_text = run_text.gsub(control_char.PAGE_BREAK, '')
43
- run.setText(run_text)
44
- #end
45
- end
46
- i = i + 1
47
- end
48
- end
49
-
50
- def remove_section_breaks(doc)
51
- # Loop through all sections starting from the section that precedes the last one
52
- # and moving to the first section.
53
- i = doc.getSections().getCount()
54
- i = i - 2
55
- while (i >= 0) do
56
- # Copy the content of the current section to the beginning of the last section.
57
- doc.getLastSection().prependContent(doc.getSections().get(i))
58
- # Remove the copied section.
59
- doc.getSections().get(i).remove()
60
- i = i - 1
61
- end
62
- end
63
-
64
- end
65
- end
1
+ module Asposewordsjavaforruby
2
+ module RemoveBreaks
3
+ def initialize()
4
+ # The path to the documents directory.
5
+ data_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + '/data/document/'
6
+
7
+ # Open the document.
8
+ doc = Rjb::import('com.aspose.words.Document').new(data_dir + "TestRemoveBreaks.doc")
9
+
10
+ # Remove the page and section breaks from the document.
11
+ # In Aspose.Words section breaks are represented as separate Section nodes in the document.
12
+ # To remove these separate sections the sections are combined.
13
+ remove_page_breaks(doc)
14
+ #remove_section_breaks(doc)
15
+
16
+ # Save the document.
17
+ doc.save(data_dir + "TestRemoveBreaks Out.doc")
18
+ end
19
+
20
+ def remove_page_breaks(doc)
21
+ # Retrieve all paragraphs in the document.
22
+ node_type = Rjb::import("com.aspose.words.NodeType")
23
+ paragraphs = doc.getChildNodes(node_type.PARAGRAPH, true)
24
+ paragraphs_count = paragraphs.getCount()
25
+
26
+ i = 0
27
+ while (i < paragraphs_count) do
28
+ paragraphs = doc.getChildNodes(node_type.PARAGRAPH, true)
29
+ para = paragraphs.get(i)
30
+
31
+ if (para.getParagraphFormat().getPageBreakBefore()) then
32
+ para.getParagraphFormat().setPageBreakBefore(false)
33
+ end
34
+
35
+ runs = para.getRuns().toArray()
36
+ runs.each do |run|
37
+ control_char = Rjb::import("com.aspose.words.ControlChar")
38
+ p run.getText().contains(control_char.PAGE_BREAK)
39
+ abort()
40
+ #if (run.getText().contains(control_char.PAGE_BREAK)) then
41
+ run_text = run.getText()
42
+ run_text = run_text.gsub(control_char.PAGE_BREAK, '')
43
+ run.setText(run_text)
44
+ #end
45
+ end
46
+ i = i + 1
47
+ end
48
+ end
49
+
50
+ def remove_section_breaks(doc)
51
+ # Loop through all sections starting from the section that precedes the last one
52
+ # and moving to the first section.
53
+ i = doc.getSections().getCount()
54
+ i = i - 2
55
+ while (i >= 0) do
56
+ # Copy the content of the current section to the beginning of the last section.
57
+ doc.getLastSection().prependContent(doc.getSections().get(i))
58
+ # Remove the copied section.
59
+ doc.getSections().get(i).remove()
60
+ i = i - 1
61
+ end
62
+ end
63
+
64
+ end
65
+ end
@@ -1,23 +1,23 @@
1
- module Asposewordsjavaforruby
2
- module RemoveField
3
- def initialize()
4
- # The path to the documents directory.
5
- data_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + '/data/'
6
-
7
- # Open the document.
8
- doc = Rjb::import('com.aspose.words.Document').new(data_dir + "Field.RemoveField.doc")
9
-
10
- #ExStart
11
- #ExFor:Field.Remove
12
- #ExId:DocumentBuilder_RemoveField
13
- #ExSummary:Removes a field from the document.
14
- field = doc.getRange().getFields().get(0)
15
- # Calling this method completely removes the field from the document.
16
- field.remove()
17
- #ExEnd
18
-
19
- # Save the document.
20
- doc.save(data_dir + "Field.RemoveField Out.doc")
21
- end
22
- end
23
- end
1
+ module Asposewordsjavaforruby
2
+ module RemoveField
3
+ def initialize()
4
+ # The path to the documents directory.
5
+ data_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + '/data/'
6
+
7
+ # Open the document.
8
+ doc = Rjb::import('com.aspose.words.Document').new(data_dir + "Field.RemoveField.doc")
9
+
10
+ #ExStart
11
+ #ExFor:Field.Remove
12
+ #ExId:DocumentBuilder_RemoveField
13
+ #ExSummary:Removes a field from the document.
14
+ field = doc.getRange().getFields().get(0)
15
+ # Calling this method completely removes the field from the document.
16
+ field.remove()
17
+ #ExEnd
18
+
19
+ # Save the document.
20
+ doc.save(data_dir + "Field.RemoveField Out.doc")
21
+ end
22
+ end
23
+ end