How to export Diagram into image and Word document?
Essential® Diagram allows exporting the diagram to a Word document and an image.
- Exporting as Image can be achieved by using Diagram.ExportDiagramAsImage() and saving as Image.
- Exporting into Word document can be achieved by saving the diagram in standard image formats such as bitmaps, enhanced metafiles , SVG format files and these images can be exported to word document using Essential® DocIO. For this it is neccessary to have Essential® DocIO to be installed.
Exporting as Image
C#
ImageFormat imgformat = ImageFormat.Bmp; Image img = this.diagram1.View.ExportDiagramAsImage(true); img.Save("MyDiagram.bmp", imgformat);
VB
Dim imgformat As ImageFormat = ImageFormat.Bmp Dim img As Image = Me.diagram1.View.ExportDiagramAsImage(True) img.Save("MyDiagram.bmp", imgformat)
Exporting into Word Document
C#
System.Drawing.Image diagramimage = new Bitmap(1, 1, PixelFormat.Format24bppRgb); Graphics grfx = Graphics.FromImage(diagramimage); IntPtr hdc = grfx.GetHdc(); Metafile emf = new Metafile(hdc, EmfType.EmfOnly); Graphics emfgrfx = Graphics.FromImage(emf); this.diagram1.View.ExportDiagramToGraphics(emfgrfx,true); grfx.ReleaseHdc(hdc); grfx.Dispose(); emfgrfx.Dispose(); diagramimage.Dispose(); WordDocument document = new WordDocument(); // Adding a new section to the document. IWSection section = document.AddSection(); // Adding a paragraph to the section IWParagraph paragraph = section.AddParagraph(); WPicture mImage = (WPicture)paragraph.AppendPicture(emf); document.Save("Sample.doc", Syncfusion.DocIO.FormatType.Doc); System.Diagnostics.Process.Start("Sample.doc");
VB
Dim diagramimage As System.Drawing.Image = New Bitmap(1, 1, PixelFormat.Format24bppRgb) Dim grfx As Graphics = Graphics.FromImage(diagramimage) Dim hdc As IntPtr = grfx.GetHdc() Dim emf As Metafile = New Metafile(hdc, EmfType.EmfOnly) Dim emfgrfx As Graphics = Graphics.FromImage(emf) Me.diagram1.View.ExportDiagramToGraphics(emfgrfx,True) grfx.ReleaseHdc(hdc) grfx.Dispose() emfgrfx.Dispose() diagramimage.Dispose() Dim document As WordDocument = New WordDocument() 'Adding a new section to the document. Dim section As IWSection = document.AddSection() 'Adding a paragraph to the section Dim paragraph As IWParagraph = section.AddParagraph() Dim mImage As WPicture = CType(paragraph.AppendPicture(emf), WPicture) document.Save("Sample.doc", Syncfusion.DocIO.FormatType.Doc) System.Diagnostics.Process.Start("Sample.doc")
Sample :
Conclusion
I hope you enjoyed learning about how to export a diagram into an image and a Word document.
You can refer to the WinForms Diagram feature tour page to learn about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WinForms Diagram example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!