Module: Asposeslidesjava::Paragraphs

Defined in:
lib/asposeslidesjava/Text/paragraphs.rb

Instance Method Summary collapse

Instance Method Details

#initializeObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/asposeslidesjava/Text/paragraphs.rb', line 3

def initialize()
    # Managing Paragraphs Alignment
    paragraphs_alignment()

    # Managing Multiple Paragraphs having Multiple Portions
    multiple_paragraphs_having_muliple_portions()

    # Managing Paragraph Bullets
    paragraphs_bullets()

    # Managing Paragraph Indent
    paragraphs_indentation()

    # Managing Line Spacing of the paragraph
    line_spacing()
end

#line_spacingObject



233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
# File 'lib/asposeslidesjava/Text/paragraphs.rb', line 233

def line_spacing()
    data_dir = File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))) + '/data/Text/'
            
    # Create an instance of Presentation class
    pres = Rjb::import('com.aspose.slides.Presentation').new(data_dir + 'Welcome.pptx')

    # Get the first slide
    slide = pres.getSlides().get_Item(0)

    # Access the TextFrame
    tf = slide.getShapes().get_Item(0).getTextFrame()

    # Access the Paragraph
    para = tf.getParagraphs().get_Item(0)

    # Set properties of Paragraph
    para.getParagraphFormat().setSpaceWithin(80)
    para.getParagraphFormat().setSpaceBefore(40)
    para.getParagraphFormat().setSpaceAfter(40)

    # Write the presentation as a PPTX file 
    save_format = Rjb::import('com.aspose.slides.SaveFormat')
    pres.save(data_dir + "LineSpacing.pptx", save_format.Pptx)

    puts "Done with line spacing, please check the output file."
end

#multiple_paragraphs_having_muliple_portionsObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/asposeslidesjava/Text/paragraphs.rb', line 52

def multiple_paragraphs_having_muliple_portions()
    data_dir = File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))) + '/data/Text/'
            
    # Create an instance of Presentation class
    pres = Rjb::import('com.aspose.slides.Presentation').new

    # Get the first slide
    slide = pres.getSlides().get_Item(0)

    # Add an AutoShape of Rectangle type
    ashp = slide.getShapes().addAutoShape(Rjb::import('com.aspose.slides.ShapeType').Rectangle, 50, 150, 300, 150)

    # Access TextFrame of the AutoShape
    tf = ashp.getTextFrame()

    # Create Paragraphs and Portions with different text formats
    para0 = tf.getParagraphs().get_Item(0)
    port01 = Rjb::import('com.aspose.slides.Portion').new
    port02 = Rjb::import('com.aspose.slides.Portion').new
    para0.getPortions().add(port01)
    para0.getPortions().add(port02)

    para1 = Rjb::import('com.aspose.slides.Paragraph').new
    tf.getParagraphs().add(para1)
    port10 = Rjb::import('com.aspose.slides.Portion').new
    port11 = Rjb::import('com.aspose.slides.Portion').new
    port12 = Rjb::import('com.aspose.slides.Portion').new
    para1.getPortions().add(port10)
    para1.getPortions().add(port11)
    para1.getPortions().add(port12)

    para2 = Rjb::import('com.aspose.slides.Paragraph').new
    tf.getParagraphs().add(para2)
    port20 = Rjb::import('com.aspose.slides.Portion').new
    port21 = Rjb::import('com.aspose.slides.Portion').new
    port22 = Rjb::import('com.aspose.slides.Portion').new
    para2.getPortions().add(port20)
    para2.getPortions().add(port21)
    para2.getPortions().add(port22)

    i = 0
    for i in 0..2
       j = 0
       for j in 0..2
           tf.getParagraphs().get_Item(i).getPortions().get_Item(j).setText("Portion0#{j}")
           if j == 0
               tf.getParagraphs().get_Item(i).getPortions().get_Item(j).getPortionFormat().getFillFormat().setFillType(Rjb::import('com.aspose.slides.FillType').Solid)
               tf.getParagraphs().get_Item(i).getPortions().get_Item(j).getPortionFormat().getFillFormat().getSolidFillColor().setColor(Rjb::import('java.awt.Color').RED)
               tf.getParagraphs().get_Item(i).getPortions().get_Item(j).getPortionFormat().setFontBold(Rjb::import('com.aspose.slides.NullableBool').True)
               tf.getParagraphs().get_Item(i).getPortions().get_Item(j).getPortionFormat().setFontHeight(15)
           #elseif j == 1
           #    tf.getParagraphs().get_Item(i).getPortions().get_Item(j).getPortionFormat().getFillFormat().setFillType(Rjb::import('com.aspose.slides.FillType').Solid)
           #    tf.getParagraphs().get_Item(i).getPortions().get_Item(j).getPortionFormat().getFillFormat().getSolidFillColor().setColor(Rjb::import('java.awt.Color').BLUE)
           #    tf.getParagraphs().get_Item(i).getPortions().get_Item(j).getPortionFormat().setFontItalic(Rjb::import('com.aspose.slides.NullableBool').True)
           #    tf.getParagraphs().get_Item(i).getPortions().get_Item(j).getPortionFormat().setFontHeight(18)
           end
       end
    end   

    # Write the presentation as a PPTX file 
    save_format = Rjb::import('com.aspose.slides.SaveFormat')
    pres.save(data_dir + "multiParaPort.pptx", save_format.Pptx)

    puts "Done with multiple paragraphs, please check the output file."
end

#paragraphs_alignmentObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/asposeslidesjava/Text/paragraphs.rb', line 20

def paragraphs_alignment()
    data_dir = File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))) + '/data/Text/'
            
    # Create an instance of Presentation class
    pres = Rjb::import('com.aspose.slides.Presentation').new(data_dir + 'leftalign.pptx')

    # Get the first slide
    slide = pres.getSlides().get_Item(0)

    # Accessing the first and second placeholder in the slide and typecasting it as AutoShape
    tf1 = slide.getShapes().get_Item(0).getTextFrame()
    tf2 = slide.getShapes().get_Item(1).getTextFrame()

    # Change the text in both placeholders
    tf1.setText("Center Align by Aspose")
    tf2.setText("Center Align by Aspose")

    # Getting the first paragraph of the placeholders
    para1 = tf1.getParagraphs().get_Item(0)
    para2 = tf2.getParagraphs().get_Item(0)

    # Aligning the text paragraph to center
    para1.getParagraphFormat().setAlignment(Rjb::import('com.aspose.slides.TextAlignment').Center)
    para2.getParagraphFormat().setAlignment(Rjb::import('com.aspose.slides.TextAlignment').Center)

    # Write the presentation as a PPTX file 
    save_format = Rjb::import('com.aspose.slides.SaveFormat')
    pres.save(data_dir + "Centeralign.pptx", save_format.Pptx)

    puts "Done with text alignment, please check the output file."
end

#paragraphs_bulletsObject



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/asposeslidesjava/Text/paragraphs.rb', line 118

def paragraphs_bullets()
    data_dir = File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))) + '/data/Text/'
            
    # Create an instance of Presentation class
    pres = Rjb::import('com.aspose.slides.Presentation').new

    # Get the first slide
    slide = pres.getSlides().get_Item(0)

    # Adding and accessing Autoshape
    shp = slide.getShapes().addAutoShape(Rjb::import('com.aspose.slides.ShapeType').Rectangle, 200, 200, 400, 200)

    # Accessing the text frame of created autoshape
    txt_frm = shp.getTextFrame()

    # Removing the default exisiting paragraph
    txt_frm.getParagraphs().removeAt(0)

    # Creating a paragraph
    para = Rjb::import('com.aspose.slides.Paragraph').new

    # Setting paragraph bullet style and symbol
    para.getParagraphFormat().getBullet().setType(Rjb::import('com.aspose.slides.BulletType').Symbol)
    para.getParagraphFormat().getBullet().setChar(8226)

    # Setting paragraph text
    para.setText("Welcome to Aspose.Slides")

    # Setting bullet indent
    para.getParagraphFormat().setIndent(25)

    # Setting bullet color
    para.getParagraphFormat().getBullet().getColor().setColorType(Rjb::import('com.aspose.slides.ColorType').RGB)
    para.getParagraphFormat().getBullet().getColor().setColor(Rjb::import('java.awt.Color').BLACK)

    # set IsBulletHardColor to true to use own bullet color
    para.getParagraphFormat().getBullet().isBulletHardColor(Rjb::import('com.aspose.slides.NullableBool').True)

    # Setting Bullet Height
    para.getParagraphFormat().getBullet().setHeight(100)

    # Adding Paragraph to text frame
    txt_frm.getParagraphs().add(para)

    # Creating second paragraph
    para2 = Rjb::import('com.aspose.slides.Paragraph').new

    # Setting paragraph bullet type and style
    para2.getParagraphFormat().getBullet().setType(Rjb::import('com.aspose.slides.BulletType').Numbered)
    para2.getParagraphFormat().getBullet().setNumberedBulletStyle(Rjb::import('com.aspose.slides.NumberedBulletStyle').BulletCircleNumWDBlackPlain)

    # Adding paragraph text
    para2.setText("This is numbered bullet")

    # Setting bullet indent
    para2.getParagraphFormat().setIndent(25)

    para2.getParagraphFormat().getBullet().getColor().setColorType(Rjb::import('com.aspose.slides.ColorType').RGB)
    para2.getParagraphFormat().getBullet().getColor().setColor(Rjb::import('java.awt.Color').BLACK)

    # set IsBulletHardColor to true to use own bullet color
    para2.getParagraphFormat().getBullet().isBulletHardColor(Rjb::import('com.aspose.slides.NullableBool').True)

    # Setting Bullet Height
    para2.getParagraphFormat().getBullet().setHeight(100)

    # Adding Paragraph to text frame
    txt_frm.getParagraphs().add(para2)

    # Write the presentation as a PPTX file 
    save_format = Rjb::import('com.aspose.slides.SaveFormat')
    pres.save(data_dir + "Bullet.pptx", save_format.Pptx)

    puts "Done with Paragraphs bullet, please check the output file."
end

#paragraphs_indentationObject



194
195
196
197
198
199
200
201
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
227
228
229
230
231
# File 'lib/asposeslidesjava/Text/paragraphs.rb', line 194

def paragraphs_indentation()
    data_dir = File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))) + '/data/Text/'
            
    # Create an instance of Presentation class
    pres = Rjb::import('com.aspose.slides.Presentation').new

    # Get the first slide
    slide = pres.getSlides().get_Item(0)

    # Add a Rectangle Shape
    rect = slide.getShapes().addAutoShape(Rjb::import('com.aspose.slides.ShapeType').Rectangle,100, 100, 500, 150)

    # Add TextFrame to the Rectangle
    tf = rect.addTextFrame("This is first line \nThis is second line \nThis is third line")

    # Set the text to fit the shape
    tf.getTextFrameFormat().setAutofitType(Rjb::import('com.aspose.slides.TextAutofitType').Shape)

    # Hide the lines of the Rectangle
    rect.getLineFormat().getFillFormat().setFillType(Rjb::import('com.aspose.slides.FillType').Solid)

    # Get first Paragraph in the TextFrame and set its Indent
    para1 = tf.getParagraphs().get_Item(0)

    # Setting paragraph bullet style and symbol
    para1.getParagraphFormat().getBullet().setType(Rjb::import('com.aspose.slides.BulletType').Symbol)
    para1.getParagraphFormat().getBullet().setChar(8226)
    para1.getParagraphFormat().setAlignment(Rjb::import('com.aspose.slides.TextAlignment').Left)

    para1.getParagraphFormat().setDepth(2)
    para1.getParagraphFormat().setIndent(30)

    # Write the presentation as a PPTX file 
    save_format = Rjb::import('com.aspose.slides.SaveFormat')
    pres.save(data_dir + "InOutDent.pptx", save_format.Pptx)

    puts "Done with paragraphs identation, please check the output file."
end