Hello
Hi Shubhi,
Thank you for contacting support. Please note, we recommend our users get a temporary license for Aspose APIs evaluation purposes. We offer 30 day temporary license.
Please download the latest version of Aspose.Diagram API and apply a valid license. Please refer to the following help topics: Applying a License for Aspose.Diagram for Java library, Download Aspose.Diagram for Java API
After applying a valid license, please use the sample codes as narrated there: Copy shape from one Visio file to another Visio file, Copy a Visio page into another Diagram and Insert a new blank page into a Visio drawing
Please note, “add” method of the ShapeCollection class allows to add group shape too. We hope, this helps. Please let us know in case of any confusion or questions.
Hello Imran
Thanks for your reply .I tried copying a GROUP shape using following snippet:
Diagram newDiagram = new Diagram();
int MaxPageId = GetMaxPageID(newDiagram);
Diagram srcVisio=new Diagram(“E:\Practice\asposeprac\asposeDiagram\Drawing3vsd.vsd”);
String pageName=“Page-1”;
// Initialize a new page object
Page newPage = new Page();
// Set name
newPage.setName(“new page”);
// Set page ID
newPage.setID(MaxPageId + 1);
// Add a new blank page
newDiagram.getPages().add(newPage);
// remove first empty page
newDiagram.getPages().remove(newDiagram.getPages().get(0));
// add all masters from the source Visio diagram
MasterCollection originalMasters = srcVisio.getMasters();
for (Master master : (Iterable) originalMasters) {
newDiagram.addMaster(srcVisio, master.getName());
}
// get the page object from the original diagram
Page SrcPage = srcVisio.getPages().getPage(pageName);
Shape shapeNew=null;
for(Shape shape:(Iterable)srcVisio.getPages().getPage(pageName).getShapes()){
if(shape.getType()==TypeValue.GROUP /*&&shape.getName().equalsIgnoreCase(groupName)*/){
shapeNew=shape;
break;
}
}
[//shapeNew.setName](https://shapenew.setname/)(“New Shape”);
shapeNew.setID(15);
shapeNew.setType(TypeValue.GROUP);
ShapeCollection ss=newDiagram.getPages().getPage(MaxPageId+1).getShapes();
ss.add(shapeNew);
newDiagram.save(“Temp111.vdx”, SaveFileFormat.VDX);
But it is saving a blank page ,shape is not getting displayed in VDX Output. Kindly confirm if it is correct way of adding GROUP type shapes.
Also I need to confirm when iam trying to save newDiagram in other formats such as PDF/HTML they are coming empty shape is not getting shown in it . Is there any way to directly save newDiagram to other formats rather than saving it to VDX.
Regards
Shubhi
Hi Shubhi,
Hello Imran please find the updated snippet :
License license = new License();license.setLicense(“Aspose.Diagram.lic”);Diagram newDiagram = new Diagram();int MaxPageId = GetMaxPageID(newDiagram);Diagram srcVisio=new Diagram(“E:\Practice\asposeprac\asposeDiagram\DemoGroup.vsdx”);String pageName=“Page-1”;// Initialize a new page objectPage newPage = new Page();// Set namenewPage.setName(“new page”);// Set page IDnewPage.setID(MaxPageId + 1);// Add a new blank pagenewDiagram.getPages().add(newPage);// remove first empty pagenewDiagram.getPages().remove(newDiagram.getPages().get(0));// add all masters from the source Visio diagramMasterCollection originalMasters = srcVisio.getMasters();for (Master master : (Iterable) originalMasters) {newDiagram.addMaster(srcVisio, master.getName());}// get the page object from the original diagramPage SrcPage = srcVisio.getPages().getPage(pageName);Shape shapeNew=null;for(Shape shape:(Iterable)srcVisio.getPages().getPage(pageName).getShapes()){if(shape.getType()==TypeValue.SHAPE ){shapeNew=shape;break;}}shapeNew.setName(“New Shape”);shapeNew.setID(GetMaxShapeID(SrcPage));shapeNew.setType(TypeValue.SHAPE);ShapeCollection ss=newDiagram.getPages().getPage(MaxPageId+1).getShapes();ss.add(shapeNew);newDiagram.save(“Temp111.pdf”, SaveFileFormat.PDF);
shubhi15sood:1) With this I am able to get group shape in VDX format only(For GROUP shape only) but it is not visible fully .Only one character (Text) within that shape is visible .Also Shape outlining is not coming.Do i need to set other properties for it?
shubhi15sood:2)On saving newDiagram to HTML ((in SHAPE as well as GROUP) )format I get following exception :java.lang.IllegalArgumentException: Width (0) and height (0) must be > 0at java.awt.image.SampleModel.(SampleModel.java:126)at java.awt.image.ComponentSampleModel.(ComponentSampleModel.java:146)at java.awt.image.PixelInterleavedSampleModel.(PixelInterleavedSampleModel.java:87)at java.awt.image.Raster.createInterleavedRaster(Raster.java:641)at java.awt.image.Raster.createInterleavedRaster(Raster.java:278)at java.awt.image.BufferedImage.(BufferedImage.java:384)at com.aspose.diagram.b.a.b.a.(Unknown Source)at com.aspose.diagram.b.a.b.a.(Unknown Source)at com.aspose.diagram.kd.a(Unknown Source)at com.aspose.diagram.kd.a(Unknown Source)at com.aspose.diagram.Diagram.save(Unknown Source)at com.aspose.diagram.Diagram.save(Unknown Source)at CopyShape.main(CopyShape.java:63)3) On saving newDiagram to PDF format (in SHAPE as well as GROUP) I get the blank PDF , Attaching the PDF named as Temp111.pdf. that is saved.
Hello Imran
- CopyShape.txtcode that i am using to copy shapes as well as Group shape.
- Temp111.PDF after saving newDiagram to PDF getting blank document
Hi Shubhi,
Hello Imran
Hi Shubhi,
Hello Imran
Hi Shubhi,
shubhi15sood:2)On saving newDiagram to HTML ((in SHAPE as well as GROUP) )format I get following exception :java.lang.IllegalArgumentException: Width (0) and height (0) must be > 0at java.awt.image.SampleModel.(SampleModel.java:126)at java.awt.image.ComponentSampleModel.(ComponentSampleModel.java:146)at java.awt.image.PixelInterleavedSampleModel.(PixelInterleavedSampleModel.java:87)at java.awt.image.Raster.createInterleavedRaster(Raster.java:641)at java.awt.image.Raster.createInterleavedRaster(Raster.java:278)at java.awt.image.BufferedImage.(BufferedImage.java:384)at com.aspose.diagram.b.a.b.a.(Unknown Source)at com.aspose.diagram.b.a.b.a.(Unknown Source)at com.aspose.diagram.kd.a(Unknown Source)at com.aspose.diagram.kd.a(Unknown Source)at com.aspose.diagram.Diagram.save(Unknown Source)at com.aspose.diagram.Diagram.save(Unknown Source)at CopyShape.main(CopyShape.java:63)
Hello
Hi Shubhi,
shubhi15sood:1) Fill style of the normal shapes are not getting copied in VDX format.We have logged a separate ticket id DIAGRAMJAVA-50238 for the fill style issue. This issue has also been linked to this forum thread. We'll let you know once a significant progress has been made in this regard. We're sorry for the inconvenience cause.shubhi15sood:2) While saving the newDiagram in different formats such as PDF/HTML I am still getting blank document for normal shapes as well as Group shapes.
shubhi15sood:Also kindly let me know the status of above bogs logged in relation to Group Shapes.
Hello Imran
Hi Shubhi,
Hi Shubhi,
Hi Shubhi,
Hi Shubhi,