Reset the size of shape on the word document in C#

2017-10-26 02:24:52 Written by  support iceblue
Rate this item
(0 votes)

Spire.Doc supports to add new shape and shape group to the word document, it also supports to remove the shapes from the word. This article will show you how to reset the size of shape on an existing word document via Spire.Doc.

Firstly, view the original shape on the word document:

C# reset the size of shape on the word

Step 1: Create a new instance of word document and load the document from file.

Document doc = new Document();
doc.LoadFromFile("Sample.docx",FileFormat.Docx2010);

Step 2: Get the first section and the third paragraph that contains the shape.

Section section = doc.Sections[0]; 
Paragraph para = section.Paragraphs[2];

Step 3: Get the shape and reset the width and height for the shape.

ShapeObject shape = para.ChildObjects[0] as ShapeObject;

shape.Width = 400;
shape.Height = 300;

Step 4: Save the document to file.

doc.SaveToFile("result.docx",FileFormat.Docx2010);

Effective screenshot of the shape after reset the size.

C# reset the size of shape on the word

Full codes:

[C#]
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
namespace Reset
{
    class Program
    {
        static void Main(string[] args)
        {
            Document doc = new Document();
            doc.LoadFromFile("Sample.docx", FileFormat.Docx2010);

            Section section = doc.Sections[0];
            Paragraph para = section.Paragraphs[2];

            ShapeObject shape = para.ChildObjects[0] as ShapeObject;

            shape.Width = 400;
            shape.Height = 300;

            doc.SaveToFile("result.docx", FileFormat.Docx2010);
        }
    }
}
[VB.NET]
Imports Spire.Doc
Imports Spire.Doc.Documents
Imports Spire.Doc.Fields
Namespace Reset
	Class Program
		Private Shared Sub Main(args As String())
			Dim doc As New Document()
			doc.LoadFromFile("Sample.docx", FileFormat.Docx2010)

			Dim section As Section = doc.Sections(0)
			Dim para As Paragraph = section.Paragraphs(2)

			Dim shape As ShapeObject = TryCast(para.ChildObjects(0), ShapeObject)

			shape.Width = 400
			shape.Height = 300

			doc.SaveToFile("result.docx", FileFormat.Docx2010)
		End Sub
	End Class
End Namespace

Additional Info

  • tutorial_title: Reset the size of shape on the word document
Last modified on Friday, 03 September 2021 03:47