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

This tutorial shows how .NET developers can convert a Visio shape to 0ther file formats inside .NET applications using Aspose.Diagram for .NET. Aspose.Diagram for .NET API allows developers to convert a single Visio shape to any other supported file format. In this article, we remove all other Visio shapes from the page and customize page setting according to the source Shape size. Developers can convert a Visio shape to PDF, HTML, Image, SVG, and SWF by specifying the Visio save options.
//your code here...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)

Url: http://www.aspose.com/.net/diagram-component.aspx

Language: C# | User: Sheraz Khan | Created: Feb 3, 2016 | Tags: Visio Shape to Other File Formats, convert single Visio shape to other formats, convert a Visio shape to PDF, convert Visio shape to HTML, convert Visio shape to Images, .NET Visio Component , C# Visio API Visio Shape to Other File Formats convert single Visio shape to other formats convert a Visio shape to PDF convert Visio shape to HTML convert Visio shape to Images .NET Visio Component C# Visio API