Skip to content

Aspose.Slides Java for pptx4j - v1.2 - Comparison Examples #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package asposefeatures.security.applypasswordprotection.java;

import com.aspose.slides.Presentation;

public class AsposeApplyPasswordProtection
{
public static void main(String[] args)
{
String dataPath = "src/asposefeatures/security/applypasswordprotection/data/";

//Instantiate a Presentation object that represents a PPT file
Presentation pres = new Presentation();

//....do some work here.....

//Setting Password
pres.getProtectionManager().encrypt("pass");

//Save your presentation to a file
pres.save(dataPath + "AsposeProtection_Out.pptx", com.aspose.slides.SaveFormat.Pptx);

//Printing the status
System.out.println("Protection Applied successfully!");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package asposefeatures.security.applyprotectionwithproperties.java;

import com.aspose.slides.Presentation;

public class AsposeApplyProtectionwithPropertiesAccess
{
public static void main(String[] args)
{
String dataPath = "src/asposefeatures/security/applyprotectionwithproperties/data/";

//Instantiate a Presentation object that represents a PPT file
Presentation pres = new Presentation();

//....do some work here.....

//Setting access to document properties in password protected mode
pres.getProtectionManager().setEncryptDocumentProperties ( false);

//Setting Password
pres.getProtectionManager().encrypt("pass");

//Save your presentation to a file
pres.save(dataPath + "AsposeProtection-PropAccess_Out.pptx", com.aspose.slides.SaveFormat.Pptx);

//Printing the status
System.out.println("Protection Applied successfully!");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package asposefeatures.workingwithcharts.charttrendlines.java;

import java.awt.Color;

import com.aspose.slides.ChartType;
import com.aspose.slides.FillType;
import com.aspose.slides.IChart;
import com.aspose.slides.ITrendline;
import com.aspose.slides.Presentation;
import com.aspose.slides.SaveFormat;
import com.aspose.slides.TrendlineType;

public class AddChartTrendLines
{
public static void main(String[] args)
{
String dataPath = "src/asposefeatures/workingwithcharts/charttrendlines/data/";

//Creating empty presentation//Creating empty presentation
Presentation pres = new Presentation();

//Creating a clustered column chart
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.ClusteredColumn, 20, 20, 500, 400);

//Adding potential trend line for chart series 1
ITrendline tredLinep = chart.getChartData().getSeries().get_Item(0).getTrendLines().add(TrendlineType.Exponential);
tredLinep.setDisplayEquation(false);
tredLinep.setDisplayRSquaredValue(false);

//Adding Linear trend line for chart series 1
ITrendline tredLineLin = chart.getChartData().getSeries().get_Item(0).getTrendLines().add(TrendlineType.Linear);
tredLineLin.setTrendlineType(TrendlineType.Linear);
tredLineLin.getFormat().getLine().getFillFormat().setFillType(FillType.Solid);
tredLineLin.getFormat().getLine().getFillFormat().getSolidFillColor().setColor(Color.RED);


//Adding Logarithmic trend line for chart series 2
ITrendline tredLineLog = chart.getChartData().getSeries().get_Item(1).getTrendLines().add(TrendlineType.Logarithmic);
tredLineLog.setTrendlineType(TrendlineType.Logarithmic);
tredLineLog.addTextFrameForOverriding("New log trend line");

//Adding MovingAverage trend line for chart series 2
ITrendline tredLineMovAvg = chart.getChartData().getSeries().get_Item(1).getTrendLines().add(TrendlineType.MovingAverage);
tredLineMovAvg.setTrendlineType(TrendlineType.MovingAverage);
tredLineMovAvg.setPeriod((byte)3);
tredLineMovAvg.setTrendlineName("New TrendLine Name");

//Adding Polynomial trend line for chart series 3
ITrendline tredLinePol = chart.getChartData().getSeries().get_Item(2).getTrendLines().add(TrendlineType.Polynomial);
tredLinePol.setTrendlineType(TrendlineType.Polynomial);
tredLinePol.setForward(1);
tredLinePol.setOrder ((byte)3);

//Adding Power trend line for chart series 3
ITrendline tredLinePower = chart.getChartData().getSeries().get_Item(1).getTrendLines().add(TrendlineType.Power);
tredLinePower.setTrendlineType(TrendlineType.Power);
tredLinePower.setBackward(1);

//Saving presentation
pres.save(dataPath + "AsposeChartTrendLines.pptx", SaveFormat.Pptx);
System.out.println("AsposeChartTrendLines Saved.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package asposefeatures.workingwithcharts.numberformatforchartdatacell.java;

import com.aspose.slides.ChartType;
import com.aspose.slides.IChart;
import com.aspose.slides.IChartDataPoint;
import com.aspose.slides.IChartSeries;
import com.aspose.slides.IChartSeriesCollection;
import com.aspose.slides.ISlide;
import com.aspose.slides.Presentation;
import com.aspose.slides.SaveFormat;

public class NumberFormatForChartDataCell
{
public static void main(String[] args)
{
String dataPath = "src/asposefeatures/workingwithcharts/numberformatforchartdatacell/data/";

// Instantiate the presentation//Instantiate the presentation
Presentation pres = new Presentation();

// Access the first presentation slide
ISlide slide = pres.getSlides().get_Item(0);

// Adding a defautlt clustered column chart
IChart chart = slide.getShapes().addChart(ChartType.ClusteredColumn, 50, 50, 500, 400);

// Accessing the chart series collection
IChartSeriesCollection series = chart.getChartData().getSeries();

// Setting the preset number format
// Traverse through every chart series
for (IChartSeries ser : series)
{
// Traverse through every data cell in series
for (IChartDataPoint cell : ser.getDataPoints())
{
// Setting the number format
cell.getValue().getAsCell().setPresetNumberFormat((byte) 10); // 0.00%
}
}

// Saving presentation
pres.save(dataPath + "AsposePresetNumberFormat.pptx", SaveFormat.Pptx);
System.out.println("AsposePresetNumberFormat Saved.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
package asposefeatures.workingwithcharts.piechartsectorcolor.java;

import java.awt.Color;

import com.aspose.slides.ChartType;
import com.aspose.slides.FillType;
import com.aspose.slides.IChart;
import com.aspose.slides.IChartDataPoint;
import com.aspose.slides.IChartDataWorkbook;
import com.aspose.slides.IChartSeries;
import com.aspose.slides.IDataLabel;
import com.aspose.slides.ISlide;
import com.aspose.slides.LineDashStyle;
import com.aspose.slides.LineStyle;
import com.aspose.slides.NullableBool;
import com.aspose.slides.Presentation;
import com.aspose.slides.PresetColor;
import com.aspose.slides.SaveFormat;

public class AsposeSettingPieChartSectorColors
{
public static void main(String[] args)
{
String dataPath = "src/asposefeatures/workingwithcharts/piechartsectorcolor/data/";

// Instantiate Presentation class that represents PPTX file
Presentation pres = new Presentation();

// Access first slide
ISlide sld = pres.getSlides().get_Item(0);

// Add chart with default data
IChart chart = sld.getShapes().addChart(ChartType.Pie, 100, 100, 400, 400);

// Setting chart Title
chart.getChartTitle().addTextFrameForOverriding("Sample Title");
chart.getChartTitle().getTextFrameForOverriding().getTextFrameFormat()
.setCenterText(NullableBool.True);
chart.getChartTitle().setHeight(20);
chart.setTitle(true);

// Set first series to Show Values
chart.getChartData().getSeries().get_Item(0).getLabels().getDefaultDataLabelFormat()
.setShowValue(true);

// Setting the index of chart data sheet
int defaultWorksheetIndex = 0;

// Getting the chart data worksheet
IChartDataWorkbook fact = chart.getChartData().getChartDataWorkbook();

// Delete default generated series and categories

chart.getChartData().getSeries().clear();
chart.getChartData().getCategories().clear();

// Adding new categories
chart.getChartData().getCategories().add(fact.getCell(0, 1, 0, "First Qtr"));
chart.getChartData().getCategories().add(fact.getCell(0, 2, 0, "2nd Qtr"));
chart.getChartData().getCategories().add(fact.getCell(0, 3, 0, "3rd Qtr"));

// Adding new series
IChartSeries series = chart.getChartData().getSeries()
.add(fact.getCell(0, 0, 1, "Series 1"), chart.getType());

// Now populating series data
series.getDataPoints().addDataPointForPieSeries(
fact.getCell(defaultWorksheetIndex, 1, 1, 20));
series.getDataPoints().addDataPointForPieSeries(
fact.getCell(defaultWorksheetIndex, 2, 1, 50));
series.getDataPoints().addDataPointForPieSeries(
fact.getCell(defaultWorksheetIndex, 3, 1, 30));

// Not working in new version
// Adding new points and setting sector color
// series.IsColorVaried = true;
chart.getChartData().getSeriesGroups().get_Item(0).setColorVaried(true);

IChartDataPoint point = series.getDataPoints().get_Item(0);
point.getFormat().getFill().setFillType(FillType.Solid);
point.getFormat().getFill().getSolidFillColor().setColor(Color.CYAN);
// Setting Sector border
point.getFormat().getLine().getFillFormat().setFillType(FillType.Solid);
point.getFormat().getLine().getFillFormat().getSolidFillColor().setColor(Color.GRAY);
point.getFormat().getLine().setWidth(3.0);
point.getFormat().getLine().setStyle(LineStyle.ThinThick);
point.getFormat().getLine().setDashStyle(LineDashStyle.DashDot);

IChartDataPoint point1 = series.getDataPoints().get_Item(1);
point1.getFormat().getFill().setFillType(FillType.Solid);
point1.getFormat().getFill().getSolidFillColor().setColor(new Color(PresetColor.Brown));

// Setting Sector border
point1.getFormat().getLine().getFillFormat().setFillType(FillType.Solid);
point1.getFormat().getLine().getFillFormat().getSolidFillColor().setColor(Color.BLUE);
point1.getFormat().getLine().setWidth(3.0);
point1.getFormat().getLine().setStyle(LineStyle.Single);
point1.getFormat().getLine().setDashStyle(LineDashStyle.LargeDashDot);

IChartDataPoint point2 = series.getDataPoints().get_Item(2);
point2.getFormat().getFill().setFillType(FillType.Solid);
point2.getFormat().getFill().getSolidFillColor().setColor(new Color(PresetColor.Coral));

// Setting Sector border
point2.getFormat().getLine().getFillFormat().setFillType(FillType.Solid);
point2.getFormat().getLine().getFillFormat().getSolidFillColor().setColor(Color.RED);
point2.getFormat().getLine().setWidth(2.0);
point2.getFormat().getLine().setStyle(LineStyle.ThinThin);
point2.getFormat().getLine().setDashStyle(LineDashStyle.LargeDashDotDot);

// Create custom labels for each of categories for new series

IDataLabel lbl1 = series.getDataPoints().get_Item(0).getLabel();
// lbl.ShowCategoryName = true;
lbl1.getDataLabelFormat().setShowValue(true);

IDataLabel lbl2 = series.getDataPoints().get_Item(1).getLabel();
lbl2.getDataLabelFormat().setShowValue(true);
lbl2.getDataLabelFormat().setShowLegendKey(true);
lbl2.getDataLabelFormat().setShowPercentage(true);

IDataLabel lbl3 = series.getDataPoints().get_Item(2).getLabel();
lbl3.getDataLabelFormat().setShowSeriesName(true);
lbl3.getDataLabelFormat().setShowPercentage(true);

// Showing Leader Lines for Chart
series.getLabels().getDefaultDataLabelFormat().setShowLeaderLines(true);

// Setting Rotation Angle for Pie Chart Sectors
chart.getChartData().getSeriesGroups().get_Item(0).setFirstSliceAngle(180);

// Save presentation with chart
pres.save(dataPath + "AsposePieChart.pptx", SaveFormat.Pptx);

System.out.println("Done");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* Copyright (c) Aspose 2002-2016. All Rights Reserved.
*
* LICENSE: This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://opensource.org/licenses/gpl-3.0.html>;.
*
* @author Shoaib Khan
*
* @link https://asposejavadocx4j.codeplex.com/
* @link https://sourceforge.net/projects/asposejavafordocx4j/
* @link https://github.com/asposemarketplace/Aspose_Java_for_Docx4j
* @link https://bitbucket.org/asposemarketplace/aspose-java-for-docx4j/
*/

package asposefeatures.workingwithmediacontrols.addaudioframe.java;

import java.io.File;
import java.io.FileInputStream;

import com.aspose.slides.AudioPlayModePreset;
import com.aspose.slides.AudioVolumeMode;
import com.aspose.slides.IAudioFrame;
import com.aspose.slides.ISlide;
import com.aspose.slides.Presentation;
import com.aspose.slides.SaveFormat;

public class AsposeAudioFrame
{
public static void main(String[] args) throws Exception
{
String dataPath = "src/asposefeatures/workingwithmediacontrols/addaudioframe/data/";

//Instantiate Prsentation class that represents the PPTX
Presentation pres = new Presentation();

//Get the first slide
ISlide sld = pres.getSlides().get_Item(0);

//Load the wav sound file to stram
FileInputStream fstr = new FileInputStream(new File(dataPath + "logon.wav"));

//Add Audio Frame
IAudioFrame af = sld.getShapes().addAudioFrameEmbedded(50, 150, 100, 100, fstr);

//Set Play Mode and Volume of the Audio
af.setPlayMode(AudioPlayModePreset.Auto);
af.setVolume(AudioVolumeMode.Loud);

//Write the PPTX file to disk
pres.save(dataPath + "AsposeAudio_Out.pptx", SaveFormat.Pptx);

System.out.println("Audio Control Added.");
}
}
Loading