private void btnRun_Click(object sender, EventArgs e)
        {
            //create PPT document
            Presentation presentation = new Presentation();

            //set background Image
            string     ImageFile = @"..\..\..\..\..\..\Data\bg.png";
            RectangleF rect      = new RectangleF(0, 0, presentation.SlideSize.Size.Width, presentation.SlideSize.Size.Height);

            presentation.Slides[0].Shapes.AppendEmbedImage(ShapeType.Rectangle, ImageFile, rect);
            presentation.Slides[0].Shapes[0].Line.FillFormat.SolidFillColor.Color = Color.FloralWhite;

            //add title
            RectangleF rec_title   = new RectangleF(presentation.SlideSize.Size.Width / 2 - 200, 70, 400, 50);
            IAutoShape shape_title = presentation.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, rec_title);

            shape_title.ShapeStyle.LineColor.Color = Color.White;
            shape_title.Fill.FillType  = Spire.Presentation.Drawing.FillFormatType.None;
            shape_title.TextFrame.Text = "Spire.Presentation";
            TextParagraph para_title = shape_title.TextFrame.Paragraphs[0];

            para_title.Alignment = TextAlignmentType.Center;
            para_title.TextRanges[0].LatinFont  = new TextFont("Myriad Pro Light");
            para_title.TextRanges[0].FontHeight = 36;

            //add hyperlink to the shape
            ClickHyperlink hyperlink = new ClickHyperlink("http://www.e-iceblue.com/Introduce/presentation-for-net-introduce.html");

            shape_title.Click = hyperlink;
            shape_title.TextFrame.TextRange.ClickAction = hyperlink;

            //add new shape to PPT document
            RectangleF rec   = new RectangleF(presentation.SlideSize.Size.Width / 2 - 300, 155, 600, 300);
            IAutoShape shape = presentation.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, rec);

            shape.ShapeStyle.LineColor.Color = Color.White;
            shape.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.None;

            //add text to shape
            shape.AppendTextFrame("Spire.Presentation for .NET is a professional PowerPoint compatible component that enables developers to create, read, write, modify, convert and Print PowerPoint documents from any .NET(C#, VB.NET, ASP.NET) platform. As an independent PowerPoint .NET component, Spire.Presentation for .NET doesn't need Microsoft PowerPoint installed on the machine.");

            TextParagraph para = new TextParagraph();

            para.Text = "Spire.Presentation for .NET support PPT, PPS, PPTX and PPSX presentation formats. It provides functions such as managing text, image, shapes, tables, animations, audio and video on slides. It also support exporting presentation slides to EMF, JPG, TIFF, PDF format etc.";
            shape.TextFrame.Paragraphs.Append(para);

            //set the font and fill style of text
            foreach (TextParagraph paragraph in shape.TextFrame.Paragraphs)
            {
                paragraph.TextRanges[0].Fill.FillType         = Spire.Presentation.Drawing.FillFormatType.Solid;
                paragraph.TextRanges[0].Fill.SolidColor.Color = Color.Black;
                paragraph.TextRanges[0].FontHeight            = 20;
                paragraph.TextRanges[0].LatinFont             = new TextFont("Myriad Pro");
                paragraph.Alignment = TextAlignmentType.Left;
            }

            //set spacing after
            shape.TextFrame.Paragraphs[0].SpaceAfter = 80;

            //save the document
            presentation.SaveToFile("hyperlink.pptx", FileFormat.Pptx2010);
            System.Diagnostics.Process.Start("hyperlink.pptx");
        }
Exemple #2
0
        static void Main(string[] args)
        {
            Presentation ppt     = new Presentation();
            ISlide       slide   = ppt.Slides[0];
            SizeF        pptSize = ppt.SlideSize.Size;

            //Set background
            string     bgFile = "bg.jpg";
            RectangleF bgRect = new RectangleF(new PointF(0, 0), pptSize);

            slide.Shapes.AppendEmbedImage(ShapeType.Rectangle, bgFile, bgRect);

            //Add title
            RectangleF titleRect  = new RectangleF(pptSize.Width / 2 - 200, 10, 400, 50);
            IAutoShape titleShape = slide.Shapes.AppendShape(ShapeType.Rectangle, titleRect);

            titleShape.Fill.FillType = FillFormatType.None;
            titleShape.ShapeStyle.LineColor.Color = Color.Empty;
            TextParagraph titlePara = titleShape.TextFrame.Paragraphs[0];

            titlePara.Text = "Microsoft PowerPoint";
            titlePara.FirstTextRange.FontHeight            = 36;
            titlePara.FirstTextRange.Fill.FillType         = FillFormatType.Solid;
            titlePara.FirstTextRange.Fill.SolidColor.Color = Color.Black;
            titlePara.Alignment = TextAlignmentType.Center;

            //Insert Image
            string      logoFile = "logo.png";
            RectangleF  logoRect = new RectangleF(pptSize.Width / 2 - 40, 60, 80, 80);
            IEmbedImage image    = slide.Shapes.AppendEmbedImage(ShapeType.Rectangle, logoFile, logoRect);

            image.Line.FillType = FillFormatType.None;

            //Insert Table and apply built-in table style
            double[] widths  = { 160, 320 };
            double[] heights = { 15, 15, 15, 15, 15, 15, 15 };
            ITable   table   = slide.Shapes.AppendTable(pptSize.Width / 2 - 240, 150, widths, heights);

            string[,] data = new string[, ]
            {
                { "Developer(s)", "Microsoft" },
                { "Stable Release", "2013/10,2,2012; 2 years ago" },
                { "Written In", "C++" },
                { "Operation System", "Microsoft Windows" },
                { "Type", "Presentation Program" },
                { "License", "Trialware" },
                { "Website", "http://office.microsoft.com/powerpoint" }
            };
            for (int i = 0; i < 7; i++)
            {
                for (int j = 0; j < 2; j++)
                {
                    table[j, i].TextFrame.Text = data[i, j];
                }
            }
            table.StylePreset = TableStylePreset.LightStyle3Accent5;

            //Add hyperlink
            ClickHyperlink hyperlink = new ClickHyperlink("http://office.microsoft.com/powerpoint");

            table[1, 6].TextFrame.TextRange.ClickAction = hyperlink;

            //Add content
            RectangleF textRect  = new RectangleF(pptSize.Width / 2 - 240, 365, 480, 130);
            IAutoShape textShape = slide.Shapes.AppendShape(ShapeType.Rectangle, textRect);
            //Content format
            string text = File.ReadAllText("description.txt");

            textShape.AppendTextFrame(text);

            TextParagraph contentPara = textShape.TextFrame.Paragraphs[0];

            contentPara.FirstTextRange.Fill.FillType         = FillFormatType.Solid;
            contentPara.FirstTextRange.Fill.SolidColor.Color = Color.Black;
            contentPara.Alignment = TextAlignmentType.Left;
            //Shape format
            textShape.ShapeStyle.LineColor.Color = Color.Empty;
            textShape.Fill.FillType = FillFormatType.Gradient;
            textShape.Fill.Gradient.GradientStops.Append(0, Color.LightBlue);
            textShape.Fill.Gradient.GradientStops.Append(1, Color.LightGreen);
            //Set footer
            ppt.SetDateTimeVisible(true);
            ppt.SetSlideNoVisible(true);

            //Set transition of slide
            slide.SlideShowTransition.Type = TransitionType.Cover;

            //Save the file
            ppt.SaveToFile("result.pptx", FileFormat.Pptx2010);
        }