.NET (1322)
Children categories
We often need to resize images to a desired size after we insert them into a Word document. This article demonstrates how to programmatically resize images in a Word document using Spire.Doc and C#.
Below is the screenshot of the example document we used for demonstration:

Detail steps:
Step 1: Load the Word document.
Document document = new Document("Input.docx");
Step 2: Get the first section and the first paragraph in the section.
Section section = document.Sections[0]; Paragraph paragraph = section.Paragraphs[0];
Step 3: Resize images in the paragraph.
foreach (DocumentObject docObj in paragraph.ChildObjects)
{
if (docObj is DocPicture)
{
DocPicture picture = docObj as DocPicture;
picture.Width = 50f;
picture.Height = 50f;
}
}
Step 4: Save the document.
document.SaveToFile("ResizeImages.docx");
Output:

Full code:
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
namespace Resize
{
class Program
{
static void Main(string[] args)
{
Document document = new Document("Input.docx");
Section section = document.Sections[0];
Paragraph paragraph = section.Paragraphs[0];
foreach (DocumentObject docObj in paragraph.ChildObjects)
{
if (docObj is DocPicture)
{
DocPicture picture = docObj as DocPicture;
picture.Width = 50f;
picture.Height = 50f;
}
}
document.SaveToFile("ResizeImages.docx");
}
}
}
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:


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);
}
}
}
How to set the indent style for the paragraph on presentation slide in C#
2018-01-30 07:45:45 Written by KoohjiSpire.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:

Full codes:
using Spire.Presentation;
using Spire.Presentation.Collections;
namespace SetIndentStyle
{
class Program
{
static void Main(string[] args)
{
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.
using Spire.Doc;
namespace ODTtoDOCX
{
class Program
{
static void Main(string[] args)
{
Document doc = new Document();
doc.LoadFromFile("SampleODTFile.odt");
doc.SaveToFile("output.docx", FileFormat.Docx)
}
}
}
Imports Spire.Doc
Namespace ODTtoDOCX
Class Program
Private Shared Sub Main(args As String())
Dim doc As New Document()
doc.LoadFromFile("SampleODTFile.odt")
doc.SaveToFile("output.docx", FileFormat.Docx)
End Sub
End Class
End Namespace
DOCX to ODT
To convert Doc to ODT, load a .Doc file format document when loading the source file.
using Spire.Doc;
namespace DOCXtoODT
{
class Program
{
static void Main(string[] args)
{
Document doc = new Document();
doc.LoadFromFile("SampleODTFile.odt");
doc.SaveToFile("output.docx", FileFormat.Docx);
}
}
}
Imports Spire.Doc
Namespace DOCXtoODT
Class Program
Private Shared Sub Main(args As String())
Dim doc As New Document()
doc.LoadFromFile("SampleODTFile.odt")
doc.SaveToFile("output.docx", FileFormat.Docx)
End Sub
End Class
End Namespace
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:

Full Code:
using Spire.Presentation;
using Spire.Presentation.Charts;
using Spire.Presentation.Drawing;
using System;
using System.Drawing;
namespace CreateScatterChart
{
class Program
{
static void Main(string[] args)
{
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);
}
}
}
C# Set animation effect for the animate text on the presentation slides
2018-01-24 08:24:09 Written by KoohjiWe 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".

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".


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();
}
}
}
Preserve Theme When Copying Sections from One Word Document to Another in C#
2018-01-19 08:04:49 Written by KoohjiA 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:

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:

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:

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:
