by
8,582 16
0
5
3,195
0
Top 1% !
Famous
Easy-to-find
Specified
OpenSource
Popularity: 4158th place
Languagestata
LicenseMIT_X11

How to Convert a Visio Shape to Other File Formats inside .NET Applications

Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/1037963/How-to-Convert-a-Visio-Shape-to-Other-Fi?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
// Enter here the actual content of the snippet. The code snippets below show the complete source code for adding new shapes to a Visio diagram. // [C# Code Sample] double shapeWidth = 0; double shapeHeight = 0; // load Visio diagram Diagram srcVisio = new Diagram("C:/temp/MyVisio.vsd"); // get Visio page Aspose.Diagram.Page srcPage = srcVisio.Pages[1]; // remove background page srcPage.BackPage = null; // get hash table of shapes, it holds id and name Hashtable remShapes = new Hashtable(); //Hashtable<Long, String> remShapes = new Hashtable<Long, String>(); foreach (Aspose.Diagram.Shape shape in srcPage.Shapes) // for the normal shape remShapes.Add(shape.ID, shape.Name); // iterate through the hash table foreach (DictionaryEntry shapeEntry in remShapes) { long key = (long)shapeEntry.Key; string val = (string)shapeEntry.Value; Aspose.Diagram.Shape shape = srcPage.Shapes.GetShape(key); // check of the shape name if (val.Equals("GroupShape1")) { // move shape to the origin corner shapeWidth = shape.XForm.Width.Value; shapeHeight = shape.XForm.Height.Value; shape.MoveTo(shapeWidth * 0.5, shapeHeight * 0.5); // trim page size srcPage.PageSheet.PageProps.PageWidth.Value = shapeWidth; srcPage.PageSheet.PageProps.PageHeight.Value = shapeHeight; } else { // remove shape from the Visio page and hash table srcPage.Shapes.Remove(shape); } } remShapes.Clear(); // specify saving options Aspose.Diagram.Saving.PdfSaveOptions opts = new Aspose.Diagram.Saving.PdfSaveOptions(); // set page count to save opts.PageCount = 1; // set starting index of the page opts.PageIndex = 1; // save it srcVisio.Save("C:/temp/Output.pdf", opts); // [VB.NET Code Sample] Dim shapeWidth As Double = 0 Dim shapeHeight As Double = 0 ' load Visio diagram Dim srcVisio As New Diagram("C:/temp/MyVisio.vsd") ' get Visio page Dim srcPage As Aspose.Diagram.Page = srcVisio.Pages(1) ' remove background page srcPage.BackPage = Nothing ' get hash table of shapes, it holds id and name Dim remShapes As New Hashtable() 'Hashtable<Long, String> remShapes = new Hashtable<Long, String>(); For Each shape As Aspose.Diagram.Shape In srcPage.Shapes ' for the normal shape remShapes.Add(shape.ID, shape.Name) Next ' iterate through the hash table For Each shapeEntry As DictionaryEntry In remShapes Dim key As Long = CLng(shapeEntry.Key) Dim val As String = DirectCast(shapeEntry.Value, String) Dim shape As Aspose.Diagram.Shape = srcPage.Shapes.GetShape(key) ' check of the shape name If val.Equals("GroupShape1") Then ' move shape to the origin corner shapeWidth = shape.XForm.Width.Value shapeHeight = shape.XForm.Height.Value shape.MoveTo(shapeWidth * 0.5, shapeHeight * 0.5) ' trim page size srcPage.PageSheet.PageProps.PageWidth.Value = shapeWidth srcPage.PageSheet.PageProps.PageHeight.Value = shapeHeight Else ' remove shape from the Visio page and hash table srcPage.Shapes.Remove(shape) End If Next remShapes.Clear() ' specify saving options Dim opts As New Aspose.Diagram.Saving.PdfSaveOptions() ' set page count to save opts.PageCount = 1 ' set starting index of the page opts.PageIndex = 1 ' save it srcVisio.Save("C:/temp/Output.pdf", opts)
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus