Knowledgebase (2330)
Children categories
We have introduced how to add shapes to the slides by Spire.Presentaion. Spire.Presentation supports to work with lots of shapes, such as triangle, rectangle, ellipse, star, line and so on. This time we will show you how to add line arrow to the slides in C#.
Here comes to the code snippet.
Step 1: Create a PPT document.
Presentation presentation = new Presentation();
Step 2: Add a line to the slides and set its color to red.
IAutoShape shape = presentation.Slides[0].Shapes.AppendShape(ShapeType.Line, new RectangleF(50, 100, 100, 100)); shape.ShapeStyle.LineColor.Color = Color.Red;
Step 3: Set the line arrow by using LineEndType.
shape.Line.LineEndType = LineEndType.StealthArrow;
Step 4: Save and launch to view the PPTX document.
presentation.SaveToFile("shape.pptx", FileFormat.Pptx2010);
System.Diagnostics.Process.Start("shape.pptx");
Effective screenshots:

Full codes:
using Spire.Presentation;
using System.Drawing;
namespace AddLineArrow
{
class Program
{
static void Main(string[] args)
{
Presentation presentation = new Presentation();
IAutoShape shape = presentation.Slides[0].Shapes.AppendShape(ShapeType.Line, new RectangleF(50, 100, 100, 100));
shape.ShapeStyle.LineColor.Color = Color.Red;
shape.Line.LineEndType = LineEndType.StealthArrow;
shape = presentation.Slides[0].Shapes.AppendShape(ShapeType.Line, new RectangleF(300, 250, 150, 150));
shape.Rotation = -45;
shape.Line.LineEndType = LineEndType.TriangleArrowHead;
presentation.SaveToFile("shape.pptx", FileFormat.Pptx2010);
System.Diagnostics.Process.Start("shape.pptx");
}
}
}
New method get alias, tag and id of content controls in a Word document in C#
2015-06-05 03:59:58 Written by KoohjiContent controls provide a way for you to design documents. When you add a content control to a document, the control is identified by a border, a title, and temporary text that can provide instructions to the user, and can prevent users from editing or deleting protected sections of a document.
Bind parts of a document or template to data. You can bind content controls to database fields, managed objects in the .NET Framework, XML elements that are stored in the document, and other data sources.
This article illustrates how to get all controls and their properties including alias, id and tag via Spire.Doc with new method and replace the Barcode with another image.
Refer this article to check old method: Get alias, tag and id of content controls in a Word document in C#
The following is test file new.docx.

Here are the steps:
Step 1: Create a new Word document and load the test file.
Document doc = new Document(@"new.docx");
Step 2: Create a list StructureDocument to store tags. Here, each content control will be identified by tag.
public class StructureTags
{
List m_structureDocumnt;
public List StructureDocument
{
get
{
if (m_structureDocumnt == null)
m_structureDocumnt = new List();
return m_structureDocumnt;
}
}
}
Step 3: Use foreach sentence to get all tags in the Word document.
foreach (Section section in doc.Sections)
{
foreach (Body body in section.ChildObjects)
{
ModifyBody(body);
}
}
Step 4: Show the properties of all controls.
List tagInlines = structureTags.StructureDocument;
Console.WriteLine("Part1");
for (int i = 0; i < tagInlines.Count; i++)
{
string alias = tagInlines[i].SDTProperties.Alias; // Can be null or empty
decimal id = tagInlines[i].SDTProperties.Id;
string tag = tagInlines[i].SDTProperties.Tag;
string STDType = tagInlines[i].SDTProperties.SDTType.ToString();
Console.WriteLine("{0,20},{1,15},{2, 10} - {3}", alias, id, STDType, tag);
Console.ReadKey();
}
Step 5: Replace image inside of Picture Content Control.
doc.SaveToFile("replace1.docx", FileFormat.Docx2013);
System.Diagnostics.Process.Start("replace1.docx");
Result Screenshot:


Full code:
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System;
using System.Drawing;
namespace GetAlias
{
class Program
{
static StructureTags structureTags = new StructureTags();
static void Main(string[] args)
{
Document doc = new Document(@"new.docx");
foreach (Section section in doc.Sections)
{
foreach (Body body in section.ChildObjects)
{
ModifyBody(body);
}
}
List tagInlines = structureTags.StructureDocument;
Console.WriteLine("Part1");
for (int i = 0; i < tagInlines.Count; i++)
{
string alias = tagInlines[i].SDTProperties.Alias;
decimal id = tagInlines[i].SDTProperties.Id;
string tag = tagInlines[i].SDTProperties.Tag;
string STDType = tagInlines[i].SDTProperties.SDTType.ToString();
Console.WriteLine("{0,20},{1,15},{2, 10} - {3}", alias, id, STDType, tag);
Console.ReadKey();
if (tagInlines[i].SDTProperties.SDTType == SdtType.Picture)
{
DocPicture picture = tagInlines[i].ChildObjects.FirstItem as DocPicture;
if (picture == null)
{
picture = new DocPicture(doc);
picture.LoadImage(Image.FromFile(@"cat.jpg"));
tagInlines[i].ChildObjects.Add(picture);
}
else
{
picture.LoadImage(Image.FromFile(@"cat.jpg"));
}
}
}
doc.SaveToFile("replace1.docx", FileFormat.Docx2013);
System.Diagnostics.Process.Start("replace1.docx");
}
static void ModifyBody(Body body)
{
if (body == null)
return;
foreach (DocumentObject docObj in body.ChildObjects)
{
if (docObj is StructureDocumentTag)
{
structureTags.StructureDocument.Add(docObj as StructureDocumentTag);
}
else if (docObj is Table)
{
ModifyTable(docObj as Table);
}
else if (docObj is Paragraph)
{
ModifyParagraph(docObj as Paragraph);
}
}
}
static void ModifyTable(Table table)
{
if (table == null)
return;
foreach (TableRow row in table.Rows)
{
foreach (TableCell cell in row.Cells)
{
if (cell is StructureDocumentTagCell)
{
structureTags.StructureDocument.Add(cell as StructureDocumentTagCell);
}
else
{
ModifyBody(cell);
}
}
}
}
static void ModifyParagraph(Paragraph para)
{
if (para == null)
return;
foreach (DocumentObject docObj in para.ChildObjects)
{
if (docObj is StructureDocumentTagInline)
{
structureTags.StructureDocument.Add(docObj as StructureDocumentTagInline);
}
}
}
public class StructureTags
{
List m_structureDocumnt;
public List StructureDocument
{
get
{
if (m_structureDocumnt == null)
m_structureDocumnt = new List();
return m_structureDocumnt;
}
}
}
}
}
Headers and footers are widely used to show addition information such as chapter name, page numbers to keep the document organized. By default, MS Word sets the same headers and footers on each page, but sometimes we need to create different headers or footers for odd and even pages. This article is going to introduce the method to set different odd and even header/footer using Spire.Doc in C#.
Note: Before Start, please download the latest version of Spire.Doc and add Spire.Doc .dll in the bin folder as the reference of Visual Studio.
Step 1: Create a new document and load from file.
Document document = new Document();
document.LoadFromFile("T1.docx");
Step 2: Add a section and set the property true.
Section section = document.Sections[0]; section.PageSetup.DifferentOddAndEvenPagesHeaderFooter = true;
Step 3: Create odd and even footer, odd and even header, and set their format.
//add EvenFooter
Paragraph P1 = section.HeadersFooters.EvenFooter.AddParagraph();
TextRange EF = P1.AppendText("Even Footer Demo from E-iceblue Using Spire.Doc");
EF.CharacterFormat.FontName = "Calibri";
EF.CharacterFormat.FontSize = 20;
EF.CharacterFormat.TextColor = Color.Green;
EF.CharacterFormat.Bold = true;
P1.Format.HorizontalAlignment = HorizontalAlignment.Center;
//add OddFooter
Paragraph P2 = section.HeadersFooters.OddFooter.AddParagraph();
TextRange OF = P2.AppendText("Odd Footer Demo");
P2.Format.HorizontalAlignment = HorizontalAlignment.Center;
OF.CharacterFormat.FontName = "Calibri";
OF.CharacterFormat.FontSize = 20;
OF.CharacterFormat.Bold = true;
OF.CharacterFormat.TextColor = Color.Blue;
//add OddHeader
Paragraph P3 = section.HeadersFooters.OddHeader.AddParagraph();
TextRange OH = P3.AppendText("Odd Header Demo");
P3.Format.HorizontalAlignment = HorizontalAlignment.Center;
OH.CharacterFormat.FontName = "Calibri";
OH.CharacterFormat.FontSize = 20;
OH.CharacterFormat.Bold = true;
OH.CharacterFormat.TextColor = Color.Blue;
//add EvenHeader
Paragraph P4 = section.HeadersFooters.EvenHeader.AddParagraph();
TextRange EH = P4.AppendText("Even Header Demo from E-iceblue Using Spire.Doc");
P4.Format.HorizontalAlignment = HorizontalAlignment.Center;
EH.CharacterFormat.FontName = "Calibri";
EH.CharacterFormat.FontSize = 20;
EH.CharacterFormat.Bold = true;
EH.CharacterFormat.TextColor = Color.Green;
Step 4: Save the document and launch to see effects.
document.SaveToFile("R.docx", FileFormat.Docx2010);
System.Diagnostics.Process.Start("R.docx");
Effects:

Full code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System.Drawing;
namespace Mirror_Margin
{
class Program
{
static void Main(string[] args)
{
Document document = new Document();
document.LoadFromFile("T1.docx");
Section section = document.Sections[0];
section.PageSetup.DifferentOddAndEvenPagesHeaderFooter = true;
Paragraph P1 = section.HeadersFooters.EvenFooter.AddParagraph();
TextRange EF = P1.AppendText("Even Footer Demo from E-iceblue Using Spire.Doc");
EF.CharacterFormat.FontName = "Calibri";
EF.CharacterFormat.FontSize = 20;
EF.CharacterFormat.TextColor = Color.Green;
EF.CharacterFormat.Bold = true;
P1.Format.HorizontalAlignment = HorizontalAlignment.Center;
Paragraph P2 = section.HeadersFooters.OddFooter.AddParagraph();
TextRange OF = P2.AppendText("Odd Footer Demo");
P2.Format.HorizontalAlignment = HorizontalAlignment.Center;
OF.CharacterFormat.FontName = "Calibri";
OF.CharacterFormat.FontSize = 20;
OF.CharacterFormat.Bold = true;
OF.CharacterFormat.TextColor = Color.Blue;
Paragraph P3 = section.HeadersFooters.OddHeader.AddParagraph();
TextRange OH = P3.AppendText("Odd Header Demo");
P3.Format.HorizontalAlignment = HorizontalAlignment.Center;
OH.CharacterFormat.FontName = "Calibri";
OH.CharacterFormat.FontSize = 20;
OH.CharacterFormat.Bold = true;
OH.CharacterFormat.TextColor = Color.Blue;
Paragraph P4 = section.HeadersFooters.EvenHeader.AddParagraph();
TextRange EH = P4.AppendText("Even Header Demo from E-iceblue Using Spire.Doc");
P4.Format.HorizontalAlignment = HorizontalAlignment.Center;
EH.CharacterFormat.FontName = "Calibri";
EH.CharacterFormat.FontSize = 20;
EH.CharacterFormat.Bold = true;
EH.CharacterFormat.TextColor = Color.Green;
document.SaveToFile("R.docx", FileFormat.Docx2010);
System.Diagnostics.Process.Start("R.docx");
}
}
}