Error bars in charts can help us to see margins of error and standard deviations at a glance. We can use error bars in area, bar, column, line, and XY charts. In XY charts i.e. scatter and bubble charts, we can show X (Horizontal) and Y (Vertical) error bars. However if the chart type is not XY, the error bars for X values are disabled.

This article demonstrates how to add and format error bars for non-XY and XY charts in a PowerPoint document using Spire.Presentation and C#.

Detail steps:

Step 1: Initialize an object of Presentation class and load the PowerPoint document.

Presentation ppt = new Presentation();
ppt.LoadFromFile("Input.pptx");

Step 2: Get the column chart on the first slide and set chart title.

IChart columnChart = ppt.Slides[0].Shapes[0] as IChart;
columnChart.ChartTitle.TextProperties.Text = "Vertical Error Bars";

Step 3: Add Y (Vertical) error bars to the first chart series and format the error bars.

//Get Y error bars of the first chart series
IErrorBarsFormat errorBarsYFormat1 = columnChart.Series[0].ErrorBarsYFormat;
//Set end cap
errorBarsYFormat1.ErrorBarNoEndCap = false;
//Specify direction
errorBarsYFormat1.ErrorBarSimType = ErrorBarSimpleType.Plus;
//Specify error amount type
errorBarsYFormat1.ErrorBarvType = ErrorValueType.StandardError;
//Set value
errorBarsYFormat1.ErrorBarVal = 0.3f;            
//Set line format          
errorBarsYFormat1.Line.FillType = FillFormatType.Solid;
errorBarsYFormat1.Line.SolidFillColor.Color = Color.MediumVioletRed;
errorBarsYFormat1.Line.Width = 1;

Step 4: Get the bubble chart on the second slide and set chart title.

IChart chart2 = ppt.Slides[1].Shapes[0] as IChart;
chart2.ChartTitle.TextProperties.Text = "Vertical and Horizontal Error Bars";

Step 5: Add x (Horizontal) and Y (Vertical) error bars to the first chart series and format the error bars.

//Get X error bars of the first chart series
IErrorBarsFormat errorBarsXFormat = bubbleChart.Series[0].ErrorBarsXFormat;
//Set end cap
errorBarsXFormat.ErrorBarNoEndCap = false;
//Specify direction
errorBarsXFormat.ErrorBarSimType = ErrorBarSimpleType.Both;

//Specify error amount type
errorBarsXFormat.ErrorBarvType = ErrorValueType.StandardError;
//Set value
errorBarsXFormat.ErrorBarVal = 0.3f;
            
//Get Y error bars of the first chart series
IErrorBarsFormat errorBarsYFormat2 = bubbleChart.Series[0].ErrorBarsYFormat;
//Set end cap
errorBarsYFormat2.ErrorBarNoEndCap = false;
//Specify direction
errorBarsYFormat2.ErrorBarSimType = ErrorBarSimpleType.Both;
//Specify error amount type
errorBarsYFormat2.ErrorBarvType = ErrorValueType.StandardError;
//Set value
errorBarsYFormat2.ErrorBarVal = 0.3f;

Step 6: Save the document.

ppt.SaveToFile("ErrorBars.pptx", FileFormat.Pptx2013);

Screenshot:

Add and Format Error Bars in PowerPoint Charts in C#

Add and Format Error Bars in PowerPoint Charts in C#

Full code:

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

namespace Add_error_bars_to_chart_in_PPT
{
    class Program
    {
        static void Main(string[] args)
        {
            //Load the PowerPoint document
            Presentation ppt = new Presentation();
            ppt.LoadFromFile("Input.pptx");

            //Get the column chart on the first slide and set chart title
            IChart columnChart = ppt.Slides[0].Shapes[0] as IChart;
            columnChart.ChartTitle.TextProperties.Text = "Vertical Error Bars";

            //Add Y (Vertical) Error Bars

            //Get Y error bars of the first chart series
            IErrorBarsFormat errorBarsYFormat1 = columnChart.Series[0].ErrorBarsYFormat;
            //Set end cap
            errorBarsYFormat1.ErrorBarNoEndCap = false;
            //Specify direction
            errorBarsYFormat1.ErrorBarSimType = ErrorBarSimpleType.Plus;
            //Specify error amount type
            errorBarsYFormat1.ErrorBarvType = ErrorValueType.StandardError;
            //Set value
            errorBarsYFormat1.ErrorBarVal = 0.3f;            
            //Set line format          
            errorBarsYFormat1.Line.FillType = FillFormatType.Solid;
            errorBarsYFormat1.Line.SolidFillColor.Color = Color.MediumVioletRed;
            errorBarsYFormat1.Line.Width = 1;

            //Get the bubble chart on the second slide and set chart title
            IChart bubbleChart = ppt.Slides[1].Shapes[0] as IChart;
            bubbleChart.ChartTitle.TextProperties.Text = "Vertical and Horizontal Error Bars";

            //Add X (Horizontal) and Y (Vertical) Error Bars

            //Get X error bars of the first chart series
            IErrorBarsFormat errorBarsXFormat = bubbleChart.Series[0].ErrorBarsXFormat;
            //Set end cap
            errorBarsXFormat.ErrorBarNoEndCap = false;
            //Specify direction
            errorBarsXFormat.ErrorBarSimType = ErrorBarSimpleType.Both;
            //Specify error amount type
            errorBarsXFormat.ErrorBarvType = ErrorValueType.StandardError;
            //Set value
            errorBarsXFormat.ErrorBarVal = 0.3f;
            
            //Get Y error bars of the first chart series
            IErrorBarsFormat errorBarsYFormat2 = bubbleChart.Series[0].ErrorBarsYFormat;
            //Set end cap
            errorBarsYFormat2.ErrorBarNoEndCap = false;
            //Specify direction
            errorBarsYFormat2.ErrorBarSimType = ErrorBarSimpleType.Both;
            //Specify error amount type
            errorBarsYFormat2.ErrorBarvType = ErrorValueType.StandardError;
            //Set value
            errorBarsYFormat2.ErrorBarVal = 0.3f;
                        
            //Save the document
            ppt.SaveToFile("ErrorBars.pptx", FileFormat.Pptx2013);
        }
    }
}

Spire.Presentation supports to operate the paragraph styles from code. There are two kinds of special indentation styles for the paragraph, first line and hanging. This article will demonstrate how to set the indent style for the paragraph on presentation slide in C#.

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

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

Step 2: Get the paragraphs from the first slide.

IAutoShape shape = (IAutoShape)presentation.Slides[0].Shapes[0];
ParagraphCollection paras = shape.TextFrame.Paragraphs;

Step 3: Set the indentation as first line for the first paragraph.

paras[0].Indent = 20;
paras[0].SpaceAfter = 10;

Step 4: Set the indentation as Hanging for the third paragraph.

paras[2].Indent = -100;
paras[2].LeftMargin = 30;

Step 5: Save the document to file.

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

Effective screenshot of the presentation with indentation style:

How to set the indent style for the paragraph on presentation slide in C#

Full codes:

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

IAutoShape shape = (IAutoShape)presentation.Slides[0].Shapes[0];
ParagraphCollection paras = shape.TextFrame.Paragraphs;

paras[0].Indent = 20;
paras[0].SpaceAfter = 10;

paras[2].Indent = -100;
paras[2].LeftMargin = 30;

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

A file with the .ODT file extension is an OpenDocument Text document file. These files are most often created by the free OpenOffice Writer word processor program. ODT files are similar to the popular DOCX file format used with Microsoft Word. Both of the two file types can hold things like text, images, objects, and styles.

However, when you open an ODT document in Microsoft Word, the formatting of the ODT document may differ as a result of the two programs not sharing the same features. When converting ODT to DOCX or vice versa, the data and content will be converted successfully, but may not including the original formatting.

Following code snippets introduce how to convert ODT to DOC or DOCX and vice versa using Spire.Doc.

ODT to DOCX

To convert ODT to DOC, change the file extension and file format to .Doc in SaveToFile method.

[C#]
Document doc = new Document();
doc.LoadFromFile("SampleODTFile.odt");
doc.SaveToFile("output.docx", FileFormat.Docx);
[VB.NET]
Document doc = New Document()
doc.LoadFromFile("SampleODTFile.odt")
doc.SaveToFile("output.docx", FileFormat.Docx)

DOCX to ODT

To convert Doc to ODT, load a .Doc file format document when loading the source file.

[C#]
Document doc = new Document();
doc.LoadFromFile("SampleWordFile.docx");
doc.SaveToFile("output.odt", FileFormat.Odt);
[VB.NET]
Document doc = New Document()
doc.LoadFromFile("SampleWordFile.docx")
doc.SaveToFile("output.odt", FileFormat.Odt)
Thursday, 25 January 2018 06:25

Create Scatter Chart in PowerPoint in C#

A Scatter (X Y) Chart has two value axes – X value axis and Y value axis. It combines X and Y values into single data points and shows them in irregular intervals, or clusters. This article will show you how to create scatter chart in PowerPoint using Spire.Presentation with C#.

Step 1: Create a Presentation object.

Presentation presentation = new Presentation();

Step 2: Add a "Scatter with Smooth Lines and Markers" chart to the first slide, and set the chart title.

IChart chart = presentation.Slides[0].Shapes.AppendChart(ChartType.ScatterSmoothLinesAndMarkers, new RectangleF(40, 80, 550, 320), false);
chart.ChartTitle.TextProperties.Text = "Scatter Chart";
chart.ChartTitle.TextProperties.IsCentered = true;
chart.ChartTitle.Height = 20;
chart.HasTitle = true;

Step 3: Write data to the chart data.

Double[] xdata = new Double[] { 1.0, 2.4, 5.0, 8.9 };
Double[] ydata = new Double[] { 5.3, 15.2, 6.7, 8 };
chart.ChartData[0, 0].Text = "X-Values";
chart.ChartData[0, 1].Text = "Y-Values";
for (Int32 i = 0; i < xdata.Length; ++i)
{
    chart.ChartData[i + 1, 0].Value = xdata[i];
    chart.ChartData[i + 1, 1].Value = ydata[i];
}

Step 4: Set up the data source of the X values, the Y values, and the series label.

chart.Series.SeriesLabel = chart.ChartData["B1", "B1"];
chart.Series[0].XValues= chart.ChartData["A2", "A5"];
chart.Series[0].YValues = chart.ChartData["B2", "B5"];

Step 5: Add and display the data labels in the chart.

for (int i = 0; i < 4; i++)
{
    ChartDataLabel dataLabel = chart.Series[0].DataLabels.Add();
    dataLabel.LabelValueVisible = true;
}

Step 6: Set the axis titles.

chart.PrimaryValueAxis.HasTitle = true;
chart.PrimaryValueAxis.Title.TextProperties.Text = "X-Axis Title";
chart.SecondaryValueAxis.HasTitle = true;
chart.SecondaryValueAxis.Title.TextProperties.Text = "Y-Axis Title";

Step 7: Format the gridlines.

chart.SecondaryValueAxis.MajorGridTextLines.FillType = FillFormatType.Solid;
chart.SecondaryValueAxis.MajorGridTextLines.Style = TextLineStyle.ThinThin;
chart.SecondaryValueAxis.MajorGridTextLines.SolidFillColor.Color = Color.Gray;
chart.PrimaryValueAxis.MajorGridTextLines.FillType = FillFormatType.None;

Step 8: Format the outline.

chart.Series[0].Line.FillType = FillFormatType.Solid;
chart.Series[0].Line.Width = 0.1f;
chart.Series[0].Line.SolidFillColor.Color = Color.RoyalBlue;

Step 9: Save the file.

presentation.SaveToFile("ScatterChart.pptx", FileFormat.Pptx2010);

Output:

Create Scatter Chart in PowerPoint in C#

Full Code:

Presentation presentation = new Presentation();
IChart chart = presentation.Slides[0].Shapes.AppendChart(ChartType.ScatterSmoothLinesAndMarkers, new RectangleF(40, 80, 550, 320), false);
chart.ChartTitle.TextProperties.Text = "Scatter Chart";
chart.ChartTitle.TextProperties.IsCentered = true;
chart.ChartTitle.Height = 20;
chart.HasTitle = true;

Double[] xdata = new Double[] { 1.0, 2.4, 5.0, 8.9 };
Double[] ydata = new Double[] { 5.3, 15.2, 6.7, 8 };
chart.ChartData[0, 0].Text = "X-Values";
chart.ChartData[0, 1].Text = "Y-Values";
for (Int32 i = 0; i < xdata.Length; ++i)
{
    chart.ChartData[i + 1, 0].Value = xdata[i];
    chart.ChartData[i + 1, 1].Value = ydata[i];
}

chart.Series.SeriesLabel = chart.ChartData["B1", "B1"];
chart.Series[0].XValues= chart.ChartData["A2", "A5"];
chart.Series[0].YValues = chart.ChartData["B2", "B5"];

for (int i = 0; i < 4; i++)
{
    ChartDataLabel dataLabel = chart.Series[0].DataLabels.Add();
    dataLabel.LabelValueVisible = true;
}

chart.PrimaryValueAxis.HasTitle = true;
chart.PrimaryValueAxis.Title.TextProperties.Text = "X-Axis Title";
chart.SecondaryValueAxis.HasTitle = true;
chart.SecondaryValueAxis.Title.TextProperties.Text = "Y-Axis Title";

chart.SecondaryValueAxis.MajorGridTextLines.FillType = FillFormatType.Solid;
chart.SecondaryValueAxis.MajorGridTextLines.Style = TextLineStyle.ThinThin;
chart.SecondaryValueAxis.MajorGridTextLines.SolidFillColor.Color = Color.Gray;
chart.PrimaryValueAxis.MajorGridTextLines.FillType = FillFormatType.None;

chart.Series[0].Line.FillType = FillFormatType.Solid;
chart.Series[0].Line.Width = 0.1f;
chart.Series[0].Line.SolidFillColor.Color = Color.RoyalBlue;

presentation.SaveToFile("ScatterChart.pptx", FileFormat.Pptx2010);

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:

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:

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);
Tuesday, 16 January 2018 08:10

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

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

//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#

Using PdfDocument.XmpMetaData

//Initialize a PdfDocument object
PdfDocument pdf = new PdfDocument();
//Load the PDF file
pdf.LoadFromFile("Example.pdf");

//Get the XMP MetaData of the file
XmpMetadata xmpData = pdf.XmpMetaData;

//Get the XMP MetaData in XML format
XmlDocument xmlData = xmpData.XmlData;
string s = xmlData.InnerXml;
Console.WriteLine(s);

Output:

From the following output, we can see there is an XML tag named pdfaid:part and another XML tag named pdfaid:conformance. The PDF/A specification indicates that pdfaid:part references the PDF/A version identifier, and pdfaid:conformance references the PDF/A conformance level (A or B in case of PDF/A-1). In this example, the PDF/A version is 1 and the PDF/A conformance level is A. That is to say, this file is PDF/A-1a.

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

With Spire.PDF, programmers can extract text from a specific rectangular area within a PDF document. This article demonstrates how to implement this function using Spire.PDF and C#.

The sample file we used for demonstration:

Extract Text from a Specific Rectangular Area in PDF using C#

Detail steps:

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

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

Step 2: Get the first page.

PdfPageBase page = pdf.Pages[0];

Step 3: Extract text from a specific rectangular area within the page, after that save the text to a .txt file.

string text = page.ExtractText(new RectangleF(50, 50, 500, 100) );
StringBuilder sb = new StringBuilder();
sb.AppendLine(text);
File.WriteAllText("Extract.txt", sb.ToString());

Output:

Extract Text from a Specific Rectangular Area in PDF using C#

Full code:

//Initialize an object of PdfDocument class
PdfDocument pdf = new PdfDocument();
//Load the PDF file
pdf.LoadFromFile("Stories.pdf");

//Get the first page
PdfPageBase page = pdf.Pages[0];

// Extract text from a specific rectangular area within the page
string text = page.ExtractText(new RectangleF(50, 50, 500, 100) );

//Save the text to a .txt file
StringBuilder sb = new StringBuilder();
sb.AppendLine(text);
File.WriteAllText("Extract.txt", sb.ToString());
Page 8 of 97