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.
- data/Gempackage +3 -0
- data/LICENSE +21 -0
- data/README.md +2 -0
- data/Rakefile +2 -0
- data/asposewordsjavaforruby.gemspec +27 -0
- data/config/aspose.yml +5 -0
- data/data/Field.RemoveField.doc +0 -0
- data/data/LoadTxt.txt +15 -0
- data/data/Template.doc +0 -0
- data/data/Test.Styles.doc +0 -0
- data/data/TestAutofittables.doc +0 -0
- data/data/TestComments.doc +0 -0
- data/data/TestCompressImages.docx +0 -0
- data/data/TestFile.doc +0 -0
- data/data/TestWatermark.doc +0 -0
- data/data/bookmarks/Template.doc +0 -0
- data/data/bookmarks/TestDefect1352.doc +0 -0
- data/data/document/TestFile.doc +0 -0
- data/data/document/TestRemoveBreaks.doc +0 -0
- data/data/joiningandappending/TestFile.Destination.doc +0 -0
- data/data/joiningandappending/TestFile.DestinationList.doc +0 -0
- data/data/joiningandappending/TestFile.Source.doc +0 -0
- data/data/joiningandappending/TestFile.SourceList.doc +0 -0
- data/data/joiningandappending/TestFile.SourcePageSetup.doc +0 -0
- data/data/mailmerge/Template.doc +0 -0
- data/data/mailmerge/TestFile.doc +0 -0
- data/data/quickstart/Document.doc +0 -0
- data/data/quickstart/HelloWorld.docx +0 -0
- data/data/quickstart/MailMerge.doc +0 -0
- data/data/quickstart/ReplaceSimple.doc +0 -0
- data/data/quickstart/TestFile.Destination.doc +0 -0
- data/data/quickstart/TestFile.Source.doc +0 -0
- data/jars/aspose-words-15.4.0.jar +0 -0
- data/lib/asposewordsjavaforruby.rb +71 -0
- data/lib/asposewordsjavaforruby/addwatermark.rb +84 -0
- data/lib/asposewordsjavaforruby/appenddoc.rb +24 -0
- data/lib/asposewordsjavaforruby/appenddocument.rb +229 -0
- data/lib/asposewordsjavaforruby/applylicense.rb +16 -0
- data/lib/asposewordsjavaforruby/asposewordsjava.rb +24 -0
- data/lib/asposewordsjavaforruby/autofittables.rb +123 -0
- data/lib/asposewordsjavaforruby/bookmarks.rb +132 -0
- data/lib/asposewordsjavaforruby/checkformat.rb +70 -0
- data/lib/asposewordsjavaforruby/compressimages.rb +53 -0
- data/lib/asposewordsjavaforruby/doc2pdf.rb +15 -0
- data/lib/asposewordsjavaforruby/doctohtml.rb +26 -0
- data/lib/asposewordsjavaforruby/extractcontent.rb +395 -0
- data/lib/asposewordsjavaforruby/findandreplace.rb +29 -0
- data/lib/asposewordsjavaforruby/helloworld.rb +26 -0
- data/lib/asposewordsjavaforruby/imagetopdf.rb +71 -0
- data/lib/asposewordsjavaforruby/insertnestedfields.rb +39 -0
- data/lib/asposewordsjavaforruby/loadandsavetodisk.rb +20 -0
- data/lib/asposewordsjavaforruby/loadandsavetostream.rb +32 -0
- data/lib/asposewordsjavaforruby/loadtxt.rb +14 -0
- data/lib/asposewordsjavaforruby/mergefield.rb +45 -0
- data/lib/asposewordsjavaforruby/nodes.rb +29 -0
- data/lib/asposewordsjavaforruby/processcomments.rb +72 -0
- data/lib/asposewordsjavaforruby/removebreaks.rb +65 -0
- data/lib/asposewordsjavaforruby/removefield.rb +23 -0
- data/lib/asposewordsjavaforruby/saveasmultipagetiff.rb +26 -0
- data/lib/asposewordsjavaforruby/simplemailmerge.rb +23 -0
- data/lib/asposewordsjavaforruby/styles.rb +77 -0
- data/lib/asposewordsjavaforruby/updatefields.rb +62 -0
- data/lib/asposewordsjavaforruby/version.rb +3 -0
- metadata +65 -2
@@ -0,0 +1,71 @@
|
|
1
|
+
module Asposewordsjavaforruby
|
2
|
+
module ImageToPdf
|
3
|
+
def initialize()
|
4
|
+
# The path to the documents directory.
|
5
|
+
data_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + '/data/imagetopdf/'
|
6
|
+
|
7
|
+
convert_image_to_pdf(data_dir + "Test.jpg", data_dir + "TestJpg Out.pdf")
|
8
|
+
convert_image_to_pdf(data_dir + "Test.png", data_dir + "TestPng Out.pdf")
|
9
|
+
convert_image_to_pdf(data_dir + "Test.bmp", data_dir + "TestBmp Out.pdf")
|
10
|
+
convert_image_to_pdf(data_dir + "Test.gif", data_dir + "TestGif Out.pdf")
|
11
|
+
end
|
12
|
+
|
13
|
+
def convert_image_to_pdf(input_filename, output_filename)
|
14
|
+
# Create Aspose.Words.Document and DocumentBuilder.
|
15
|
+
# The builder makes it simple to add content to the document.
|
16
|
+
doc = Rjb::import('com.aspose.words.Document').new
|
17
|
+
builder = Rjb::import('com.aspose.words.DocumentBuilder').new(doc)
|
18
|
+
|
19
|
+
# Load images from the disk using the approriate reader.
|
20
|
+
# The file formats that can be loaded depends on the image readers available on the machine.
|
21
|
+
imageio = Rjb::import('javax.imageio.ImageIO')
|
22
|
+
ImageInputStream = Rjb::import('javax.imageio.stream.ImageInputStream')
|
23
|
+
reader = Rjb::import('javax.imageio.ImageReader')
|
24
|
+
|
25
|
+
iis = imageio.createImageInputStream(Rjb::import('java.io.File').new(input_filename))
|
26
|
+
reader = imageio.getImageReaders(iis).next()
|
27
|
+
reader.setInput(iis, false)
|
28
|
+
|
29
|
+
# Get the number of frames in the image.
|
30
|
+
framesCount = reader.getNumImages(true)
|
31
|
+
|
32
|
+
# Loop through all frames.
|
33
|
+
for (int frameIdx = 0; frameIdx < framesCount; frameIdx++)
|
34
|
+
{
|
35
|
+
# Insert a section break before each new page, in case of a multi-frame image.
|
36
|
+
if (frameIdx != 0) then
|
37
|
+
break_type = Rjb::import('com.aspose.words.BreakType')
|
38
|
+
builder.insertBreak(break_type.SECTION_BREAK_NEW_PAGE)
|
39
|
+
end
|
40
|
+
|
41
|
+
# Select active frame.
|
42
|
+
image = Rjb::import('java.awt.image.BufferedImage')
|
43
|
+
image = reader.read(frameIdx)
|
44
|
+
|
45
|
+
# We want the size of the page to be the same as the size of the image.
|
46
|
+
# Convert pixels to points to size the page to the actual image size.
|
47
|
+
ps = Rjb::import('com.aspose.words.PageSetup')
|
48
|
+
ps = builder.getPageSetup()
|
49
|
+
|
50
|
+
convert_util = Rjb::import('com.aspose.words.ConvertUtil')
|
51
|
+
ps.setPageWidth(convert_util.pixelToPoint(image.getWidth()))
|
52
|
+
ps.setPageHeight(convert_util.pixelToPoint(image.getHeight()))
|
53
|
+
|
54
|
+
# Insert the image into the document and position it at the top left corner of the page.
|
55
|
+
builder.insertImage(
|
56
|
+
image,
|
57
|
+
RelativeHorizontalPosition.PAGE,
|
58
|
+
0,
|
59
|
+
RelativeVerticalPosition.PAGE,
|
60
|
+
0,
|
61
|
+
ps.getPageWidth(),
|
62
|
+
ps.getPageHeight(),
|
63
|
+
WrapType.NONE)
|
64
|
+
|
65
|
+
# Save the document.
|
66
|
+
doc.save(output_filename)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Asposewordsjavaforruby
|
2
|
+
module InsertNestedFields
|
3
|
+
def initialize()
|
4
|
+
# The path to the documents directory.
|
5
|
+
data_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + '/data/'
|
6
|
+
|
7
|
+
# Create new document.
|
8
|
+
doc = Rjb::import('com.aspose.words.Document').new
|
9
|
+
builder = Rjb::import("com.aspose.words.DocumentBuilder").new(doc)
|
10
|
+
|
11
|
+
# Insert few page breaks (just for testing)
|
12
|
+
breakType = Rjb::import("com.aspose.words.BreakType")
|
13
|
+
|
14
|
+
for i in 0..4
|
15
|
+
builder.insertBreak(breakType.PAGE_BREAK)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Move DocumentBuilder cursor into the primary footer.
|
19
|
+
headerFooterType = Rjb::import("com.aspose.words.HeaderFooterType")
|
20
|
+
builder.moveToHeaderFooter(headerFooterType.FOOTER_PRIMARY)
|
21
|
+
|
22
|
+
# We want to insert a field like this:
|
23
|
+
# { IF {PAGE} <> {NUMPAGES} "See Next Page" "Last Page" }
|
24
|
+
field = builder.insertField("IF ")
|
25
|
+
builder.moveTo(field.getSeparator())
|
26
|
+
builder.insertField("PAGE")
|
27
|
+
builder.write(" <> ")
|
28
|
+
builder.insertField("NUMPAGES")
|
29
|
+
builder.write(" \"See Next Page\" \"Last Page\" ")
|
30
|
+
|
31
|
+
# Finally update the outer field to recalcaluate the final value. Doing this will automatically update
|
32
|
+
# the inner fields at the same time.
|
33
|
+
field.update()
|
34
|
+
|
35
|
+
# Save the document.
|
36
|
+
doc.save(data_dir + "InsertNestedFields Out.doc")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Asposewordsjavaforruby
|
2
|
+
module LoadAndSaveToDisk
|
3
|
+
def initialize()
|
4
|
+
# Load and save the document.
|
5
|
+
save_to_disk()
|
6
|
+
end
|
7
|
+
|
8
|
+
def save_to_disk()
|
9
|
+
# The path to the documents directory.
|
10
|
+
data_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + '/data/quickstart/'
|
11
|
+
|
12
|
+
# Open the document.
|
13
|
+
doc = Rjb::import('com.aspose.words.Document').new(data_dir + "Document.doc")
|
14
|
+
|
15
|
+
# Save the document as DOCX document.
|
16
|
+
doc.save(data_dir + "Document Out.docx")
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Asposewordsjavaforruby
|
2
|
+
module LoadAndSaveToStream
|
3
|
+
def initialize()
|
4
|
+
# Load and save to stream.
|
5
|
+
save_to_stream()
|
6
|
+
end
|
7
|
+
|
8
|
+
def save_to_stream()
|
9
|
+
# The path to the documents directory.
|
10
|
+
data_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + '/data/quickstart/'
|
11
|
+
|
12
|
+
# Open the stream. Read only access is enough for Aspose.Words to load a document.
|
13
|
+
stream = Rjb::import('java.io.FileInputStream').new(data_dir + "Document.doc")
|
14
|
+
|
15
|
+
# Load the entire document into memory.
|
16
|
+
doc = Rjb::import('com.aspose.words.Document').new(stream)
|
17
|
+
|
18
|
+
# You can close the stream now, it is no longer needed because the document is in memory.
|
19
|
+
stream.close()
|
20
|
+
# ... do something with the document
|
21
|
+
# Convert the document to a different format and save to stream.
|
22
|
+
dst_stream = Rjb::import("java.io.ByteArrayOutputStream").new()
|
23
|
+
save_format = Rjb::import("com.aspose.words.SaveFormat")
|
24
|
+
doc.save(dst_stream, save_format.RTF)
|
25
|
+
|
26
|
+
output = Rjb::import("java.io.FileOutputStream").new(data_dir + "Document Out.rtf")
|
27
|
+
output.write(dst_stream.toByteArray())
|
28
|
+
output.close()
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Asposewordsjavaforruby
|
2
|
+
module LoadTxt
|
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 + "LoadTxt.txt")
|
9
|
+
|
10
|
+
# Save as any Aspose.Words supported format, such as DOCX.
|
11
|
+
doc.save(data_dir + "LoadTxt Out.doc")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +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
|
@@ -0,0 +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
|
@@ -0,0 +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
|
@@ -0,0 +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
|
@@ -0,0 +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
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Asposewordsjavaforruby
|
2
|
+
module SaveAsMultipageTiff
|
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 + "TestFile.doc")
|
9
|
+
|
10
|
+
# Save the document as multipage TIFF.
|
11
|
+
doc.save(data_dir + "TestFile Out.doc")
|
12
|
+
|
13
|
+
save_format = Rjb::import('com.aspose.words.SaveFormat')
|
14
|
+
|
15
|
+
options = Rjb::import('com.aspose.words.ImageSaveOptions').new(save_format.TIFF)
|
16
|
+
options.setPageIndex(0)
|
17
|
+
options.setPageCount(2)
|
18
|
+
|
19
|
+
tiff_compression = Rjb::import('com.aspose.words.TiffCompression')
|
20
|
+
options.setTiffCompression(tiff_compression.CCITT_4)
|
21
|
+
options.setResolution(160)
|
22
|
+
|
23
|
+
doc.save(data_dir + "TestFileWithOptions Out.tiff", options)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|