Independentsoft
Professional software libraries for developers
Home
Purchase
Support
Company
Contact
ODF .NET
>
Tutorial
> Draw shapes
The following example shows how to draw a rectangle shape in a text document.
C# example
using System; using Independentsoft.Office.Odf; using Independentsoft.Office.Odf.Drawing; using Independentsoft.Office.Odf.Styles; namespace Sample { class Program { static void Main(string[] args) { TextDocument doc = new TextDocument(); GraphicStyle shapeStyle = new GraphicStyle("GS1"); shapeStyle.GraphicProperties.FillColor = "#4472C4"; shapeStyle.GraphicProperties.StrokeColor = "#000000"; doc.AutomaticStyles.Styles.Add(shapeStyle); Rectangle rect = new Rectangle(); rect.Style = "GS1"; rect.X = new Size(20, Unit.Millimeter); rect.Y = new Size(20, Unit.Millimeter); rect.Width = new Size(80, Unit.Millimeter); rect.Height = new Size(40, Unit.Millimeter); Paragraph p1 = new Paragraph(); p1.Add(rect); doc.Body.Add(p1); doc.Save("c:\\test\\output.odt", true); } } }
VB example
Imports System Imports Independentsoft.Office.Odf Imports Independentsoft.Office.Odf.Drawing Imports Independentsoft.Office.Odf.Styles Module Module1 Sub Main(ByVal args() As String) Dim doc As TextDocument = New TextDocument Dim shapeStyle As GraphicStyle = New GraphicStyle("GS1") shapeStyle.GraphicProperties.FillColor = "#4472C4" shapeStyle.GraphicProperties.StrokeColor = "#000000" doc.AutomaticStyles.Styles.Add(shapeStyle) Dim rect As Rectangle = New Rectangle rect.Style = "GS1" rect.X = New Size(20, Unit.Millimeter) rect.Y = New Size(20, Unit.Millimeter) rect.Width = New Size(80, Unit.Millimeter) rect.Height = New Size(40, Unit.Millimeter) Dim p1 As Paragraph = New Paragraph p1.Add(rect) doc.Body.Add(p1) doc.Save("c:\test\output.odt", True) End Sub End Module
Need help? Ask our developers:
Name*
Email*
Message*