With auto-fit feature, you can automatically reduce the font size of text to fit a shape, or you can shrink or enlarge shape to fit the exact size of your text. This article will show you how to auto-fit text or shape using Spire.Presentation with C#, VB.NET.

Step 1: Create an instance of Presentation class.

Presentation presentation = new Presentation();

Step 2: Insert a shape, and set the AutofitType property to Normal, which means the text automatically shrinks to fit shape.

IAutoShape textShape1 = presentation.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 50, 150, 80));
textShape1.TextFrame.Text = "Shrink text to fit shape. Shrink text to fit shape. Shrink text to fit shape. Shrink text to fit shape.";
textShape1.TextFrame.AutofitType = TextAutofitType.Normal;

Step 3: Insert a shape, and set the AutofitType property to Shape, which means the shape size automatically decreases or increases to fit text.

IAutoShape textShape2 = presentation.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(350, 50, 150, 80));
textShape2.TextFrame.Text = "Resize shape to fit text.";
textShape2.TextFrame.AutofitType = TextAutofitType.Shape;

Step 4: Save the file.

presentation.SaveToFile("output.pptx", FileFormat.Pptx2013);

Output:

Auto-Fit Text or Shape in PowerPoint in C#, VB.NET

Full Code:

[C#]
using Spire.Presentation;
using System.Drawing;
namespace AutofitinPPT
{
    class Program
    {
        static void Main(string[] args)
        {

            Presentation presentation = new Presentation();

            IAutoShape textShape1 = presentation.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 50, 150, 80));
            textShape1.TextFrame.Text = "Shrink text to fit shape. Shrink text to fit shape. Shrink text to fit shape. Shrink text to fit shape.";
            textShape1.TextFrame.AutofitType = TextAutofitType.Normal;

            IAutoShape textShape2 = presentation.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(350, 50, 150, 80));
            textShape2.TextFrame.Text = "Resize shape to fit text.";
            textShape2.TextFrame.AutofitType = TextAutofitType.Shape;

            presentation.SaveToFile("output.pptx", FileFormat.Pptx2013);
        }
    }
}
[VB.NET]
Imports Spire.Presentation
Imports System.Drawing
Namespace AutofitinPPT
	Class Program
		Private Shared Sub Main(args As String())

			Dim presentation As New Presentation()

			Dim textShape1 As IAutoShape = presentation.Slides(0).Shapes.AppendShape(ShapeType.Rectangle, New RectangleF(50, 50, 150, 80))
			textShape1.TextFrame.Text = "Shrink text to fit shape. Shrink text to fit shape. Shrink text to fit shape. Shrink text to fit shape."
			textShape1.TextFrame.AutofitType = TextAutofitType.Normal

			Dim textShape2 As IAutoShape = presentation.Slides(0).Shapes.AppendShape(ShapeType.Rectangle, New RectangleF(350, 50, 150, 80))
			textShape2.TextFrame.Text = "Resize shape to fit text."
			textShape2.TextFrame.AutofitType = TextAutofitType.Shape

			presentation.SaveToFile("output.pptx", FileFormat.Pptx2013)
		End Sub
	End Class
End Namespace

How to explode a doughnut chart in C#

2018-02-06 07:37:57 Written by Koohji

In the previous article, we have demonstrated how to explode a pie chart via Spire.XLS. This article we will explain how to explode a doughnut chart in C#.

When we need to explode a doughnut chart, we can set the chart type as DoughnutExploded when we create a doughnut chart from scratch. For the existing doughnut chart, we can easily change the chart type to explode the doughnut chart.

Step 1: Create an instance of Excel workbook and load the document from file.

Workbook workbook = new Workbook();
workbook.LoadFromFile("DoughnutChart.xlsx",ExcelVersion.Version2010);

Step 2: Get the first worksheet from the sample workbook.

Worksheet sheet = workbook.Worksheets[0];

Step 3: Get the first chart from the first worksheet.

Chart chart = sheet.Charts[0];

Step 4: Set the chart type as DoughnutExploded to explode the doughnut chart.

chart.ChartType = ExcelChartType.DoughnutExploded;

Step 5: Save the document to file.

workbook.SaveToFile("ExplodedDoughnutChart.xlsx", ExcelVersion.Version2010);

Effective screenshot of the explode doughnut chart:

How to explode a doughnut chart in C#

Full codes of how to explode a doughnut chart:

using Spire.Xls;
namespace ExplodeDoughnut
{

    class Program
    {

        static void Main(string[] args)
        {
            Workbook workbook = new Workbook();
            workbook.LoadFromFile("DoughnutChart.xlsx", ExcelVersion.Version2010);

            Worksheet sheet = workbook.Worksheets[0];
            Chart chart = sheet.Charts[0];
            chart.ChartType = ExcelChartType.DoughnutExploded;

            workbook.SaveToFile("ExplodedDoughnutChart.xlsx", ExcelVersion.Version2010);
        }

    }
}

Resize Images in a Word document in C#

2018-02-06 07:32:50 Written by Koohji

We often need to resize images to a desired size after we insert them into a Word document. This article demonstrates how to programmatically resize images in a Word document using Spire.Doc and C#.

Below is the screenshot of the example document we used for demonstration:

Resize Images in a Word document in C#

Detail steps:

Step 1: Load the Word document.

Document document = new Document("Input.docx");

Step 2: Get the first section and the first paragraph in the section.

Section section = document.Sections[0];
Paragraph paragraph = section.Paragraphs[0];

Step 3: Resize images in the paragraph.

foreach (DocumentObject docObj in paragraph.ChildObjects)
{
    if (docObj is DocPicture)
    {
        DocPicture picture = docObj as DocPicture;
        picture.Width = 50f;
        picture.Height = 50f;
    }
} 

Step 4: Save the document.

document.SaveToFile("ResizeImages.docx");

Output:

Resize Images in a Word document in C#

Full code:

using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
namespace Resize
{
    class Program
    {
        static void Main(string[] args)
        {
            Document document = new Document("Input.docx");
            Section section = document.Sections[0];
            Paragraph paragraph = section.Paragraphs[0];

            foreach (DocumentObject docObj in paragraph.ChildObjects)
            {
                if (docObj is DocPicture)
                {
                    DocPicture picture = docObj as DocPicture;
                    picture.Width = 50f;
                    picture.Height = 50f;
                }
            }
            document.SaveToFile("ResizeImages.docx");
        }
    }
}
page 178