Spire.XLS enables developers to change the color of data series in an Excel chart with just a few lines of code. Once changed, the legend color will also turn into the same as the color you set to the series.

The following part demonstrates the steps of how to accomplish this task. Below picture shows the original colors of the data series in an Excel chart:

How to change the color of data series in an Excel chart

Code snippets:

Step 1: Instantiate a Workbook object and load the Excel workbook.

Workbook book = new Workbook();
book.LoadFromFile("Sample.xlsx");

Step 2: Get the first worksheet.

Worksheet sheet = book.Worksheets[0];

Step 3: Get the second series of the chart.

ChartSerie cs = sheet.Charts[0].Series[1];

Step 4: Change the color of the second series to Purple.

cs.Format.Fill.FillType = ShapeFillType.SolidColor;
cs.Format.Fill.ForeColor = Color.FromKnownColor(KnownColor.Purple);

Step 5: Save the Excel workbook to file.

book.SaveToFile("ChangeSeriesColor.xlsx", ExcelVersion.Version2010);

After running the code, the color of the second series has been changed into Purple, screenshot as shown below.

How to change the color of data series in an Excel chart

Full code:

[C#]
using System.Drawing;
using Spire.Xls;
using Spire.Xls.Charts;

namespace Change_Series_Color
{
    class Program
    {
        static void Main(string[] args)
        {
            Workbook book = new Workbook();
            book.LoadFromFile("Sample.xlsx");
            Worksheet sheet = book.Worksheets[0];
            ChartSerie cs = sheet.Charts[0].Series[1];
            cs.Format.Fill.FillType = ShapeFillType.SolidColor;
            cs.Format.Fill.ForeColor = Color.FromKnownColor(KnownColor.Purple);
            book.SaveToFile("ChangeSeriesColor.xlsx", ExcelVersion.Version2010);
        }
    }
}
[VB.NET]
Imports System.Drawing
Imports Spire.Xls
Imports Spire.Xls.Charts

Namespace Change_Series_Color
	Class Program
		Private Shared Sub Main(args As String())
			Dim book As New Workbook()
			book.LoadFromFile("Sample.xlsx")
			Dim sheet As Worksheet = book.Worksheets(0)
			Dim cs As ChartSerie = sheet.Charts(0).Series(1)
			cs.Format.Fill.FillType = ShapeFillType.SolidColor
			cs.Format.Fill.ForeColor = Color.FromKnownColor(KnownColor.Purple)
			book.SaveToFile("ChangeSeriesColor.xlsx", ExcelVersion.Version2010)
		End Sub
	End Class
End Namespace

Browsed at a kiosk (full screen) is one kind of the slide show types in PowerPoint, if users choose this option, the Slide Show is full screen but they cannot navigate from slide to slide, for example, move to the next or previous slides.

The following part will demonstrate how to set the presentation show type as kiosk in C# and VB.NET using Spire.Presentation.

Detail steps:

Step 1: Instantiate a Presentation object and load the PPT file.

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

Step 2: Specify the presentation show type as kiosk.

presentation.ShowType = SlideShowType.Kiosk;

Step 3: Save the file.

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

Output:

How to set the presentation show type as kiosk (full screen) in C#, VB.NET

Full code:

[C#]
using Spire.Presentation;

namespace Set_Presentation_show_type_as_ kiosk
{
    class Program
    {
        static void Main(string[] args)
        {
            Presentation presentation = new Presentation();
            presentation.LoadFromFile("Sample.pptx");
            presentation.ShowType = SlideShowType.Kiosk;
            presentation.SaveToFile("Result.pptx", FileFormat.Pptx2013);
        }
    }
}
[VB.NET]
Imports Spire.Presentation

Namespace Set_Presentation_show_type_as_ kiosk
	Class Program
		Private Shared Sub Main(args As String())
			Dim presentation As New Presentation()
			presentation.LoadFromFile("Sample.pptx")
			presentation.ShowType = SlideShowType.Kiosk
			presentation.SaveToFile("Result.pptx", FileFormat.Pptx2013)
		End Sub
	End Class
End Namespace

In charts, each category on the category axis is identified by a tick-mark label and separated from other categories by tick marks. The tick-mark label text comes from the name of the associated category and is usually placed next to the axis.

In this article, we will introduce how we can custom the tick-mark labels by changing the labels' position, rotating labels and specifying interval between labels in C#, VB.ENT.

Working with Tick-mark Labels on the Category Axis in C#, VB.NET

Figure 1 – Chart in Example File

To facilitate the introduction, we prepared a PowerPoint document that contains a column chart looks like the screenshot in Figure 1 and used below code to get the chart from the PowerPoint slide. Then we're able to custom the labels through the following ways.

Presentation ppt = new Presentation(@"C:\Users\Administrator\Desktop\ColumnChart.pptx",FileFormat.Pptx2013);
IChart chart = ppt.Slides[0].Shapes[0] as IChart;

Rotate tick labels

chart.PrimaryCategoryAxis.TextRotationAngle = 45;

Working with Tick-mark Labels on the Category Axis in C#, VB.NET

Specify interval between labels

To change the number of unlabeled tick marks, we must set IsAutomaticTickLabelSpacing property as false and change the TickLabelSpacing property to any number between 1 - 255.

chart.PrimaryCategoryAxis.IsAutomaticTickLabelSpacing = false;
chart.PrimaryCategoryAxis.TickLabelSpacing = 2;

Working with Tick-mark Labels on the Category Axis in C#, VB.NET

Change tick labels' position

chart.PrimaryCategoryAxis.TickLabelPosition = TickLabelPositionType.TickLabelPositionHigh;

Working with Tick-mark Labels on the Category Axis in C#, VB.NET

Full Code:

[C#]
Presentation ppt = new Presentation(@"C:\Users\Administrator\Desktop\ColumnChart.pptx",FileFormat.Pptx2013);
IChart chart = ppt.Slides[0].Shapes[0] as IChart;

//rotate tick labels
chart.PrimaryCategoryAxis.TextRotationAngle = 45;

//specify interval between labels
chart.PrimaryCategoryAxis.IsAutomaticTickLabelSpacing = false;
chart.PrimaryCategoryAxis.TickLabelSpacing = 2;

////change position
//chart.PrimaryCategoryAxis.TickLabelPosition = TickLabelPositionType.TickLabelPositionHigh;

ppt.SaveToFile("result.pptx", FileFormat.Pptx2013);
[VB.NET]
Dim ppt As New Presentation("C:\Users\Administrator\Desktop\ColumnChart.pptx", FileFormat.Pptx2013)
Dim chart As IChart = TryCast(ppt.Slides(0).Shapes(0), IChart)

'rotate tick labels
chart.PrimaryCategoryAxis.TextRotationAngle = 45

'specify interval between labels
chart.PrimaryCategoryAxis.IsAutomaticTickLabelSpacing = False
chart.PrimaryCategoryAxis.TickLabelSpacing = 2

'''/change position
'chart.PrimaryCategoryAxis.TickLabelPosition = TickLabelPositionType.TickLabelPositionHigh;

ppt.SaveToFile("result.pptx", FileFormat.Pptx2013)
Tuesday, 15 November 2016 07:43

How to change the image on button field in C#

We have already had an article of showing how to replace the image on the existing PDF file. Starts from Spire.PDF V3.8.45, it newly supports to update the image on button field via the method of field.SetButtonImage(PdfImage.FromFile(@"")). This article will focus on demonstrate how to replace the image on the button field in C#.

Firstly, check the original PDF file with the button field.

How to change the image on button field in C#

Step 1: Create a PDF document and load from file.

PdfDocument pdf = new PdfDocument();
pdf.LoadFromFile("Sample.PDF", FileFormat.PDF);

Step 2: Get the form from the loaded PDF document.

PdfFormWidget form = pdf.Form as PdfFormWidget;

Step 3: Find the button field named "Image" and then set a new image for this button field.

for (int i = 0; i < form.FieldsWidget.Count; i++)
{
    if (form.FieldsWidget[i] is PdfButtonWidgetFieldWidget)
    {
        PdfButtonWidgetFieldWidget field = form.FieldsWidget[i] as PdfButtonWidgetFieldWidget;
        if (field.Name == "Image")
        { field.SetButtonImage(PdfImage.FromFile("logo.png")); }
    }
}

Step 4: Save the document to file.

pdf.SaveToFile("result.pdf");

Effective screenshot after replace the image on the button field.

How to change the image on button field in C#

Full codes:

public ButtonField()
{
    PdfDocument pdf = new PdfDocument();
    pdf.LoadFromFile("Sample.PDF", FileFormat.PDF);

    PdfFormWidget form = pdf.Form as PdfFormWidget;

    for (int i = 0; i < form.FieldsWidget.Count; i++)
    {
        if (form.FieldsWidget[i] is PdfButtonWidgetFieldWidget)
        {
            PdfButtonWidgetFieldWidget field = form.FieldsWidget[i] as PdfButtonWidgetFieldWidget;
            if (field.Name == "Image")
            { field.SetButtonImage(PdfImage.FromFile("logo.png")); }

        }
    }

    pdf.SaveToFile("result.pdf");

}

Now Spire.Doc supports to embed private fonts from font files into Word document when save as .docx file format. This article will show you the detail steps of how to accomplish this task by using Spire.Doc.

For demonstration, we used a font file DeeDeeFlowers.ttf.

Embed private font into Word document when save as .docx file format

In the following part, we will embed font from above file into a Word document and use it to create text.

Step 1: Create a blank Word document.

Document document = new Document();

Step 2: Add a section and a paragraph to the document.

Section section = document.AddSection();
Paragraph p = section.AddParagraph();

Step 3: Append text to the paragraph, then set the font name and font size for the text.

TextRange range = p.AppendText("Let life be beautiful like summer flowers\n"
    +"Life, thin and light-off time and time again\n"
    + "Frivolous tireless");
range.CharacterFormat.FontName = "DeeDeeFlowers";
range.CharacterFormat.FontSize = 20;

Step 4: Allow embedding font in document by setting the Boolean value of EmbedFontsInFile property to true.

document.EmbedFontsInFile = true;

Step 5: Embed private font from font file into the document.

document.PrivateFontList.Add(new PrivateFontPath("DeeDeeFlowers", @"E:\Program Files\DeeDeeFlowers.ttf"));   

Step 6: Save as .docx file format.

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

After running the code, we'll get the following output:

Embed private font into Word document when save as .docx file format

Full code:

using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;

namespace Embed_private_font_into_Word
{
    class Program
    {
        static void Main(string[] args)
        {
            Document document = new Document();           
            Section section = document.AddSection();
            Paragraph p = section.AddParagraph();

            TextRange range = p.AppendText("Let life be beautiful like summer flowers\n"
                +"Life, thin and light-off time and time again\n"
                + "Frivolous tireless");
            range.CharacterFormat.FontName = "DeeDeeFlowers";
            range.CharacterFormat.FontSize = 20;

            document.EmbedFontsInFile = true;
            document.PrivateFontList.Add(new PrivateFontPath("DeeDeeFlowers", @"E:\Program Files\DeeDeeFlowers.ttf"));   

            document.SaveToFile("result.docx", FileFormat.Docx);
        }
    }
}
Tuesday, 08 November 2016 08:05

How to get text from word document in C#

Sometimes we only need to get the text from the word document for other use when we deal with the word documents with large amount of information. With the help of Spire.Doc, we have already demonstrated how to extract the text from the word document by traverse every paragraph on the word document and then append the text accordingly. This article will show you how to use the method of doc.GetText() to extract the text directly from the word documents with texts, images and tables. It is more convenient for developers to extract the text from the word document from code.

Firstly, view the sample word document which will be extracted the text firstly:

How to get text from word document in C#

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

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

Step 2: Invoke the doc.GetText() method to get all the texts from the word document.

string s = doc.GetText();

Step 3: Create a New TEXT File to Save Extracted Text.

File.WriteAllText("Extract.txt", s.ToString());

Effective screenshot after get all the text from the word document:

How to get text from word document in C#

Full codes:

class WordText
 {
   public GetText()
   {
     Document doc = new Document();
     doc.LoadFromFile("Sample.docx");

     string s = doc.GetText();

     File.WriteAllText("Extract.txt", s.ToString());

    }
 }

Spire.PDF provides an easy and straightforward method called FindText to find a particular text in a page of a PDF document. After the specified text is found, we’re able to acquire the coordinate information by the Position property. Follow sections presents how to get coordinates of desired text in PDF using Spire.PDF.

Code Snippets:

Step 1: Initialize an instance of PdfDocument class and load a sample PDF file.

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

Step 2: Declare a variable of an array whose array type is PdfTextFind class, which represents a result of searching text in a PDF page.

PdfTextFind[] results = null;

Step 3: Find all results of searched text “Spire.PDF” in the PDF document and store the results in PdfTextFind[]. Traversal the results to get the specified text and acquire its coordinate information by the Position property.

foreach (PdfPageBase page in doc.Pages)
{
    results = page.FindText("Spire.PDF").Finds;
    foreach (PdfTextFind text in results)
    {
        PointF p = text.Position;
        Console.WriteLine(p);
    }
}

Result:

How to Get Coordinates of Desired Text in PDF in C#, VB.NET

Full Code:

[C#]
PdfDocument doc = new PdfDocument();
doc.LoadFromFile(@"sample.pdf");

PdfTextFind[] results = null;
foreach (PdfPageBase page in doc.Pages)
{
    results = page.FindText("C#").Finds;
    foreach (PdfTextFind text in results)
    {
        PointF p = text.Position;
        Console.WriteLine(p);
    }
}
[VB.NET]
Dim doc As PdfDocument = New PdfDocument()
doc.LoadFromFile("sample.pdf")
 
Dim results() As PdfTextFind = Nothing
Dim page As PdfPageBase
For Each page In doc.Pages
    results = page.FindText("C#").Finds
    Dim text As PdfTextFind
    For Each text In results
        Dim p As PointF =  text.Position
        Console.WriteLine(p)
    Next
Next
Tuesday, 01 November 2016 08:10

How to get the font information of text in PDF

Spire.PDF provides a class named PdfDocument that represents a PDF file, this class contains a property named UsedFonts which allows us to access the fonts used in PDF file, and then we can get the font information such as name, size, type and style easily.

The following steps explain how to get the font information of text in PDF by using Spire.PDF.

Step 1: Instantiate an object of PdfDocument class and load the PDF file.

PdfDocument pdf = new PdfDocument();
pdf.LoadFromFile(@"E:\Program Files\Sample.pdf");

Step 2: Get the fonts that are used in the PDF file and put them into a PdfUsedFont array.

PdfUsedFont[] usedfont = pdf.UsedFonts;

Step 3: Loop through the array and print out the name, size, type and style of each font.

foreach (PdfUsedFont font in usedfont)
{
    Console.WriteLine("{0}, {1}, {2}, {3}", font.Name, font.Size, font.Type, font.Style);
}
Console.ReadKey();

Output:

How to get the font information of text in PDF

Full code:

[C#]
using System;
using Spire.Pdf;
using Spire.Pdf.Graphics.Fonts;

namespace Get_the_font_information_of_text_in_PDF
{
    class Program
    {
        static void Main(string[] args)
        {
            PdfDocument pdf = new PdfDocument();
            pdf.LoadFromFile(@"E:\Program Files\Sample.pdf");
            PdfUsedFont[] usedfont = pdf.UsedFonts;
            foreach (PdfUsedFont font in usedfont)
            {
                Console.WriteLine("{0}, {1}, {2}, {3}", font.Name, font.Size, font.Type, font.Style);
            }
            Console.ReadKey();
        }
    }
}
[VB.NET]
Imports Spire.Pdf
Imports Spire.Pdf.Graphics.Fonts

Namespace Get_the_font_information_of_text_in_PDF
	Class Program
		Private Shared Sub Main(args As String())
			Dim pdf As New PdfDocument()
			pdf.LoadFromFile("E:\Program Files\Sample.pdf")
			Dim usedfont As PdfUsedFont() = pdf.UsedFonts
			For Each font As PdfUsedFont In usedfont
				Console.WriteLine("{0}, {1}, {2}, {3}", font.Name, font.Size, font.Type, font.Style)
			Next
			Console.ReadKey()
		End Sub
	End Class
End Namespace
Tuesday, 01 November 2016 08:03

Add Oval shape to Excel Chart in C#

We have demonstrated how to insert textbox to Excel worksheet in C#. Starts from Spire.XLS v7.11.1, we have add a new method of chart.Shapes.AddOval(left,top,right,bottom); to enable developers to add oval shape to excel chart directly. Developers can also add the text contents to the oval shape and format the style for the oval. This article will describe clearly how to insert oval shape to Excel chart in C#.

Step 1: Create a workbook and get the first worksheet from the workbook.

Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];

Step 2: Add a chart to the worksheet.

Chart chart = sheet.Charts.Add();

Step 3: Add oval shape to Excel chart.

var shape = chart.Shapes.AddOval(20, 60, 500,400);

Step 4: Add the text to the oval shape and set the text alignment on the shape.

shape.Text = "Oval Shape added by Spire.XLS";
shape.HAlignment = CommentHAlignType.Center;
shape.VAlignment = CommentVAlignType.Center;

Step 5: Format the color for the oval shape.

((XlsOvalShape)shape).Line.ForeColor = Color.Blue;
((XlsOvalShape)shape).Fill.ForeColor = Color.Green;

Step 6: Save the document to file.

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

Effective screenshot of Oval shape added to the Excel chart:

Add Oval shape to Excel Chart in C#

Full codes:

static void Main(string[] args)
{
    Workbook workbook = new Workbook();

    Worksheet sheet = workbook.Worksheets[0];

    Chart chart = sheet.Charts.Add();
             
    var shape = chart.Shapes.AddOval(20, 60, 500,400);

    shape.Text = "Oval Shape added by Spire.XLS";

    shape.HAlignment = CommentHAlignType.Center;
    shape.VAlignment = CommentVAlignType.Center;

    ((XlsOvalShape)shape).Line.ForeColor = Color.Blue;
    ((XlsOvalShape)shape).Fill.ForeColor = Color.Green;
   
    workbook.SaveToFile("Result.xlsx",ExcelVersion.Version2010);
          
}

SVG, short for scalable vector graphics, is a XML-based file format used to depict two-dimensional vector graphics. As SVG images are defined in XML text lines, they can be easily searched, indexed, scripted, and supported by most of the up to date web browsers. Therefore, office documents are often converted to SGV images for high fidelity viewing. Following sections will introduce how to convert PowerPoint documents to SVG images using Spire.Presentation in C# and VB.NET.

Code Snippet:

Step 1: Initialize an instance of Presentation class and load a sample PowerPoint document to it.

Presentation ppt = new Presentation();
ppt.LoadFromFile(@"C:\Users\Administrator\Desktop\sample.pptx");

Step 2: Convert PowerPoint document to byte array and store in a Queue object.

Queue svgBytes = ppt.SaveToSVG();

Step 3: Initialize an instance of the FileStream class with the specified file path and creation mode. Dequeue the data in the Queue object and write to the stream.

int len = svgBytes.Count;
for (int i = 0; i < len; i++)
{
    FileStream fs = new FileStream(string.Format("result" + "{0}.svg", i), FileMode.Create);
    byte[] bytes = svgBytes.Dequeue();
    fs.Write(bytes, 0, bytes.Length);
}

Output:

How to Convert PowerPoint Document to SVG Images in C#, VB.NET

Full Code:

[C#]
Presentation ppt = new Presentation();
ppt.LoadFromFile(@"C:\Users\Administrator\Desktop\sample.pptx");
Queue svgBytes = ppt.SaveToSVG();
int len = svgBytes.Count;
for (int i = 0; i < len; i++)
{
    FileStream fs = new FileStream(string.Format("result" + "{0}.svg", i), FileMode.Create);
    byte[] bytes = svgBytes.Dequeue();
    fs.Write(bytes, 0, bytes.Length);
    ppt.Dispose();
}
[VB.NET]
Dim ppt As New Presentation()
ppt.LoadFromFile("C:\Users\Administrator\Desktop\sample.pptx")
Dim svgBytes As Queue(Of Byte()) = ppt.SaveToSVG()
Dim len As Integer = svgBytes.Count
For i As Integer = 0 To len - 1
	Dim fs As New FileStream(String.Format("result" + "{0}.svg", i), FileMode.Create)
	Dim bytes As Byte() = svgBytes.Dequeue()
	fs.Write(bytes, 0, bytes.Length)
	ppt.Dispose()
Next