Aspose.Diagram如何从存在的Visio文件里复制图形到新的文件

作者:控件中国网   出处:控件中国网   2016-01-07 14:36:30   阅读:11

Aspose.Diagram for Java是一款类似Visio软件一样的无图形界面类库,该控件提供了丰富的API可以帮助开发人员从以前存在的Visio文件中复制图形到新的Visio文件里,可以复制整个页面上的图形到新的页,下面的代码描述了怎么实现该功能,开发人员可以从控件中国网上下载试用版并进行测试,试用版都是完整功能版只是有水印。
 
// load a source Visio
Diagram srcVisio=new Diagram("C:\\temp\\DemoGroup.vsdx");
// initialize a new Visio
Diagram newDiagram = new Diagram();
 
// add all masters from the source Visio diagram
MasterCollection originalMasters = srcVisio.getMasters();
for (Master master : (Iterable<Master>) originalMasters)
    newDiagram.addMaster(srcVisio, master.getName());
 
// get the page object from the original diagram
Page SrcPage = srcVisio.getPages().getPage("Page-1");
// copy themes from the source diagram
newDiagram.copyTheme(srcVisio);
// copy pagesheet of the source Visio page
newDiagram.getPages().get(0).getPageSheet().copy(SrcPage.getPageSheet());
 
// copy shapes from the source Visio page
for (Shape shape : (Iterable<Shape>) srcVisio.getPages().getPage("Page-1").getShapes())
{
    shape.setID(GetMaxShapeID(SrcPage)+1);
    newDiagram.getPages().get(0).getShapes().add(shape);
}
// save the new Visio
newDiagram.save("C:\\temp\\Output.vdx", SaveFileFormat.VDX);
Copyright© 2006-2015 ComponentCN.com all rights reserved.重庆磐岩科技有限公司(控件中国网) 版权所有 渝ICP备12000264号 法律顾问:元炳律师事务所
客服软件
live chat