示例#1
0
        /// <summary>
        /// Adds text 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 AddTextWatermark(
            string sourceFile,
            string outFile,
            TextWatermarkOptionsModel options
            )
        {
            using (var presentation = new Presentation(sourceFile))
            {
                var size   = presentation.SlideSize.Size;
                var height = size.Height;
                var width  = size.Width;

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

                foreach (var slide in presentation.Slides)
                {
                    var shape = slide.Shapes.AddAutoShape(
                        ShapeType.Rectangle,
                        centerW, centerH,
                        width, height
                        );
                    shape.Name = "WaterMark";

                    shape.FillFormat.FillType            = FillType.NoFill;
                    shape.LineFormat.FillFormat.FillType = FillType.NoFill;

                    var textFrame = shape.AddTextFrame(" ");
                    textFrame.TextFrameFormat.AnchoringType = TextAnchorType.Center;
                    textFrame.TextFrameFormat.CenterText    = NullableBool.True;

                    var paragraph = textFrame.Paragraphs[0];
                    paragraph.ParagraphFormat.Alignment = TextAlignment.Center;

                    var portion = paragraph.Portions[0];
                    var format  = portion.PortionFormat;

                    format.FillFormat.FillType = FillType.Solid;

                    portion.Text = options.Text;
                    format.FillFormat.SolidFillColor.Color = options.ColorValue;
                    format.LatinFont  = new FontData(options.FontName);
                    format.FontHeight = options.FontSize;
                    shape.Rotation    = options.RotationAngleDegrees;
                }

                presentation.Save(outFile, GetFormatFromSource(sourceFile));
            }
        }
示例#2
0
        protected void ProcessTextWatermarkButton_Click(object sender, EventArgs e)
        {
            TextWatermarkOptionsModel textWatermarkOptionsModel = new TextWatermarkOptionsModel();

            textWatermarkOptionsModel.id       = FolderNameHidden.Value;
            textWatermarkOptionsModel.FileName = FileNameHidden.Value;

            textWatermarkOptionsModel.Text                 = textWatermark.Value;
            textWatermarkOptionsModel.Color                = pickcolor.Value;
            textWatermarkOptionsModel.FontName             = fontFamily.SelectedValue;
            textWatermarkOptionsModel.FontSize             = int.Parse(fontSize.Text);
            textWatermarkOptionsModel.RotationAngleDegrees = int.Parse(textAngle.Text);

            var response = asposeSlides.AddTextWatermark(textWatermarkOptionsModel);

            SuccessLabel.InnerText = Resources["WatermarkAddedSuccessMessage"];
            PerformResponse(response, TextMessage, ShowDownloadPage);
        }