コード例 #1
0
        public static void Run()
        {
            //ExStart:AddRelativeScaleHeightPictureFrame
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_Shapes();

            // Instantiate presentation object
            using (Presentation presentation = new Presentation())
            {
                // Load Image to be added in presentaiton image collection
                Image    img   = new Bitmap(dataDir + "aspose-logo.jpg");
                IPPImage image = presentation.Images.AddImage(img);

                // Add picture frame to slide
                IPictureFrame pf = presentation.Slides[0].Shapes.AddPictureFrame(ShapeType.Rectangle, 50, 50, 100, 100, image);

                // Setting relative scale width and height
                pf.RelativeScaleHeight = 0.8f;
                pf.RelativeScaleWidth  = 1.35f;

                // Save presentation
                presentation.Save(dataDir + "Adding Picture Frame with Relative Scale_out.pptx", SaveFormat.Pptx);
            }
            //ExEnd:AddRelativeScaleHeightPictureFrame
        }
コード例 #2
0
        /// <summary>
        /// Adds image watermark into source file, saves resulted file to out file.
        /// </summary>
        /// <param name="sourceFile">Source slides file to proceed.</param>
        /// <param name="outFile">Output slides file.</param>
        /// <param name="options">Watermark options.</param>
        public void AddImageWatermark(
            string sourceFile,
            string outFile,
            ImageWatermarkOptionsModel options
            )
        {
            using (var presentation = new Presentation(sourceFile))
            {
                var size = presentation.SlideSize.Size;
                var img  = ResizeImage(
                    new Bitmap(options.ImageFile),
                    options.ZoomPercent / 100.0
                    ) as Image;

                if (options.IsGrayScaled)
                {
                    img = ToolStripRenderer.CreateDisabledImage(img);
                }

                var imgx = presentation.Images.AddImage(img);

                var height = imgx.Height;
                var width  = imgx.Width;

                var centerW = (size.Width - width) / 2;
                var centerH = (size.Height - height) / 2;

                foreach (var slide in presentation.Slides)
                {
                    IPictureFrame pf = slide.Shapes.AddPictureFrame(
                        ShapeType.Rectangle,
                        centerW, centerH,
                        imgx.Width, imgx.Height,
                        imgx
                        );

                    pf.Name = "WaterMark";

                    pf.LineFormat.FillFormat.FillType = FillType.NoFill;

                    pf.Rotation = options.RotationAngleDegrees;
                }

                presentation.Save(outFile, GetFormatFromSource(sourceFile));
            }
        }
コード例 #3
0
        public static void Run()
        {
            //ExStart:PictureFrameFormatting
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_Shapes();

            // Create directory if it is not already present.
            bool IsExists = System.IO.Directory.Exists(dataDir);

            if (!IsExists)
            {
                System.IO.Directory.CreateDirectory(dataDir);
            }

            // Instantiate Presentation class that represents the PPTX
            using (Presentation pres = new Presentation())
            {
                // Get the first slide
                ISlide sld = pres.Slides[0];

                // Instantiate the ImageEx class
                System.Drawing.Image img  = (System.Drawing.Image) new Bitmap(dataDir + "aspose-logo.jpg");
                IPPImage             imgx = pres.Images.AddImage(img);

                // Add Picture Frame with height and width equivalent of Picture
                IPictureFrame pf = sld.Shapes.AddPictureFrame(ShapeType.Rectangle, 50, 150, imgx.Width, imgx.Height, imgx);

                // Apply some formatting to PictureFrameEx
                pf.LineFormat.FillFormat.FillType             = FillType.Solid;
                pf.LineFormat.FillFormat.SolidFillColor.Color = Color.Blue;
                pf.LineFormat.Width = 20;
                pf.Rotation         = 45;

                //Write the PPTX file to disk
                pres.Save(dataDir + "RectPicFrameFormat_out.pptx", SaveFormat.Pptx);
            }
            //ExEnd:PictureFrameFormatting
        }
コード例 #4
0
        public static void Run()
        {
            string dataDir          = RunExamples.GetDataDir_Conversion();
            string presTemplatePath = Path.Combine(dataDir, "PresentationTemplate.pptx");
            string resultPath       = Path.Combine(RunExamples.OutPath, "MailMergeResult");

            // Path to the data.
            // XML data is one of the examples of the possible MailMerge data sources (among RDBMS and other types of data sources).
            string dataPath = Path.Combine(dataDir, "TestData.xml");

            // Check if result path exists
            if (!Directory.Exists(resultPath))
            {
                Directory.CreateDirectory(resultPath);
            }

            // Creating DataSet using XML data
            using (DataSet dataSet = new DataSet())
            {
                dataSet.ReadXml(dataPath);

                DataTableCollection dataTables     = dataSet.Tables;
                DataTable           usersTable     = dataTables["TestTable"];
                DataTable           staffListTable = dataTables["StaffList"];
                DataTable           planFactTable  = dataTables["Plan_Fact"];

                // For all records in main table we will create a separate presentation
                foreach (DataRow userRow in usersTable.Rows)
                {
                    // create result (individual) presentation name
                    string presPath = Path.Combine(resultPath, "PresFor_" + userRow["Name"] + ".pptx");

                    // Load presentation template
                    using (Presentation pres = new Presentation(presTemplatePath))
                    {
                        // Fill text boxes with data from data base main table
                        ((AutoShape)pres.Slides[0].Shapes[0]).TextFrame.Text =
                            "Chief of the department - " + userRow["Name"];
                        ((AutoShape)pres.Slides[0].Shapes[4]).TextFrame.Text = userRow["Department"].ToString();

                        // Get image from data base
                        byte[] bytes = Convert.FromBase64String(userRow["Img"].ToString());

                        // insert image into picture frame of presentation
                        IPPImage      image = pres.Images.AddImage(bytes);
                        IPictureFrame pf    = pres.Slides[0].Shapes[1] as PictureFrame;
                        pf.PictureFormat.Picture.Image.ReplaceImage(image);

                        // Get abd prepare text frame for filling it with datas
                        IAutoShape list      = pres.Slides[0].Shapes[2] as IAutoShape;
                        ITextFrame textFrame = list.TextFrame;

                        textFrame.Paragraphs.Clear();
                        Paragraph para = new Paragraph();
                        para.Text = "Department Staff:";
                        textFrame.Paragraphs.Add(para);

                        // fill staff data
                        FillStaffList(textFrame, userRow, staffListTable);

                        // fill plan fact data
                        FillPlanFact(pres, userRow, planFactTable);

                        pres.Save(presPath, SaveFormat.Pptx);
                    }
                }
            }
        }