Skip to content

Commit c6afa39

Browse files
Merge pull request #17 from shoaibkhan-aspose/master
Aspose.Slides Java for pptx4j - Comparison Examples - v1.2
2 parents 7ffb5a5 + c010519 commit c6afa39

File tree

123 files changed

+3471
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

123 files changed

+3471
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package asposefeatures.security.applypasswordprotection.java;
2+
3+
import com.aspose.slides.Presentation;
4+
5+
public class AsposeApplyPasswordProtection
6+
{
7+
public static void main(String[] args)
8+
{
9+
String dataPath = "src/asposefeatures/security/applypasswordprotection/data/";
10+
11+
//Instantiate a Presentation object that represents a PPT file
12+
Presentation pres = new Presentation();
13+
14+
//....do some work here.....
15+
16+
//Setting Password
17+
pres.getProtectionManager().encrypt("pass");
18+
19+
//Save your presentation to a file
20+
pres.save(dataPath + "AsposeProtection_Out.pptx", com.aspose.slides.SaveFormat.Pptx);
21+
22+
//Printing the status
23+
System.out.println("Protection Applied successfully!");
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package asposefeatures.security.applyprotectionwithproperties.java;
2+
3+
import com.aspose.slides.Presentation;
4+
5+
public class AsposeApplyProtectionwithPropertiesAccess
6+
{
7+
public static void main(String[] args)
8+
{
9+
String dataPath = "src/asposefeatures/security/applyprotectionwithproperties/data/";
10+
11+
//Instantiate a Presentation object that represents a PPT file
12+
Presentation pres = new Presentation();
13+
14+
//....do some work here.....
15+
16+
//Setting access to document properties in password protected mode
17+
pres.getProtectionManager().setEncryptDocumentProperties ( false);
18+
19+
//Setting Password
20+
pres.getProtectionManager().encrypt("pass");
21+
22+
//Save your presentation to a file
23+
pres.save(dataPath + "AsposeProtection-PropAccess_Out.pptx", com.aspose.slides.SaveFormat.Pptx);
24+
25+
//Printing the status
26+
System.out.println("Protection Applied successfully!");
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package asposefeatures.workingwithcharts.charttrendlines.java;
2+
3+
import java.awt.Color;
4+
5+
import com.aspose.slides.ChartType;
6+
import com.aspose.slides.FillType;
7+
import com.aspose.slides.IChart;
8+
import com.aspose.slides.ITrendline;
9+
import com.aspose.slides.Presentation;
10+
import com.aspose.slides.SaveFormat;
11+
import com.aspose.slides.TrendlineType;
12+
13+
public class AddChartTrendLines
14+
{
15+
public static void main(String[] args)
16+
{
17+
String dataPath = "src/asposefeatures/workingwithcharts/charttrendlines/data/";
18+
19+
//Creating empty presentation//Creating empty presentation
20+
Presentation pres = new Presentation();
21+
22+
//Creating a clustered column chart
23+
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.ClusteredColumn, 20, 20, 500, 400);
24+
25+
//Adding potential trend line for chart series 1
26+
ITrendline tredLinep = chart.getChartData().getSeries().get_Item(0).getTrendLines().add(TrendlineType.Exponential);
27+
tredLinep.setDisplayEquation(false);
28+
tredLinep.setDisplayRSquaredValue(false);
29+
30+
//Adding Linear trend line for chart series 1
31+
ITrendline tredLineLin = chart.getChartData().getSeries().get_Item(0).getTrendLines().add(TrendlineType.Linear);
32+
tredLineLin.setTrendlineType(TrendlineType.Linear);
33+
tredLineLin.getFormat().getLine().getFillFormat().setFillType(FillType.Solid);
34+
tredLineLin.getFormat().getLine().getFillFormat().getSolidFillColor().setColor(Color.RED);
35+
36+
37+
//Adding Logarithmic trend line for chart series 2
38+
ITrendline tredLineLog = chart.getChartData().getSeries().get_Item(1).getTrendLines().add(TrendlineType.Logarithmic);
39+
tredLineLog.setTrendlineType(TrendlineType.Logarithmic);
40+
tredLineLog.addTextFrameForOverriding("New log trend line");
41+
42+
//Adding MovingAverage trend line for chart series 2
43+
ITrendline tredLineMovAvg = chart.getChartData().getSeries().get_Item(1).getTrendLines().add(TrendlineType.MovingAverage);
44+
tredLineMovAvg.setTrendlineType(TrendlineType.MovingAverage);
45+
tredLineMovAvg.setPeriod((byte)3);
46+
tredLineMovAvg.setTrendlineName("New TrendLine Name");
47+
48+
//Adding Polynomial trend line for chart series 3
49+
ITrendline tredLinePol = chart.getChartData().getSeries().get_Item(2).getTrendLines().add(TrendlineType.Polynomial);
50+
tredLinePol.setTrendlineType(TrendlineType.Polynomial);
51+
tredLinePol.setForward(1);
52+
tredLinePol.setOrder ((byte)3);
53+
54+
//Adding Power trend line for chart series 3
55+
ITrendline tredLinePower = chart.getChartData().getSeries().get_Item(1).getTrendLines().add(TrendlineType.Power);
56+
tredLinePower.setTrendlineType(TrendlineType.Power);
57+
tredLinePower.setBackward(1);
58+
59+
//Saving presentation
60+
pres.save(dataPath + "AsposeChartTrendLines.pptx", SaveFormat.Pptx);
61+
System.out.println("AsposeChartTrendLines Saved.");
62+
}
63+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package asposefeatures.workingwithcharts.numberformatforchartdatacell.java;
2+
3+
import com.aspose.slides.ChartType;
4+
import com.aspose.slides.IChart;
5+
import com.aspose.slides.IChartDataPoint;
6+
import com.aspose.slides.IChartSeries;
7+
import com.aspose.slides.IChartSeriesCollection;
8+
import com.aspose.slides.ISlide;
9+
import com.aspose.slides.Presentation;
10+
import com.aspose.slides.SaveFormat;
11+
12+
public class NumberFormatForChartDataCell
13+
{
14+
public static void main(String[] args)
15+
{
16+
String dataPath = "src/asposefeatures/workingwithcharts/numberformatforchartdatacell/data/";
17+
18+
// Instantiate the presentation//Instantiate the presentation
19+
Presentation pres = new Presentation();
20+
21+
// Access the first presentation slide
22+
ISlide slide = pres.getSlides().get_Item(0);
23+
24+
// Adding a defautlt clustered column chart
25+
IChart chart = slide.getShapes().addChart(ChartType.ClusteredColumn, 50, 50, 500, 400);
26+
27+
// Accessing the chart series collection
28+
IChartSeriesCollection series = chart.getChartData().getSeries();
29+
30+
// Setting the preset number format
31+
// Traverse through every chart series
32+
for (IChartSeries ser : series)
33+
{
34+
// Traverse through every data cell in series
35+
for (IChartDataPoint cell : ser.getDataPoints())
36+
{
37+
// Setting the number format
38+
cell.getValue().getAsCell().setPresetNumberFormat((byte) 10); // 0.00%
39+
}
40+
}
41+
42+
// Saving presentation
43+
pres.save(dataPath + "AsposePresetNumberFormat.pptx", SaveFormat.Pptx);
44+
System.out.println("AsposePresetNumberFormat Saved.");
45+
}
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
package asposefeatures.workingwithcharts.piechartsectorcolor.java;
2+
3+
import java.awt.Color;
4+
5+
import com.aspose.slides.ChartType;
6+
import com.aspose.slides.FillType;
7+
import com.aspose.slides.IChart;
8+
import com.aspose.slides.IChartDataPoint;
9+
import com.aspose.slides.IChartDataWorkbook;
10+
import com.aspose.slides.IChartSeries;
11+
import com.aspose.slides.IDataLabel;
12+
import com.aspose.slides.ISlide;
13+
import com.aspose.slides.LineDashStyle;
14+
import com.aspose.slides.LineStyle;
15+
import com.aspose.slides.NullableBool;
16+
import com.aspose.slides.Presentation;
17+
import com.aspose.slides.PresetColor;
18+
import com.aspose.slides.SaveFormat;
19+
20+
public class AsposeSettingPieChartSectorColors
21+
{
22+
public static void main(String[] args)
23+
{
24+
String dataPath = "src/asposefeatures/workingwithcharts/piechartsectorcolor/data/";
25+
26+
// Instantiate Presentation class that represents PPTX file
27+
Presentation pres = new Presentation();
28+
29+
// Access first slide
30+
ISlide sld = pres.getSlides().get_Item(0);
31+
32+
// Add chart with default data
33+
IChart chart = sld.getShapes().addChart(ChartType.Pie, 100, 100, 400, 400);
34+
35+
// Setting chart Title
36+
chart.getChartTitle().addTextFrameForOverriding("Sample Title");
37+
chart.getChartTitle().getTextFrameForOverriding().getTextFrameFormat()
38+
.setCenterText(NullableBool.True);
39+
chart.getChartTitle().setHeight(20);
40+
chart.setTitle(true);
41+
42+
// Set first series to Show Values
43+
chart.getChartData().getSeries().get_Item(0).getLabels().getDefaultDataLabelFormat()
44+
.setShowValue(true);
45+
46+
// Setting the index of chart data sheet
47+
int defaultWorksheetIndex = 0;
48+
49+
// Getting the chart data worksheet
50+
IChartDataWorkbook fact = chart.getChartData().getChartDataWorkbook();
51+
52+
// Delete default generated series and categories
53+
54+
chart.getChartData().getSeries().clear();
55+
chart.getChartData().getCategories().clear();
56+
57+
// Adding new categories
58+
chart.getChartData().getCategories().add(fact.getCell(0, 1, 0, "First Qtr"));
59+
chart.getChartData().getCategories().add(fact.getCell(0, 2, 0, "2nd Qtr"));
60+
chart.getChartData().getCategories().add(fact.getCell(0, 3, 0, "3rd Qtr"));
61+
62+
// Adding new series
63+
IChartSeries series = chart.getChartData().getSeries()
64+
.add(fact.getCell(0, 0, 1, "Series 1"), chart.getType());
65+
66+
// Now populating series data
67+
series.getDataPoints().addDataPointForPieSeries(
68+
fact.getCell(defaultWorksheetIndex, 1, 1, 20));
69+
series.getDataPoints().addDataPointForPieSeries(
70+
fact.getCell(defaultWorksheetIndex, 2, 1, 50));
71+
series.getDataPoints().addDataPointForPieSeries(
72+
fact.getCell(defaultWorksheetIndex, 3, 1, 30));
73+
74+
// Not working in new version
75+
// Adding new points and setting sector color
76+
// series.IsColorVaried = true;
77+
chart.getChartData().getSeriesGroups().get_Item(0).setColorVaried(true);
78+
79+
IChartDataPoint point = series.getDataPoints().get_Item(0);
80+
point.getFormat().getFill().setFillType(FillType.Solid);
81+
point.getFormat().getFill().getSolidFillColor().setColor(Color.CYAN);
82+
// Setting Sector border
83+
point.getFormat().getLine().getFillFormat().setFillType(FillType.Solid);
84+
point.getFormat().getLine().getFillFormat().getSolidFillColor().setColor(Color.GRAY);
85+
point.getFormat().getLine().setWidth(3.0);
86+
point.getFormat().getLine().setStyle(LineStyle.ThinThick);
87+
point.getFormat().getLine().setDashStyle(LineDashStyle.DashDot);
88+
89+
IChartDataPoint point1 = series.getDataPoints().get_Item(1);
90+
point1.getFormat().getFill().setFillType(FillType.Solid);
91+
point1.getFormat().getFill().getSolidFillColor().setColor(new Color(PresetColor.Brown));
92+
93+
// Setting Sector border
94+
point1.getFormat().getLine().getFillFormat().setFillType(FillType.Solid);
95+
point1.getFormat().getLine().getFillFormat().getSolidFillColor().setColor(Color.BLUE);
96+
point1.getFormat().getLine().setWidth(3.0);
97+
point1.getFormat().getLine().setStyle(LineStyle.Single);
98+
point1.getFormat().getLine().setDashStyle(LineDashStyle.LargeDashDot);
99+
100+
IChartDataPoint point2 = series.getDataPoints().get_Item(2);
101+
point2.getFormat().getFill().setFillType(FillType.Solid);
102+
point2.getFormat().getFill().getSolidFillColor().setColor(new Color(PresetColor.Coral));
103+
104+
// Setting Sector border
105+
point2.getFormat().getLine().getFillFormat().setFillType(FillType.Solid);
106+
point2.getFormat().getLine().getFillFormat().getSolidFillColor().setColor(Color.RED);
107+
point2.getFormat().getLine().setWidth(2.0);
108+
point2.getFormat().getLine().setStyle(LineStyle.ThinThin);
109+
point2.getFormat().getLine().setDashStyle(LineDashStyle.LargeDashDotDot);
110+
111+
// Create custom labels for each of categories for new series
112+
113+
IDataLabel lbl1 = series.getDataPoints().get_Item(0).getLabel();
114+
// lbl.ShowCategoryName = true;
115+
lbl1.getDataLabelFormat().setShowValue(true);
116+
117+
IDataLabel lbl2 = series.getDataPoints().get_Item(1).getLabel();
118+
lbl2.getDataLabelFormat().setShowValue(true);
119+
lbl2.getDataLabelFormat().setShowLegendKey(true);
120+
lbl2.getDataLabelFormat().setShowPercentage(true);
121+
122+
IDataLabel lbl3 = series.getDataPoints().get_Item(2).getLabel();
123+
lbl3.getDataLabelFormat().setShowSeriesName(true);
124+
lbl3.getDataLabelFormat().setShowPercentage(true);
125+
126+
// Showing Leader Lines for Chart
127+
series.getLabels().getDefaultDataLabelFormat().setShowLeaderLines(true);
128+
129+
// Setting Rotation Angle for Pie Chart Sectors
130+
chart.getChartData().getSeriesGroups().get_Item(0).setFirstSliceAngle(180);
131+
132+
// Save presentation with chart
133+
pres.save(dataPath + "AsposePieChart.pptx", SaveFormat.Pptx);
134+
135+
System.out.println("Done");
136+
}
137+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
* Copyright (c) Aspose 2002-2016. All Rights Reserved.
3+
*
4+
* LICENSE: This program is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU General Public License
6+
* as published by the Free Software Foundation; either version 3
7+
* of the License, or (at your option) any later version.
8+
* This program is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
* GNU General Public License for more details.
12+
* You should have received a copy of the GNU General Public License
13+
* along with this program. If not, see <http://opensource.org/licenses/gpl-3.0.html>;.
14+
*
15+
* @author Shoaib Khan
16+
*
17+
* @link https://asposejavadocx4j.codeplex.com/
18+
* @link https://sourceforge.net/projects/asposejavafordocx4j/
19+
* @link https://github.com/asposemarketplace/Aspose_Java_for_Docx4j
20+
* @link https://bitbucket.org/asposemarketplace/aspose-java-for-docx4j/
21+
*/
22+
23+
package asposefeatures.workingwithmediacontrols.addaudioframe.java;
24+
25+
import java.io.File;
26+
import java.io.FileInputStream;
27+
28+
import com.aspose.slides.AudioPlayModePreset;
29+
import com.aspose.slides.AudioVolumeMode;
30+
import com.aspose.slides.IAudioFrame;
31+
import com.aspose.slides.ISlide;
32+
import com.aspose.slides.Presentation;
33+
import com.aspose.slides.SaveFormat;
34+
35+
public class AsposeAudioFrame
36+
{
37+
public static void main(String[] args) throws Exception
38+
{
39+
String dataPath = "src/asposefeatures/workingwithmediacontrols/addaudioframe/data/";
40+
41+
//Instantiate Prsentation class that represents the PPTX
42+
Presentation pres = new Presentation();
43+
44+
//Get the first slide
45+
ISlide sld = pres.getSlides().get_Item(0);
46+
47+
//Load the wav sound file to stram
48+
FileInputStream fstr = new FileInputStream(new File(dataPath + "logon.wav"));
49+
50+
//Add Audio Frame
51+
IAudioFrame af = sld.getShapes().addAudioFrameEmbedded(50, 150, 100, 100, fstr);
52+
53+
//Set Play Mode and Volume of the Audio
54+
af.setPlayMode(AudioPlayModePreset.Auto);
55+
af.setVolume(AudioVolumeMode.Loud);
56+
57+
//Write the PPTX file to disk
58+
pres.save(dataPath + "AsposeAudio_Out.pptx", SaveFormat.Pptx);
59+
60+
System.out.println("Audio Control Added.");
61+
}
62+
}

0 commit comments

Comments
 (0)