page 244

When we create a PowerPoint slide that contains charts on it, we may not want others to change the chart data, especially when we create a presentation of financial report, it is very important for legal reasons that no changes get made when the slides are presented. In this article, I'll introduce how to protect chart on PowerPoint slide via Spire.Presentation in C# and VB.NET.

Test File:

How to Protect Chart on PowerPoint Slide in C#, VB.NET

Code Snippet:

Step 1: Create a new instance of Presentation class. Load the sample file to PPT document by calling LoadFromFile() method.

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

Step 2: Get the second shape from slide and convert it as IChart. The first shape in the sample file is a textbox.

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

Step 3: Set the Boolean value of IChart.IsDataProtect as true.

chart.IsDataProtect = true;

Step 4: Save the file.

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

Output:

Run this program and open the result file, you’ll get following warning message if you try to modify the chart data in Excel.

How to Protect Chart on PowerPoint Slide in C#, VB.NET

Full Code:

[C#]
using Spire.Presentation;
using Spire.Presentation.Charts;

namespace ProtectChart
{

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

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

            IChart chart = ppt.Slides[0].Shapes[1] as IChart;
            chart.IsDataProtect = true;
            ppt.SaveToFile("result.pptx", FileFormat.Pptx2010);


        }
    }
}
[VB.NET]
Imports Spire.Presentation
Imports Spire.Presentation.Charts

Namespace ProtectChart

	Class Program
		Private Shared Sub Main(args As String())

			Dim ppt As New Presentation()
			ppt.LoadFromFile("sample.pptx", FileFormat.Pptx2010)

			Dim chart As IChart = TryCast(ppt.Slides(0).Shapes(1), IChart)
			chart.IsDataProtect = True
			ppt.SaveToFile("result.pptx", FileFormat.Pptx2010)


		End Sub
	End Class
End Namespace

Now Spire.Doc support using uninstalled font when converting Doc to PDF to diversity text content. In this article, we'll talk about how to realize this function:

Step 1: Download a font uninstalled in system.

How to use uninstalled font when converting Doc to PDF via Spire.Doc

Step 2: Create a new blank Word document.

Document document = new Document();

Step 3: Add a section and create a new paragraph.

Section section = document.AddSection();
Paragraph paragraph = section.Paragraphs.Count > 0 ? section.Paragraphs[0] : section.AddParagraph();

Step 4: Append text for a txtRange.

TextRange txtRange = paragraph.AppendText(text);

Step 5: Create an example for class ToPdfParameterList named to pdf, and create a new PrivateFontPathlist for property PrivateFontPaths, instantiate one PrivateFontPath with name and path of downloaded font.

ToPdfParameterList toPdf = new ToPdfParameterList()
{
    PrivateFontPaths = new List()
        {
          new PrivateFontPath("DeeDeeFlowers",@"D:\DeeDeeFlowers.ttf")
        }
};

Step 6: Set the new font for the txtaRange.

txtRange.CharacterFormat.FontName = "DeeDeeFlowers";

Step 7: Convert the Doc to PDF.

document.SaveToFile("result.pdf", toPdf);

Step 8: Review converted PDF files.

System.Diagnostics.Process.Start("result.pdf");

Result screenshot:

How to use uninstalled font when converting Doc to PDF via Spire.Doc

Full Code Below:

Document document = new Document();
           
//Add the first secition
Section section = document.AddSection();
//Create a new paragraph and get the first paragraph
Paragraph paragraph
    = section.Paragraphs.Count > 0 ? section.Paragraphs[0] : section.AddParagraph();

//Append Text
String text
    = "This paragraph is demo of text font and color. "
    + "The font name of this paragraph is Tahoma. "
    + "The font size of this paragraph is 20. "
    + "The under line style of this paragraph is DotDot. "
    + "The color of this paragraph is Blue. ";
 TextRange txtRange = paragraph.AppendText(text);

//Import the font
 ToPdfParameterList toPdf = new ToPdfParameterList()
 {
     PrivateFontPaths = new List<PrivateFontPath>()
         {
          new PrivateFontPath("DeeDeeFlowers",@"D:\DeeDeeFlowers.ttf")
         }
};
//Make use of the font.
txtRange.CharacterFormat.FontName = "DeeDeeFlowers";

document.SaveToFile("result.pdf", toPdf);

System.Diagnostics.Process.Start("result.pdf");

To use different versions of PowerPoint document easier, Spire.Presentation enables to convert PowerPoint Presentation 97 – 2003 to PowerPoint Presentation 2007, 2010. Spire.Presentation supports to convert PPT to PPTX, from version 2.2.17, now it starts to load .pps format document and save to .ppsx format document in C#. This article will show you how to convert PPS to PPTX in C#.

Step 1: Create a presentation document.

Presentation presentation = new Presentation();

Step 2: Load the PPS file from disk.

presentation.LoadFromFile("sample.pps");

Step 3: Save the PPS document to PPTX file format.

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

Step 4: Launch and view the resulted PPTX file.

System.Diagnostics.Process.Start("ToPPTX.pptx");

Full codes:

C#
using Spire.Presentation;
namespace PPStoPPTX
{
    class Program
    {
        static void Main(string[] args)
        {
            Presentation presentation = new Presentation();

            //load the PPS file from disk
            presentation.LoadFromFile("sample.pps");

            //save the PPS document to PPTX file format
            presentation.SaveToFile("ToPPTX.pptx", FileFormat.Pptx2010);
            System.Diagnostics.Process.Start("ToPPTX.pptx");
        }
    }
}
VB.NET
Imports Spire.Presentation
Namespace PPStoPPTX
	Class Program
		Private Shared Sub Main(args As String())
			Dim presentation As New Presentation()

			'load the PPS file from disk
			presentation.LoadFromFile("sample.pps")

			'save the PPS document to PPTX file format
			presentation.SaveToFile("ToPPTX.pptx", FileFormat.Pptx2010)
			System.Diagnostics.Process.Start("ToPPTX.pptx")
		End Sub
	End Class
End Namespace

The result PPTX document:

How to convert PPS document to PPTX in C#

page 244