We have already demonstrated how to set the animations on shapes in PowerPoint. Now Spire.Presentation starts to support set the Animation Effect for the type and time of the animate text. This article will show you how to use IterateType property and IterateTimeValue property for animation Effect to set the type and time of animate text in C#.

Firstly, view the original sample document with animate text effect with "All at once".

C# Set animation effect for the animate text on the presentation slides

Step 1: Create a presentation instance and load the sample document from file.

Presentation ppt = new Presentation();
ppt.LoadFromFile("Sample.pptx",FileFormat.Pptx2010);

Step 2: Set the AnimateType as Letter.

ppt.Slides[0].Timeline.MainSequence[0].IterateType = Spire.Presentation.Drawing.TimeLine.AnimateType.Letter;

Step 3: Set the IterateTimeValue for the animate text.

ppt.Slides[0].Timeline.MainSequence[0].IterateTimeValue = 10;

Step 4: Save the document to file.

ppt.SaveToFile("Result.pptx", FileFormat.Pptx2010);

Effective screenshot of the animation effect for the animate text effect with "by Letter".

C# Set animation effect for the animate text on the presentation slides

C# Set animation effect for the animate text on the presentation slides

This article demonstrates how to print different pages of a PDF document to different printer trays using Spire.PDF and c#.

Code snippets:

Step 1: Initialize an object of PdfDocument class and Load the PDF document.

PdfDocument doc = new PdfDocument();
doc.LoadFromFile(@"F:\sample.pdf");

Step 2: Set different printer trays for different pages of the document.

doc.PrintSettings.PaperSettings += delegate(object sender, PdfPaperSettingsEventArgs e)
{
    //Set the paper source of page 1-50 as tray 1
    if (1 <= e.CurrentPaper && e.CurrentPaper <= 50)
    {        
        e.CurrentPaperSource = e.PaperSources[0];
    }
    //Set the paper source of the rest of pages as tray 2
    else
    {
        e.CurrentPaperSource = e.PaperSources[1];
    }
};

Step 3: Print the document.

doc.Print();

Full code:

using Spire.Pdf;
using Spire.Pdf.Print;

namespace Print_pages_to_different_printer_trays
{
    class Program
    {
        static void Main(string[] args)
        {
            //Initialize an object of PdfDocument class
            PdfDocument doc = new PdfDocument();
            //Load the PDF document
            doc.LoadFromFile(@"F:\sample.pdf");

            //Set Paper source
            doc.PrintSettings.PaperSettings += delegate(object sender, PdfPaperSettingsEventArgs e)
            {
                //Set the paper source of page 1-50 as tray 1
                if (1 <= e.CurrentPaper && e.CurrentPaper <= 50)
                {
                    e.CurrentPaperSource = e.PaperSources[0];
                }
                //Set the paper source of the rest of pages as tray 2
                else
                {
                    e.CurrentPaperSource = e.PaperSources[1];
                }
            };
            //Print the document
            doc.Print();
        }
    }
}

A theme is a set of colors, fonts, and effects that determines the overall look of your Word document. Suppose you have a document which is neat and stylish, you’d like to copy contents of a section to another document without losing the theme and style. You can clone the theme to destination file using CloneThemeTo method.

Step 1: Create a Document object and load a sample Word file.

Document doc = new Document();
doc.LoadFromFile("theme.docx");

Step 2: Create a new Word document.

Document newWord = new Document();

Step 3: Clone default style, theme, compatibility from the source file to destination document.

doc.CloneDefaultStyleTo(newWord);
doc.CloneThemesTo(newWord);
doc.CloneCompatibilityTo(newWord);

Step 4: Add the cloned section to destination document.

newWord.Sections.Add(doc.Sections[0].Clone());

Step 5: Save the file.

newWord.SaveToFile("result.docx", FileFormat.Docx);

Output:

Preserve Theme When Copying Sections from One Word Document to Another in C#

Full Code:

using Spire.Doc;
namespace PreserveTheme
{
    class Program
    {

        static void Main(string[] args)
        {
            Document doc = new Document();
            doc.LoadFromFile("theme.docx");

            Document newWord = new Document();
            doc.CloneDefaultStyleTo(newWord);
            doc.CloneThemesTo(newWord);
            doc.CloneCompatibilityTo(newWord);
            newWord.Sections.Add(doc.Sections[0].Clone());

            newWord.SaveToFile("result.docx", FileFormat.Docx);

        }
    }
}

We have already shown how to use Spire.Presentation to create the bubble chart in C# on the PowerPoint document. This article will demonstrate how to scale the size of bubble chart on the presentation slides in C#. We will use a 3-D bubble chart for example.

Step 1: Create a Presentation instance and load a sample document from the file.

Presentation ppt = new Presentation();
ppt.LoadFromFile("Sample.pptx", FileFormat.Pptx2010);

Step 2: Get the chart from the first presentation slide.

IChart chart = ppt.Slides[0].Shapes[0] as IChart;

Step 3: Scale the bubble size, the range value is from 0 to 300.

chart.BubbleScale = 50;

Step 4: Save the document to file.

ppt.SaveToFile("Scalesize.pptx", FileFormat.Pptx2010);

Effective screenshot of scale the bubble size:

C# Scale the size of bubble chart on the presentation slides

Full codes:

using Spire.Presentation;
using Spire.Presentation.Charts;

namespace ScaleSize
{
    class Program
    {
        static void Main(string[] args)
        {
            Presentation ppt = new Presentation();
            ppt.LoadFromFile("Sample.pptx", FileFormat.Pptx2010);
            IChart chart = ppt.Slides[0].Shapes[0] as IChart;
            chart.BubbleScale = 50;
            ppt.SaveToFile("Scalesize.pptx", FileFormat.Pptx2010);
        }
    }
}

Spire.PDF provides developers two methods to detect if a PDF file is PDF/A. The one is to use PdfDocument.Conformance property, the other is to use PdfDocument.XmpMetaData property. The following examples demonstrate how we can detect if a PDF file is PDF/A using these two methods.

Below is the screenshot of the sample file we used for demonstration:

Detect if a PDF file is PDF/A in C#

Using PdfDocument.Conformance

using Spire.Pdf;
using System;

namespace Detect
{
    class Program
    {
        static void Main(string[] args)
        {
            //Initialize a PdfDocument object 
            PdfDocument pdf = new PdfDocument();
            //Load the PDF file
            pdf.LoadFromFile("Example.pdf");

            //Get the conformance level of the PDF file            
            PdfConformanceLevel conformance = pdf.Conformance;
            Console.WriteLine("This PDF file is " + conformance.ToString());
        }
    }
}

Output:

Detect if a PDF file is PDF/A in C#

With linked images, you can direct users to a URL when they click the image. This article will show you how to create image hyperlinks in a Word document by using Spire.Doc.

Step 1: Create a Word document, add a section and a paragraph.

Document doc = new Document();
Section section = doc.AddSection();
Paragraph paragraph = section.AddParagraph();

Step 2: Load an image to a DocPicture object.

DocPicture picture = new DocPicture(doc);
picture.LoadImage(Image.FromFile("logo.png"));

Step 3: Add an image hyperlink to the paragraph.

paragraph.AppendHyperlink("www.e-iceblue.com", picture, HyperlinkType.WebLink);

Step 4: Save the file.

doc.SaveToFile("output.docx", FileFormat.Docx);

Output:

Create an Image Hyperlink in Word in C#, VB.NET

Full Code:

[C#]
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System.Drawing;
namespace CreateLink
{
    class Program
    {

        static void Main(string[] args)
        {

            Document doc = new Document();
            Section section = doc.AddSection();

            Paragraph paragraph = section.AddParagraph();
            Image image = Image.FromFile("logo.png");
            DocPicture picture = new DocPicture(doc);
            picture.LoadImage(image);
            paragraph.AppendHyperlink("www.e-iceblue.com", picture, HyperlinkType.WebLink);

            doc.SaveToFile("output.docx", FileFormat.Docx);
        }
    }
}
[VB.NET]
Imports Spire.Doc
Imports Spire.Doc.Documents
Imports Spire.Doc.Fields
Imports System.Drawing
Namespace CreateLink
	Class Program

		Private Shared Sub Main(args As String())

			Dim doc As New Document()
			Dim section As Section = doc.AddSection()

			Dim paragraph As Paragraph = section.AddParagraph()
			Dim image__1 As Image = Image.FromFile("logo.png")
			Dim picture As New DocPicture(doc)
			picture.LoadImage(image__1)
			paragraph.AppendHyperlink("www.e-iceblue.com", picture, HyperlinkType.WebLink)

			doc.SaveToFile("output.docx", FileFormat.Docx)
		End Sub
	End Class
End Namespace

Get Text within a Bookmark in C#, VB.NET

2018-01-03 08:44:50 Written by Koohji

Spire.Doc supports to retrieve, replace and delete bookmark content of a specified bookmark. This article will show you how we can get the plain text within a bookmark by using Spire.Doc with C# and VB.NET.

Step 1: Create a Document instance, and load a sample Word document.

Document doc = new Document();
doc.LoadFromFile("Bookmark.docx");

Step 2: Creates a BookmarkNavigator instance to access the bookmark.

BookmarksNavigator navigator = new BookmarksNavigator(doc);

Step 3: Locate a specific bookmark by bookmark name. Call the method GetBookmarkContent to get content within the bookmark.

navigator.MoveToBookmark("bookmark_1");
TextBodyPart textBodyPart = navigator.GetBookmarkContent();

Step 4: Iterate through the items in the bookmark content to get the plain, unformatted text of the bookmark.

string text = null;
foreach (var item in textBodyPart.BodyItems)
{
    if (item is Paragraph)
    {
        foreach (var childObject in (item as Paragraph).ChildObjects)
        {
            if (childObject is TextRange)
            {
                text += (childObject as TextRange).Text;
            }
        }
    }
}

Result:

Get Text within a Bookmark in C#, VB.NET

Full Code:

[C#]
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System;
namespace GetText
{
    class Program
    {

        static void Main(string[] args)
        {

            Document doc = new Document();
            doc.LoadFromFile("Bookmark.docx");

            BookmarksNavigator navigator = new BookmarksNavigator(doc);
            navigator.MoveToBookmark("bookmark_1");
            TextBodyPart textBodyPart = navigator.GetBookmarkContent();

            string text = null;
            foreach (var item in textBodyPart.BodyItems)
            {
                if (item is Paragraph)
                {
                    foreach (var childObject in (item as Paragraph).ChildObjects)
                    {
                        if (childObject is TextRange)
                        {
                            text += (childObject as TextRange).Text;
                        }
                    }
                }
            }
            Console.WriteLine(text);
        }
    }
}
[VB.NET]
Imports Spire.Doc
Imports Spire.Doc.Documents
Imports Spire.Doc.Fields
Namespace GetText
	Class Program

		Private Shared Sub Main(args As String())

			Dim doc As New Document()
			doc.LoadFromFile("Bookmark.docx")

			Dim navigator As New BookmarksNavigator(doc)
			navigator.MoveToBookmark("bookmark_1")
			Dim textBodyPart As TextBodyPart = navigator.GetBookmarkContent()

			Dim text As String = Nothing
			For Each item As var In textBodyPart.BodyItems
				If TypeOf item Is Paragraph Then
					For Each childObject As var In TryCast(item, Paragraph).ChildObjects
						If TypeOf childObject Is TextRange Then
							text += TryCast(childObject, TextRange).Text
						End If
					Next
				End If
			Next
			Console.WriteLine(text)
		End Sub
	End Class
End Namespace

With the help of Spire.Presentation, we can easily set the border type and color of a whole table on the presentation slides. This article will focus on demonstrating how to set the border for the table in C#.

Firstly, view the 12 border types for the table on PowerPoint file:

Set the border type and color for the table on Presentation slides

How to set the border type and color for an existing table on presentation slide:

//create a presentation document and load the file from disk
Presentation presentation = new Presentation();
presentation.LoadFromFile("Sample.pptx");

//get the table from the first slide of the sample document
ISlide slide = presentation.Slides[0];
ITable table = slide.Shapes[1] as ITable;
     
//set the border type as Inside and the border color as blue
table.SetTableBorder(TableBorderType.Inside, 1, Color.Blue);

//save the document to file
presentation.SaveToFile("Insideborder.pptx", FileFormat.Pptx2010);

Effective screenshot after set the border type for an existing table on presentation slide:

Set the border type and color for the table on Presentation slides

How to set the border type and color for newly added tables on presentation slide:

using Spire.Presentation;
using System;

namespace Set_border_type_and_color
{

    class Program
    {
        static void Main(string[] args)
        {

            //create a presentation document 
            Presentation presentation = new Presentation();

            //set the table width and height for each table cell
            double[] tableWidth = new double[] { 100, 100, 100, 100, 100 };
            double[] tableHeight = new double[] { 20, 20 };

            //traverse all the border type of the table
            foreach (TableBorderType item in Enum.GetValues(typeof(TableBorderType)))

            //add a table to the presentation slide with the setting width and height
            {
                ITable itable = presentation.Slides.Append().Shapes.AppendTable(100, 100, tableWidth, tableHeight);

                //add some text to the table cell
                itable.TableRows[0][0].TextFrame.Text = "Row";
                itable.TableRows[1][0].TextFrame.Text = "Column";

                //set the border type, border width and the border color for the table
                itable.SetTableBorder(item, 1.5, Color.Red);

            }

            //save the document to file
            presentation.SaveToFile("Addtablewithborder.pptx", FileFormat.Pptx2010);

        }
    }
}

Set the border type and color for the table on Presentation slides

Programmers may need to determine the style name of a section of text, or find the text in a document that appear in a specified style name, such as “Heading 1”. This article will show you how to retrieve style names that are applied in a Word document by using Spire.Doc with C# and VB.NET.

Step 1: Create a Document instance.

Document doc = new Document();

Step 2: Load a sample Word file.

doc.LoadFromFile("Sample.docx");

Step 3: Traverse all TextRanges in the document and get their style names through StyleName property.

foreach (Section section in doc.Sections)
{
    foreach (Paragraph paragraph in section.Paragraphs)
    {
        foreach (DocumentObject docObject in paragraph.ChildObjects)
        {
            if (docObject.DocumentObjectType == DocumentObjectType.TextRange)
            {
                TextRange text = docObject as TextRange;
                Console.WriteLine(text.StyleName);
            }                   
        }
    }                
}

Result:

Retrieve Style Names of all TextRanges in a Word Document in C#, VB.NET

Full Code:

[C#]
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System;
using System.Text.RegularExpressions;
namespace RetrieveStyleNames
{
    class Program
    {
        static void Main(string[] args)
        {
            Document doc = new Document();
            doc.LoadFromFile("Sample.docx");

            foreach (Section section in doc.Sections)
            {
                foreach (Paragraph paragraph in section.Paragraphs)
                {
                    foreach (DocumentObject docObject in paragraph.ChildObjects)
                    {
                        if (docObject.DocumentObjectType == DocumentObjectType.TextRange)
                        {
                            TextRange text = docObject as TextRange;
                            Console.WriteLine(text.StyleName);
                        }
                    }
                    Console.WriteLine();
                }
            }
        }
    }
}
[VB.NET]
Imports Spire.Doc
Imports Spire.Doc.Documents
Imports Spire.Doc.Fields
Imports System.Text.RegularExpressions
Namespace RetrieveStyleNames
	Class Program
		Private Shared Sub Main(args As String())
			Dim doc As New Document()
			doc.LoadFromFile("Sample.docx")

			For Each section As Section In doc.Sections
				For Each paragraph As Paragraph In section.Paragraphs
					For Each docObject As DocumentObject In paragraph.ChildObjects
						If docObject.DocumentObjectType = DocumentObjectType.TextRange Then
							Dim text As TextRange = TryCast(docObject, TextRange)
							Console.WriteLine(text.StyleName)
						End If
					Next
					Console.WriteLine()
				Next
			Next
		End Sub
	End Class
End Namespace

We have already demonstrated whether to display the additional information for presentation slides on header and footer area, such as hide or display date and time, the slide number, and the footer with the help of Spire.Presentation. This article will show you how to reset the position of the slide number and the date time in C#. We will also demonstrate how to reset the display format for the date and time from MM/dd/yyyy to yy.MM.yyyy on the presentation slides.

Firstly, view the default position of the date time at the left and the slide number at the right.

How to reset the position of the date time and slide number for the presentation slides

Step 1: Create a presentation document and load the file from disk.

Presentation presentation = new Presentation();
presentation.LoadFromFile("Sample.pptx", FileFormat.Pptx2013);

Step 2: Get the first slide from the sample document.

ISlide slide = presentation.Slides[0];

Step 3: Reset the position of the slide number to the left and date time to the center, and reset the date time display style.

foreach (IShape shapeToMove in slide.Shapes)
{
    if (shapeToMove.Name.Contains("Slide Number Placeholder"))
    {
        shapeToMove.Left =0;                                                  
     }

    else if (shapeToMove.Name.Contains("Date Placeholder"))
    {
        shapeToMove.Left = presentation.SlideSize.Size.Width / 2;
       
        (shapeToMove as IAutoShape).TextFrame.TextRange.Paragraph.Text = DateTime.Now.ToString("dd.MM.yyyy");
        (shapeToMove as IAutoShape).TextFrame.IsCentered = true;
    }
}

Step 4: Save the document to file.

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

Effective screenshot after reset the position and the format for the date time and slide number.

How to reset the position of the date time and slide number for the presentation slides

Full codes of how to reset the position of slide number and date time:

using Spire.Presentation;
using System;
namespace ResetPosition
{

    class Program
    {

        static void Main(string[] args)
        {
            Presentation presentation = new Presentation();

            presentation.LoadFromFile("Sample.pptx", Spire.Presentation.FileFormat.Pptx2013);

            ISlide slide = presentation.Slides[0];

            foreach (IShape shapeToMove in slide.Shapes)
            {
                if (shapeToMove.Name.Contains("Slide Number Placeholder"))
                {
                    shapeToMove.Left = 0;

                }

                else if (shapeToMove.Name.Contains("Date Placeholder"))
                {
                    shapeToMove.Left = presentation.SlideSize.Size.Width / 2;

                    (shapeToMove as IAutoShape).TextFrame.TextRange.Paragraph.Text = DateTime.Now.ToString("dd.MM.yyyy");
                    (shapeToMove as IAutoShape).TextFrame.IsCentered = true;
                }

            }
            presentation.SaveToFile("Result.pptx", Spire.Presentation.FileFormat.Pptx2013);

        }
    }
}
page 19