本文介绍如何使用Spire.Presentation for Java在PPT幻灯片中设置自定义动画路径。
import com.spire.presentation.*;
import com.spire.presentation.collections.CommonBehaviorCollection;
import com.spire.presentation.drawing.FillFormatType;
import com.spire.presentation.drawing.animation.*;
import java.awt.*;
import java.awt.geom.Point2D;
public class CustomAnimationPath {
public static void main(String[] args) throws Exception {
//创建一个空白PPT文档
Presentation ppt = new Presentation();
//获取第一张幻灯片(新建的幻灯片文档默认已包含一张幻灯片)
ISlide slide = ppt.getSlides().get(0);
//添加形状到幻灯片
IAutoShape shape = slide.getShapes().appendShape(ShapeType.FIVE_POINTED_STAR,new Rectangle(180, 100, 170, 170));
shape.getFill().setFillType(FillFormatType.GRADIENT);
shape.getFill().getGradient().getGradientStops().append(0, KnownColors.LIGHT_PINK);
shape.getFill().getGradient().getGradientStops().append(1, KnownColors.PURPLE);
shape.getShapeStyle().getLineColor().setColor(Color.white);
//添加动画效果,并设置动画效果类型为PATH_USER(自定义类型)
AnimationEffect effect = slide.getTimeline().getMainSequence().addEffect(shape, AnimationEffectType.PATH_USER);
//获取自定动画的CommonBehavior集合
CommonBehaviorCollection commonBehaviorCollection = effect.getCommonBehaviorCollection();
//设置动画动作运动起点及路径模式
AnimationMotion motion = (AnimationMotion)commonBehaviorCollection.get(0);
motion.setOrigin(AnimationMotionOrigin.LAYOUT);
motion.setPathEditMode(AnimationMotionPathEditMode.RELATIVE);
//设置动作路径
MotionPath motionPath = new MotionPath();
motionPath.addPathPoints(MotionCommandPathType.MOVE_TO,new Point2D.Float[]{new Point2D.Float(0,0)},MotionPathPointsType.CURVE_AUTO,true);
motionPath.addPathPoints(MotionCommandPathType.LINE_TO,new Point2D.Float[]{new Point2D.Float(0.1f,0.1f)},MotionPathPointsType.CURVE_AUTO,true);
motionPath.addPathPoints(MotionCommandPathType.LINE_TO,new Point2D.Float[]{new Point2D.Float(-0.1f,0.2f)},MotionPathPointsType.CURVE_AUTO,true);
motionPath.addPathPoints(MotionCommandPathType.END,new Point2D.Float[]{},MotionPathPointsType.CURVE_AUTO,true);
//设置动作路径到动画
motion.setPath(motionPath);
//保存文档
ppt.saveToFile("result.pptx", FileFormat.PPTX_2013);
ppt.dispose();
}
}
设置结果:

Spire.PDF 7.5.0已发布。该版本支持转换PDF为透明背景的图片,修复了转换SVG到PDF内容不正确的问题,并且还修复了合并文档时出现的问题。详情请阅读以下内容。
新功能:
PdfDocument doc = new PdfDocument();
doc.LoadFromFile("https://cdn.e-iceblue.cn/input.pdf");
doc.ConvertOptions.SetPdfToImageOptions(0);
Image image = doc.SaveAsImage(0);
image.Save("output.png", ImageFormat.Png);
问题修复:
Spire.Office 6.4.4已发布。本次版本更新带来了一些优质功能,比如:Spire.PDF支持了在转换PDF到Excel时设置根据线条决定单元格的功能,新增了PrintSettings.IsValid属性的功能以判断打印机是否可以使用;Spire.XLS支持获取打印机自定义的纸张大小后设置给工作表;Spire.Presentation支持通过流添加Video以及支持了添加自定义路径动画。除此之外,该版本还修复了大量问题。详情请阅读以下内容。
该版本涵盖了最新版的Spire.Doc, Spire.PDF, Spire.XLS, Spire.Presentation, Spire.Email, Spire.DocViewer, Spire.PDFViewer, Spire.Spreadsheet, Spire.OfficeViewer, Spire.DataExport, Spire.Barcode。
问题修复:
https://www.e-iceblue.cn/Downloads/Spire-Office-NET.html
新功能:
PdfDocument pdf = new PdfDocument();
pdf.LoadFromFile(PDFFile);
pdf.ConvertOptions.SetPdfToXlsxOptions(PdfToXlsxLayout.Line);
pdf.SaveToFile(ExcelFile, FileFormat.XLSX);
PdfDocument pdf = new PdfDocument();
pdf.LoadFromFile(inputFile);
pdf.PrintSettings.PrinterName = @"Microsoft XPS Document Writer";
bool value = pdf.PrintSettings.IsValid;
问题修复:
问题修复:
问题修复:
新功能:
PageSetup.CustomPaperSizeName
问题修复:
新功能:
AppendVideoMedia(Stream stream, RectangleF rectangle);
Presentation ppt = new Presentation();
IAutoShape shape = ppt.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(0, 0, 200, 200));
AnimationEffect effect = ppt.Slides[0].Timeline.MainSequence.
AddEffect(shape, AnimationEffectType.PathUser);
CommonBehaviorCollection common = effect.CommonBehaviorCollection;
AnimationMotion motion = (AnimationMotion)common[0];
motion.Origin = AnimationMotionOrigin.Layout;
motion.PathEditMode = AnimationMotionPathEditMode.Relative;
MotionPath moinPath = new MotionPath();
moinPath.Add(MotionCommandPathType.MoveTo, new PointF[] { new PointF(0, 0) }, MotionPathPointsType.CurveAuto, true);
moinPath.Add(MotionCommandPathType.LineTo, new PointF[] { new PointF(0.1f, 0.1f) }, MotionPathPointsType.CurveAuto, true);
moinPath.Add(MotionCommandPathType.LineTo, new PointF[] { new PointF(-0.1f, 0.2f) }, MotionPathPointsType.CurveAuto, true);
moinPath.Add(MotionCommandPathType.End, new PointF[] { }, MotionPathPointsType.CurveStraight, true);
motion.Path = moinPath;
ppt.SaveToFile(outputFile, FileFormat.Pptx2010);
ppt.Dispose();
问题修复:
Spire.Presentation 6.4.5已发布。该版本支持通过流添加Video以及支持了添加自定义路径动画。此外,本次更新还增强了转换PPT到图片的功能,同时也修复了加载PPT文档时出现的问题。详情请阅读以下内容。
新功能:
AppendVideoMedia(Stream stream, RectangleF rectangle);
Presentation ppt = new Presentation();
IAutoShape shape = ppt.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(0, 0, 200, 200));
AnimationEffect effect = ppt.Slides[0].Timeline.MainSequence.
AddEffect(shape, AnimationEffectType.PathUser);
CommonBehaviorCollection common = effect.CommonBehaviorCollection;
AnimationMotion motion = (AnimationMotion)common[0];
motion.Origin = AnimationMotionOrigin.Layout;
motion.PathEditMode = AnimationMotionPathEditMode.Relative;
MotionPath moinPath = new MotionPath();
moinPath.Add(MotionCommandPathType.MoveTo, new PointF[] { new PointF(0, 0) }, MotionPathPointsType.CurveAuto, true);
moinPath.Add(MotionCommandPathType.LineTo, new PointF[] { new PointF(0.1f, 0.1f) }, MotionPathPointsType.CurveAuto, true);
moinPath.Add(MotionCommandPathType.LineTo, new PointF[] { new PointF(-0.1f, 0.2f) }, MotionPathPointsType.CurveAuto, true);
moinPath.Add(MotionCommandPathType.End, new PointF[] { }, MotionPathPointsType.CurveStraight, true);
motion.Path = moinPath;
ppt.SaveToFile(outputFile, FileFormat.Pptx2010);
ppt.Dispose();
问题修复:
https://www.e-iceblue.cn/Downloads/Spire-Presentation-NET.html
Spire.XLS 11.4.6已发布。本次更新的版本支持了获取打印机自定义的纸张大小后设置给工作表,增强了转换Excel到PDF的功能,并且修复了加载保存Excel文档等出现的问题。详情请阅读以下内容。
新功能:
PageSetup.CustomPaperSizeName
问题修复:
Spire.Spreadsheet 5.4.1已发布。本次更新修复了加载和显示Excel文档相关的问题。详情请阅读以下内容。
问题修复:
https://www.e-iceblue.cn/Downloads/Spire-Spreadsheet-NET.html
Spire.Doc 9.4.18已发布。该版本增强了转换Word到PDF/XPS的功能,并且还修复了加载HTML文档、添加HTML文本时出现的问题。详情请看以下内容。
问题修复:
Spire.Office for Java 4.4.6 已发布。本次版本更新带来了一系列新的功能,比如: Spire.XLS for Java支持添加删除数字签名并新增 setCustomPaperSize 方法以自定义纸张大小;Spire.PDF for Java查找换行文本时,支持返回所有的矩形区域信息并新增移除 JavaScript 脚本的方法;Spire.Presentation for Java支持表格的分布行和分布列的功能等等。此外,该版本还修复了大量问题。详情请阅读以下内容。
获取Spire.Office for Java 4.4.6请点击:https://www.e-iceblue.cn/Downloads/Spire-Office-JAVA.html
新功能:
Workbook workbook=new Workbook();
workbook.loadFromFile("C:/sample.xlsx");
CertificateAndPrivateKey cap = new CertificateAndPrivateKey("C:/Test1.pfx","e-iceblue");
workbook.addDigitalSignature(cap, "e-iceblue",new Date());
String result="C:/result.xlsx";
workbook.saveToFile(result,ExcelVersion.Version2013);
Workbook workbook2=new Workbook();
workbook2.loadFromFile(result);
workbook2.removeAllDigitalSignatures();
String result2="C:/result2.xlsx";
workbook2.saveToFile(result2,ExcelVersion.Version2013);
workbook.getWorksheets().get(0).getPageSetup().setCustomPaperSize(100, 100);
问题修复:
新功能:
PdfDocument doc = new PdfDocument(); doc.loadFromFile(inputFile);
FileWriter fileWriter = new FileWriter(outputFile, true);
int index=0;
for (PdfPageBase page : (Iterable) doc.getPages())
{
index++; PdfTextFind[] results = page.findText("findtext", EnumSet.of(TextFindParameter.CrossLine)).getFinds();
for (PdfTextFind text : results)
{
text.applyHighLight(); List bounds = text.getTextBounds();
String context="";
for (Rectangle2D rectangle2D:bounds)
{
context +="current "+index+" page;content:"+text.getSearchText()+ ";X:="+rectangle2D.getX()+","+"Y:="+rectangle2D.getY()+","+ "Width:="+rectangle2D.getWidth()+","+"height:="+rectangle2D.getHeight()+"\r\n";
} System.out.println(context); fileWriter.write(context); fileWriter.flush();
}
} fileWriter.close(); doc.saveToFile(outputPdf);
PdfDocument pdf = new PdfDocument();
pdf.loadFromFile(https://cdn.e-iceblue.cn/input);
pdf.removeDocumentJavaScript();
pdf.saveToFile(output, FileFormat.PDF);
问题修复:
优化:
新功能:
ISlide slide = presentation.getSlides().get(0);
ITable table = (ITable) slide.getShapes().get(0);
table.distributeRows(0,3);
table.distributeColumns(0,2);
问题修复:
Spire.XLS for Java 4.4.6已发布。本次更新新增了setCustomPaperSize方法以自定义纸张大小的功能,优化Excel转HTML的功能,同时还修复了XLSX转XLSM数据被隐藏的问题。详情请阅读以下内容。
新功能:
workbook.getWorksheets().get(0).getPageSetup().setCustomPaperSize(100, 100);
问题修复:
Spire.PDF for Java 4.4.8已发布。该版本新增了移除JavaScript脚本的方法并且修复了提取文本时出现的问题。详情请阅读以下内容。
新功能:
PdfDocument pdf = new PdfDocument();
pdf.loadFromFile(https://cdn.e-iceblue.cn/input);
pdf.removeDocumentJavaScript();
pdf.saveToFile(output, FileFormat.PDF);
问题修复: