With the help of Spire.Presentation, we can add shapes to the presentation slides easily. This example shows you how to add a round corner rectangle to presentation slide and set the radius of the round corner rectangle in C#.

using Spire.Presentation;
using Spire.Presentation.Drawing;
using System.Drawing;

namespace RoundRectangle
{
    class Program
    {
        static void Main(string[] args)
        {          
            Presentation presentation = new Presentation();

            //Insert a round corner rectangle and set its radious
            presentation.Slides[0].Shapes.InsertRoundRectangle(0, 60, 90, 100, 200, 36);

            //Append a round corner rectangle and set its radious
            IAutoShape shape = presentation.Slides[0].Shapes.AppendRoundRectangle(260, 90, 100, 200, 80);
            //Set the color and fill style of shape
            shape.Fill.FillType = FillFormatType.Solid;
            shape.Fill.SolidColor.Color = Color.SeaGreen;
            shape.ShapeStyle.LineColor.Color = Color.White;
            //Rotate the shape to 90 degree
            shape.Rotation = 90;  
            
            //Save the document to file    
            presentation.SaveToFile("Result.pptx", FileFormat.Pptx2013);
                                                                              
        }
    }
}

Effective screenshot of the round corner rectangle on presentation slide:

Add a round corner rectangle to presentation slide in C#

When there are overlapping shapes/images in your presentation slide, you can control which shape is under or above which shape by bring a shape forward or to front, or sending a shape backward or to back. The following example shows you how to bring a shape forward using Spire.Presentation with C# and VB.NET.

Code Snippets

[C#]
//load the sample PowerPoint file
Presentation presentation = new Presentation();
presentation.LoadFromFile(@"C:\Users\Administrator\Desktop\input.pptx");

//get the specified shape
IShape shape = presentation.Slides[0].Shapes[0];

//bring the shape forward through SetShapeArrange method
shape.SetShapeArrange(ShapeArrange.BringForward);

//save to file
presentation.SaveToFile("output.pptx", FileFormat.Pptx2013);
[VB.NET]
'load the sample PowerPoint file
Dim presentation As Presentation =  New Presentation() 
presentation.LoadFromFile("C:\Users\Administrator\Desktop\input.pptx")
 
'get the specified shape
Dim shape As IShape =  presentation.Slides(0).Shapes(0) 
 
'bring the shape forward through SetShapeArrange method
shape.SetShapeArrange(ShapeArrange.BringForward)
 
'save to file
presentation.SaveToFile("output.pptx", FileFormat.Pptx2013)

Output

Arrange Shapes in PowerPoint in C#, VB.NET

Math equations in Word documents are essential tools for expressing mathematical concepts and relationships. Whether you are writing an academic paper, a scientific report, or any other document involving mathematical content, incorporating math equations can greatly enhance your ability to convey complex mathematical concepts and improve the visual appeal and professionalism of your document. In this article, we will explain how to insert math equations into Word documents in C# and VB.NET using Spire.Doc for .NET.

Install Spire.Doc for .NET

To begin with, you need to add the DLL files included in the Spire.Doc for .NET package as references in your .NET project. The DLL files can be either downloaded from this link or installed via NuGet.

PM> Install-Package Spire.Doc

Insert Math Equations into a Word Document in C# and VB.NET

Spire.Doc for .NET allows generating math equations from LaTeX code and MathML code using OfficeMath.FromLatexMathCode(string latexMathCode) and OfficeMath.FromMathMLCode(string mathMLCode) methods. The detailed steps are as follows:

  • Create two string arrays from LaTeX code and MathML code.
  • Create a Document instance and add a section to it using Document.AddSection() method.
  • Iterate through each LaTeX code in the string array.
  • Create a math equation from the LaTeX code using OfficeMath.FromLatexMathCode(string latexMathCode) method.
  • Add a paragraph to the section, then add the math equation to the paragraph using Paragraph.Items.Add() method.
  • Iterate through each MathML code in the string array.
  • Create a math equation from the MathML code using OfficeMath.FromMathMLCode(string mathMLCode) method.
  • Add a paragraph to the section, then add the math equation to the paragraph using Paragraph.Items.Add() method.
  • Save the result document using Document.SaveToFile() method.
  • C#
  • VB.NET
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields.OMath;

namespace AddMathEquations
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //Create a string array from LaTeX code
            string[] latexMathCode = {
                "x^{2}+\\sqrt{x^{2}+1}=2",
                "\\cos (2\\theta) = \\cos^2 \\theta - \\sin^2 \\theta",
                "k_{n+1} = n^2 + k_n^2 - k_{n-1}",
                "\\frac {\\frac {1}{x}+ \\frac {1}{y}}{y-z}",
                "\\int_0^ \\infty \\mathrm {e}^{-x} \\, \\mathrm {d}x",
                "\\forall x \\in X, \\quad \\exists y \\leq \\epsilon",
                "\\alpha, \\beta, \\gamma, \\Gamma, \\pi, \\Pi, \\phi, \\varphi, \\mu, \\Phi",
                "A_{m,n} = \\begin{pmatrix} a_{1,1} & a_{1,2} & \\cdots & a_{1,n} \\\\ a_{2,1} & a_{2,2} & \\cdots & a_{2,n} \\\\ \\vdots  & \\vdots  & \\ddots & \\vdots  \\\\ a_{m,1} & a_{m,2} & \\cdots & a_{m,n} \\end{pmatrix}",
            };

            //Create a string array from MathML code
            string[] mathMLCode = {
                "<math xmlns=\"http://www.w3.org/1998/Math/MathML\"><mi>a</mi><mo>≠</mo><mn>0</mn></math>",
                "<math xmlns=\"http://www.w3.org/1998/Math/MathML\"><mi>a</mi><msup><mi>x</mi><mn>2</mn></msup><mo>+</mo><mi>b</mi><mi>x</mi><mo>+</mo><mi>c</mi><mo>=</mo><mn>0</mn></math>",
                "<math xmlns=\"http://www.w3.org/1998/Math/MathML\"><mi>x</mi><mo>=</mo><mrow><mfrac><mrow><mo>−</mo><mi>b</mi><mo>±</mo><msqrt><msup><mi>b</mi><mn>2</mn></msup><mo>−</mo><mn>4</mn><mi>a</mi><mi>c</mi></msqrt></mrow><mrow><mn>2</mn><mi>a</mi></mrow></mfrac></mrow></math>",
            };

            //Create a Document instance
            Document doc = new Document();

            //Add a section
            Section section = doc.AddSection();

            //Add a paragraph to the section
            Paragraph textPara = section.AddParagraph();
            textPara.AppendText("Creating Equations from LaTeX Code");
            textPara.ApplyStyle(BuiltinStyle.Heading1);
            textPara.Format.HorizontalAlignment = HorizontalAlignment.Center;

            //Iterate through each LaTeX code in the string array
            for (int i = 0; i < latexMathCode.Length; i++)
            {
                //Create a math equation from the LaTeX code
                OfficeMath officeMath = new OfficeMath(doc);
                officeMath.FromLatexMathCode(latexMathCode[i]);
                //Add the math equation to the section
                Paragraph paragraph = section.AddParagraph();                                
                paragraph.Items.Add(officeMath);
                section.AddParagraph();
            }

            section.AddParagraph();

            //Add a paragraph to the section
            textPara = section.AddParagraph();
            textPara.AppendText("Creating Equations from MathML Code");
            textPara.ApplyStyle(BuiltinStyle.Heading1);
            textPara.Format.HorizontalAlignment = HorizontalAlignment.Center;

            //Iterate through each MathML code in the string array
            for (int j = 0; j < mathMLCode.Length; j++)
            {
                //Create a math equation from the MathML code
                OfficeMath officeMath = new OfficeMath(doc);
                officeMath.FromMathMLCode(mathMLCode[j]);
                //Add the math equation to the section
                Paragraph paragraph = section.AddParagraph();
                paragraph.Items.Add(officeMath);               
                section.AddParagraph();
            }

            //Save the result document    
            doc.SaveToFile("AddMathEquations.docx", FileFormat.Docx2013);
            doc.Dispose();
        }
    }
}

C#/VB.NET: Insert Math Equations into Word Documents

Apply for a Temporary License

If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.

A signature confirms that the digital document originated from the signer and has not been tampered with during transit. The use of digital signatures eliminates the need for sending paper documents, and reduces the number of the documents that need to be printed, mailed, and stored, saving you time and money. In this article, you will learn how to digitally sign a Word document in C# and VB.NET using Spire.Doc for .NET.

Install Spire.Doc for .NET

To begin with, you need to add the DLL files included in the Spire.Doc for.NET package as references in your .NET project. The DLL files can be either downloaded from this link or installed via NuGet.

PM> Install-Package Spire.Doc

Add a Digital Signature to Word in C#, VB.NET

The steps are as follows.

  • Create a Document object.
  • Load a Word document using Document.LoadFromFile() method.
  • Specify the path and the password of a .pfx certificate.
  • Digitally sign the document while saving the document using Document.SaveToFile(string fileName, FileFormat fileFormat, string certificatePath, string securePassword) method. Here are some other methods that you can use to digitally sign a Word document.
    • public void SaveToFile(string fileName, FileFormat fileFormat, byte[] certificateData, string securePassword);
    • public void SaveToStream(Stream stream, FileFormat fileFormat, byte[] certificateData, string securePassword);
    • public void SaveToStream(Stream stream, FileFormat fileFormat, string certificatePath, string securePassword);
    • public static byte[] Document.Sign(Stream sourceStream, byte[] certificateData, string securePassword);
    • public static byte[] Document.Sign(Stream sourceStream, string certificatePath, string securePassword);
  • C#
  • VB.NET
using Spire.Doc;

namespace DigitallySignWord
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a Document object
            Document doc = new Document();

            //Load a Word file
            doc.LoadFromFile("C:\\Users\\Administrator\\Desktop\\sample.docx");

            //Specify the certificate path
            string certificatePath = "C:\\Users\\Administrator\\Desktop\\gary.pfx";

            //Specify the password of the certificate
            string password = "e-iceblue";

            //Digitally sign the document while saving it to a .docx file
            doc.SaveToFile("AddDigitalSignature.docx", FileFormat.Docx2013, certificatePath, password);
        }
    }
}

C#/VB.NET: Digitally Sign Word Documents

Apply for a Temporary License

If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.

Besides the Combo Box, Text, Date Picker and Drop-Down List content controls, Checkbox and picture content control also are the mostly used content control in word document. Spire.Doc supports to add many kinds of content controls to the word document. This article will show you how to add checkbox and picture content control to word document by Spire.Doc for .NET.

Code snippets of how to add checkbox and picture content control:

using System;
using System.Drawing;
namespace AddCheckbox
{

    class Program
    {

        static void Main(string[] args)
        {
            //Create a new word document
            Document document = new Document();

            //Add a section to the document
            Section section = document.AddSection();

            //Add a document to the section
            Paragraph paragraph = section.AddParagraph();

            //Add checkbox content control
            StructureDocumentTagInline sdt = new StructureDocumentTagInline(document);
            paragraph = section.AddParagraph();
            sdt = new StructureDocumentTagInline(document);
            sdt.CharacterFormat.FontSize = 20;
            paragraph.ChildObjects.Add(sdt);
            sdt.SDTProperties.SDTType = SdtType.CheckBox;
            SdtCheckBox scb = new SdtCheckBox();
            sdt.SDTProperties.ControlProperties = scb;
            TextRange tr = new TextRange(document);
            tr.CharacterFormat.FontName = "MS Gothic";
            tr.CharacterFormat.FontSize = 20;
            sdt.ChildObjects.Add(tr);
            scb.Checked = true;

            sdt.SDTProperties.Alias = "CheckoBox";
            sdt.SDTProperties.Tag = "Checkbox";

            //Add picture content control
            paragraph = section.AddParagraph();
            sdt = new StructureDocumentTagInline(document);
            paragraph.ChildObjects.Add(sdt);
            sdt.SDTProperties.ControlProperties = new SdtPicture();

            sdt.SDTProperties.Alias = "Picture";
            sdt.SDTProperties.Tag = "Picture";

            DocPicture pic = new DocPicture(document) { Width = 10, Height = 10 };
            pic.LoadImage(Image.FromFile("Logo.jpg"));
            sdt.SDTContent.ChildObjects.Add(pic);

            document.SaveToFile("Sample.docx", FileFormat.Docx2013);

        }
    }
}

Effective screenshot after adding checkbox and picture content control to word document:

Add checkbox and picture content control to word document in C#

With the help of Spire.Presentation, developers can easily add and get speaker notes on presentation slides. From v 4.4.3, Spire.Presentation supports to retain the notes when converting presentation slides to SVG. This article will show you how to keep the notes when saving presentation slides to SVG in C#.

using Spire.Presentation;
using Spire.Presentation.Drawing;
using System.IO;
using System.Collections.Generic;

namespace PPT
{
    class Program
    {
        static void Main(string[] args)
        {
            //load the sample document with speaker notes
            Presentation ppt = new Presentation();
            ppt.LoadFromFile("Sample.pptx");

            //retain the notes when converting ppt to svg
            ppt.IsNoteRetained = true;


            //convert presentation slides to SVG
            Queue<byte[]> bytes = ppt.SaveToSVG();

            int length = bytes.Count;
            for (int i = 0; i < length; i++)
            {
                FileStream filestream = new FileStream(string.Format(@"output_{0}.svg", i), FileMode.Create);
                byte[] outputBytes = bytes.Dequeue();
                filestream.Write(outputBytes, 0, outputBytes.Length);
            }
            ppt.Dispose();
            ppt.SaveToSVG();
                                                       
        }
    }
}

Effective screenshot of retaining the speaker notes when converting presentation slides to SVG:

C# retain notes when converting presentation slides to SVG

With Spire.Doc for .NET, we can easily insert new text to word document at exact position, it also supports to insert new text after the certain text strings at many places. This article will show you how to insert new text strings after the searched text string in word document.

using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System.Drawing;

namespace Word
{
    class Program
    {
        static void Main(string[] args)
        {
            //load the sample document
            Document doc = new Document();
            doc.LoadFromFile("Sample.docx", FileFormat.Docx2010);

            //find all the text string “New Zealand” from the sample document
            TextSelection[] selections = doc.FindAllString("New Zealand", true, true);
            int index = 0;

            //defines text range
            TextRange range = new TextRange(doc);


            //insert new text string (NY) after the searched text string
            foreach (TextSelection selection in selections)
            {
                range = selection.GetAsOneRange();
                TextRange newrange = new TextRange(doc);
                newrange.Text = ("(NY)");
                index = range.OwnerParagraph.ChildObjects.IndexOf(range);
                range.OwnerParagraph.ChildObjects.Insert(index + 1, newrange);

            }

            //find and highlight the newly added text string NY
            TextSelection[] text2 = doc.FindAllString("NY", false, true);
            foreach (TextSelection seletion in text2)
            {
                seletion.GetAsOneRange().CharacterFormat.HighlightColor = Color.Yellow;
            }

            //save the document 
            doc.SaveToFile("Result.docx", FileFormat.Docx2010);
        }
    }
}

Effective screenshot after adding the text strings to the searched text:

C# add new text strings after the searched text string in word document

Get PDF Page Labels in C#

2019-03-26 07:12:21 Written by support iceblue

Page labels are used to identify each page visually on the screen or in print. This article demonstrates how to get the PDF page labels using Spire.PDF.

Below is the screenshot of the sample PDF document:

Get PDF Page Labels in C#

Detail steps:

Step 1: Create a PdfDocument instance and load the sample.pdf file.

PdfDocument pdf = new PdfDocument();
pdf.LoadFromFile("sample.pdf");

Step 2: Get the labels of the pages in the PDF file.

StringBuilder sb = new StringBuilder();
for (int i = 0; i < pdf.Pages.Count; i++)
{
    sb.AppendLine(pdf.Pages[i].PageLabel);
}

Step 3: Save to a .txt file.

File.WriteAllText("PageLabels.txt", sb.ToString());

Output:

Get PDF Page Labels in C#

Full code:

using System.IO;
using System.Text;
using Spire.Pdf;

namespace Get_PDF_Page_Labels
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a PdfDocument instance
            PdfDocument pdf = new PdfDocument();
            //Load the PDF file
            pdf.LoadFromFile("sample.pdf");

            //Create a StringBuilder instance
            StringBuilder sb = new StringBuilder();
            //Get the lables of the pages in the PDF file
            for (int i = 0; i < pdf.Pages.Count; i++)
            {
                sb.AppendLine(pdf.Pages[i].PageLabel);
            }

            //Save to a .txt file
            File.WriteAllText("PageLabels.txt", sb.ToString());
        }
    }
}

With Spire.XLS, developers can add text or image to the textbox to Excel worksheet easily. From version 9.3.10, Spire.XLS supports to set the inner margin of contents on Excel text box. With this feature, we can adjust the position of the text contents on the textbox to make it beautiful. This article is going to introduce how to set the inner margins of the textbox in Excel worksheet in C#.

using Spire.Xls;
using Spire.Xls.Core.Spreadsheet.Shapes;
namespace SetInternalMargin
{
    class Program
    {
        static void Main(string[] args)
        {
            {

                //load the sample document
                Workbook workbook = new Workbook();
                workbook.LoadFromFile("Sample.xlsx", ExcelVersion.Version2010);

                //get the first worksheet
                Worksheet sheet = workbook.Worksheets[0];

                //add a textbox to the sheet and set its position and size
                XlsTextBoxShape textbox = sheet.TextBoxes.AddTextBox(4, 2, 100, 300) as XlsTextBoxShape;

                //set the text on the textbox
                textbox.Text = "Insert TextBox in Excel and set the margin for the text";
                textbox.HAlignment = CommentHAlignType.Center;
                textbox.VAlignment = CommentVAlignType.Center;

                //set the inner margins of the contents 
                textbox.InnerLeftMargin = 1;
                textbox.InnerRightMargin = 3;
                textbox.InnerTopMargin = 1;
                textbox.InnerBottomMargin = 1;

                //save the document to file
                workbook.SaveToFile("Result.xlsx", ExcelVersion.Version2010);

            }

        }
    }
}

Effective screenshot after setting the margins of the contents:

Set the internal margin of excel textbox in C#

Get Cell Type in Excel in C#

2019-03-21 06:35:54 Written by support iceblue

Cell type refers to the data type in a cell. There are six cell types in Spire.XLS, i.e. String, Number, Formula, Boolean, Error and Blank. This article is going to show you how to get the cell types of specified cells in an Excel file using Spire.XLS.

Detail steps

Step 1: Create a Workbook instance and load the Excel file.

Workbook workbook = new Workbook();
workbook.LoadFromFile("Input.xlsx");

Step 2: Get the second worksheet.

Worksheet sheet = workbook.Worksheets[1];

Step 3: Get the cell types of the cells in range "A2:A7".

foreach (CellRange range in sheet.Range["A2:A7"])
{
    XlsWorksheet.TRangeValueType cellType = sheet.GetCellType(range.Row, range.Column, false);
    sheet[range.Row, range.Column+1].Text = cellType.ToString();
    sheet[range.Row, range.Column + 1].Style.Font.Color = Color.Red;
    sheet[range.Row, range.Column+1].Style.Font.IsBold = true;
}

Step 4: Save the file.

workbook.SaveToFile("GetCellType.xlsx", ExcelVersion.Version2013);

Output:

Get Cell Type in Excel in C#

Full code:

using System.Drawing;
using Spire.Xls;
using Spire.Xls.Core.Spreadsheet;

namespace GetCellType
{
    class Program
    {
        static void Main(string[] args)
        {
            //Load the Excel file
            Workbook workbook = new Workbook();
            workbook.LoadFromFile("Input.xlsx");

            //Get the second worksheet
            Worksheet sheet = workbook.Worksheets[1];

            //Get the cell types of the cells in range “A2:A7”
            foreach (CellRange range in sheet.Range["A2:A7"])
            {
                XlsWorksheet.TRangeValueType cellType = sheet.GetCellType(range.Row, range.Column, false);
                sheet[range.Row, range.Column+1].Text = cellType.ToString();
                sheet[range.Row, range.Column + 1].Style.Font.Color = Color.Red;
                sheet[range.Row, range.Column+1].Style.Font.IsBold = true;
            }            

            //Save the file
            workbook.SaveToFile("GetCellType.xlsx", ExcelVersion.Version2013);            
        }
    }
}
Page 9 of 91
page 9