Example #1
0
        public void Is_Base_Class_Searilzable()
        {
            ProjectSetting ps = new ProjectSetting();
            WatermarkText  wt = new WatermarkText {
                Text = "Hello world",
                WatermarkPosition      = ContentAlignment.MiddleLeft,
                WatermarkRotateAngle   = 12,
                WatermarkTextAlignment = StringAlignment.Center
            };

            ps.WatermarkCollection.Add(wt);

            WatermarkImage wi = new WatermarkImage {
                WatermarkImageFile = @"c:\temp\1.jpg",
                WatermarkPosition  = ContentAlignment.MiddleCenter
            };

            ps.WatermarkCollection.Add(wi);


            MemoryStream stream    = new MemoryStream();
            IFormatter   formatter = new BinaryFormatter();

            formatter.Serialize(stream, ps);

            stream.Position = 0;

            ProjectSetting ps1 = (ProjectSetting)formatter.Deserialize(stream);

            Assert.AreEqual(ps1.WatermarkCollection.Count, 2);
            //Assert.IsNull(ps1.WatermarkCollection[2]);
            //Assert.IsNull(ps1.WatermarkCollection[3]);
            Assert.IsInstanceOfType(ps1.WatermarkCollection[0], typeof(WatermarkText));
            Assert.IsInstanceOfType(ps1.WatermarkCollection[1], typeof(WatermarkImage));
        }
Example #2
0
        public void ConfigureScriptsAndAttributes()
        {
            EnsureChildControls();

            this.Attributes.Add("name", UniqueID);

            if (RequestDelay.HasValue)
            {
                InnerTextBox.Attributes["requestDelay"] = RequestDelay.Value.ToString();
            }

            if (ExpandOnFocus)
            {
                InnerTextBox.Attributes["expandOnFocus"] = "true";
            }

            if (OptimizedMode.HasValue)
            {
                InnerTextBox.Attributes["optimizedMode"] = OptimizedMode.Value.ToString().ToLower();
            }

            if (SourceProvider.HasValue())
            {
                InnerTextBox.Attributes["SourceProvider"] = SourceProvider;
            }

            if (ClientSide)
            {
                InnerTextBox.Attributes["clientSide"] = "true";
            }

            if (AutoPostBack)
            {
                InnerTextBox.Attributes["AutoPostBack"] = "true";
            }

            if (OnSelectedValueChange.HasValue())
            {
                InnerTextBox.Attributes["OnSelectedValueChange"] = OnSelectedValueChange;
            }

            if (OnCollapse.HasValue())
            {
                InnerTextBox.Attributes["OnCollapse"] = OnCollapse;
            }

            if (NotFoundText.HasValue())
            {
                InnerTextBox.Attributes["NotFoundText"] = NotFoundText;
            }

            if (WatermarkText.HasValue())
            {
                var water = new TextBoxWatermarkExtender {
                    WatermarkText = WatermarkText, TargetControlID = InnerTextBox.ID, WatermarkCssClass = InnerTextBox.CssClass.WithSuffix(" waterMark")
                };
                Controls.Add(water);
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="InsertWatermarkTextOnlineRequest"/> class.
 /// </summary>
 /// <param name="document">The document.</param>
 /// <param name="watermarkText">The watermark data.</param>
 /// <param name="loadEncoding">Encoding that will be used to load an HTML (or TXT) document if the encoding is not specified in HTML.</param>
 /// <param name="password">Password for opening an encrypted document.</param>
 /// <param name="destFileName">Result path of the document after the operation. If this parameter is omitted then result of the operation will be saved as the source document.</param>
 /// <param name="revisionAuthor">Initials of the author to use for revisions.If you set this parameter and then make some changes to the document programmatically, save the document and later open the document in MS Word you will see these changes as revisions.</param>
 /// <param name="revisionDateTime">The date and time to use for revisions.</param>
 public InsertWatermarkTextOnlineRequest(System.IO.Stream document, WatermarkText watermarkText, string loadEncoding = null, string password = null, string destFileName = null, string revisionAuthor = null, string revisionDateTime = null)
 {
     this.Document         = document;
     this.WatermarkText    = watermarkText;
     this.LoadEncoding     = loadEncoding;
     this.Password         = password;
     this.DestFileName     = destFileName;
     this.RevisionAuthor   = revisionAuthor;
     this.RevisionDateTime = revisionDateTime;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="InsertWatermarkTextRequest"/> class.
 /// </summary>
 /// <param name="name">The filename of the input document.</param>
 /// <param name="watermarkText">The watermark data.</param>
 /// <param name="folder">Original document folder.</param>
 /// <param name="storage">Original document storage.</param>
 /// <param name="loadEncoding">Encoding that will be used to load an HTML (or TXT) document if the encoding is not specified in HTML.</param>
 /// <param name="password">Password for opening an encrypted document.</param>
 /// <param name="destFileName">Result path of the document after the operation. If this parameter is omitted then result of the operation will be saved as the source document.</param>
 /// <param name="revisionAuthor">Initials of the author to use for revisions.If you set this parameter and then make some changes to the document programmatically, save the document and later open the document in MS Word you will see these changes as revisions.</param>
 /// <param name="revisionDateTime">The date and time to use for revisions.</param>
 public InsertWatermarkTextRequest(string name, WatermarkText watermarkText, string folder = null, string storage = null, string loadEncoding = null, string password = null, string destFileName = null, string revisionAuthor = null, string revisionDateTime = null)
 {
     this.Name             = name;
     this.WatermarkText    = watermarkText;
     this.Folder           = folder;
     this.Storage          = storage;
     this.LoadEncoding     = loadEncoding;
     this.Password         = password;
     this.DestFileName     = destFileName;
     this.RevisionAuthor   = revisionAuthor;
     this.RevisionDateTime = revisionDateTime;
 }
        public void TestPostInsertWatermarkText()
        {
            var localName    = "test_multi_pages.docx";
            var remoteName   = "TestPostInsertWatermarkText.docx";
            var fullName     = Path.Combine(this.dataFolder, remoteName);
            var destFileName = Path.Combine(BaseTestOutPath, remoteName);
            var body         = new WatermarkText {
                Text = "This is the text", RotationAngle = 90.0f
            };

            this.StorageApi.PutCreate(fullName, null, null, File.ReadAllBytes(BaseTestContext.GetDataDir(BaseTestContext.CommonFolder) + localName));

            var request = new PostInsertDocumentWatermarkTextRequest(remoteName, body, this.dataFolder, destFileName: destFileName);
            var actual  = this.WordsApi.PostInsertDocumentWatermarkText(request);

            Assert.AreEqual(200, actual.Code);
        }
Example #6
0
        /// <summary>
        /// insert water mark text into the document
        /// </summary>
        /// <param name="FileName"></param>
        /// <param name="text"></param>
        /// <param name="rotationAngle"></param>
        /// <returns></returns>
        public Boolean insertWatermarkText(string FileName, string text, double rotationAngle)
        {
            try
            {
                //build URI to get Image
                string strURI = Product.BaseProductUri + "/words/" + FileName + "/insertWatermarkText";

                string signedURI = Utils.Sign(strURI);

                //serialize the JSON request content
                WatermarkText watermark = new WatermarkText();
                watermark.Text          = text;
                watermark.RotationAngle = rotationAngle;

                string strJSON = JsonConvert.SerializeObject(watermark);

                Stream responseStream = Utils.ProcessCommand(signedURI, "POST", strJSON);

                StreamReader reader      = new StreamReader(responseStream);
                string       strResponse = reader.ReadToEnd();

                //Parse the json string to JObject
                JObject pJSON = JObject.Parse(strResponse);

                BaseResponse baseResponse = JsonConvert.DeserializeObject <BaseResponse>(pJSON.ToString());

                if (baseResponse.Code == "200" && baseResponse.Status == "OK")
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
        /// <summary>
        /// insert water mark text into the document
        /// </summary>
        /// <param name="FileName"></param>
        /// <param name="text"></param>
        /// <param name="rotationAngle"></param>
        /// <returns></returns>
        public Boolean insertWatermarkText(string FileName, string text, double rotationAngle)
        {
            try
            {
                //build URI to get Image
                string strURI = Product.BaseProductUri + "/words/" + FileName + "/insertWatermarkText";

                string signedURI = Utils.Sign(strURI);

                //serialize the JSON request content
                WatermarkText watermark = new WatermarkText();
                watermark.Text = text;
                watermark.RotationAngle = rotationAngle;

                string strJSON = JsonConvert.SerializeObject(watermark);

                Stream responseStream = Utils.ProcessCommand(signedURI, "POST", strJSON);

                StreamReader reader = new StreamReader(responseStream);
                string strResponse = reader.ReadToEnd();

                //Parse the json string to JObject
                JObject pJSON = JObject.Parse(strResponse);

                BaseResponse baseResponse = JsonConvert.DeserializeObject<BaseResponse>(pJSON.ToString());

                if (baseResponse.Code == "200" && baseResponse.Status == "OK")
                    return true;
                else
                    return false;

            }
            catch (Exception ex)
            {
                return false;
            }
        }
        public static void Run()
        {
            // ExStart:1
            WordsApi   wordsApi   = new WordsApi(Common.APP_KEY, Common.APP_SID, Common.BASEPATH);
            StorageApi storageApi = new StorageApi(Common.APP_KEY, Common.APP_SID, Common.BASEPATH);

            String        fileName      = "SampleBlankWordDocument.docx";
            String        destFileName  = "updated-" + fileName;
            Double        rotationAngle = 0.0;
            String        storage       = "dropboxstorage";
            String        folder        = null;
            String        text          = "New";
            WatermarkText body          = new WatermarkText();

            body.Text = "aspose.com";

            try
            {
                // Upload the file
                storageApi.PutCreate(fileName, "", storage, System.IO.File.ReadAllBytes(Common.GetDataDir() + fileName));
                // Invoke Aspose.Words Cloud SDK API to add watermark text to document
                DocumentResponse apiResponse = wordsApi.PostInsertWatermarkText(fileName, text, rotationAngle, destFileName, storage, folder, body);


                if (apiResponse != null && apiResponse.Status.Equals("OK"))
                {
                    Console.WriteLine("Watermark text has been added successfully");
                    Console.ReadKey();
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("error:" + ex.Message + "\n" + ex.StackTrace);
            }
            // ExEnd:1
        }
Example #9
0
        private void ProcessImage(object threadIndex)
        {
            int index = (int)threadIndex;

            Trace.WriteLine("Thread " + Thread.CurrentThread.ManagedThreadId + " is created to process indexed item [" + index + "] at " + DateTime.Now + ".");
            Trace.WriteLine("Current Thread " + Thread.CurrentThread.ManagedThreadId + " Culture " + Thread.CurrentThread.CurrentCulture.ToString() + " during processing.");

            string imagePath  = string.Empty;
            uint   imageIndex = 0;

            lock (syncRoot) {
                if (jobQueue.Count > 0)
                {
                    JobItem item = jobQueue.Dequeue();

                    imagePath  = item.FileName;
                    imageIndex = item.Index;
                    Trace.WriteLine("Thread " + Thread.CurrentThread.ManagedThreadId + " is handling " + imagePath);
                }
                else
                {
                    // nothing more to process, signal
#if DEBUG
                    Debug.WriteLine("Thread " + Thread.CurrentThread.ManagedThreadId + " is set because no more image to process at " + DateTime.Now + ".");
#endif
                    events[index].Set();
                    return;
                }
            }

            if (stopFlag)
            {
                // stop requested, signal
#if DEBUG
                Debug.WriteLine("Thread " + Thread.CurrentThread.ManagedThreadId + " is set because stop requested.");
#endif
                events[index].Set();
                return;
            }
            else
            {
                ExifMetadata exif = null;

                Image normalImage = null;
                Image thumbImage  = null;
                try {
                    if (ps.KeepExif)
                    {
                        // keep exif information from original file
                        exif = new ExifMetadata(new Uri(imagePath), true);
                        Trace.WriteLine("Thread " + Thread.CurrentThread.ManagedThreadId + " obtained EXIF for " + imagePath + " at " + DateTime.Now + ".");
                    }

                    // this will lock image until entire application quits: normalImage = Image.FromFile(imagePath);
                    // following code won't lock image.
                    using (Stream stream = File.OpenRead(imagePath)) {
                        normalImage = Image.FromStream(stream);
                        Trace.WriteLine("Thread " + Thread.CurrentThread.ManagedThreadId + " opened " + imagePath + " at " + DateTime.Now + ".");
                    }

                    ImageFormat format = getImageFormat(imagePath);

                    IProcess process;

                    // thumbnail operation
                    if (ps.ThumbnailSetting.GenerateThumbnail && ps.ThumbnailSetting.ThumbnailSize > 0)
                    {
                        process    = container.Resolve <IProcess>("ThumbImage");
                        thumbImage = process.ProcessImage(normalImage, this.ps);
                        Trace.WriteLine("Thread " + Thread.CurrentThread.ManagedThreadId + " processed thumbnail for " + imagePath + " at " + DateTime.Now + ".");
                    }

                    // shrink image operation
                    if (ps.ShrinkImage && ps.ShrinkPixelTo > 0)
                    {
                        process     = container.Resolve <IProcess>("ShrinkImage");
                        normalImage = process.ProcessImage(normalImage, this.ps);
                        Trace.WriteLine("Thread " + Thread.CurrentThread.ManagedThreadId + " shrinked " + imagePath + " at " + DateTime.Now + ".");
                    }

                    // image process effect
                    if (ps.ProcessType != ImageProcessType.None)
                    {
                        switch (ps.ProcessType)
                        {
                        case ImageProcessType.GrayScale:
                            process     = container.Resolve <IProcess>("GrayscaleEffect");
                            normalImage = process.ProcessImage(normalImage, null);
                            Trace.WriteLine("Thread " + Thread.CurrentThread.ManagedThreadId + " applied GrayscaleEffect for " + imagePath + " at " + DateTime.Now + ".");
                            break;

                        case ImageProcessType.NagativeImage:
                            process     = container.Resolve <IProcess>("NegativeEffect");
                            normalImage = process.ProcessImage(normalImage, null);
                            Trace.WriteLine("Thread " + Thread.CurrentThread.ManagedThreadId + " applied NegativeEffect for " + imagePath + " at " + DateTime.Now + ".");
                            break;

                        case ImageProcessType.OilPaint:
                            process     = container.Resolve <IProcess>("OilPaintEffect");
                            normalImage = process.ProcessImage(normalImage, null);
                            Trace.WriteLine("Thread " + Thread.CurrentThread.ManagedThreadId + " applied OilPaintEffect for " + imagePath + " at " + DateTime.Now + ".");
                            break;

                        case ImageProcessType.PencilSketch:
                            process     = container.Resolve <IProcess>("PencilSketchEffect");
                            normalImage = process.ProcessImage(normalImage, null);
                            Trace.WriteLine("Thread " + Thread.CurrentThread.ManagedThreadId + " applied PencilSketchEffect for " + imagePath + " at " + DateTime.Now + ".");
                            break;

                        case ImageProcessType.Relief:
                            process     = container.Resolve <IProcess>("ReliefEffect");
                            normalImage = process.ProcessImage(normalImage, null);
                            Trace.WriteLine("Thread " + Thread.CurrentThread.ManagedThreadId + " applied ReliefEffect for " + imagePath + " at " + DateTime.Now + ".");
                            break;

                        default:
                            break;
                        }
                    }

                    if (ps.WatermarkCollection != null && ps.WatermarkCollection.Count > 0)
                    {
                        IUnityContainer watermarkContainer;
                        watermarkContainer = container.CreateChildContainer();
                        watermarkContainer.RegisterInstance <List <ExifContainerItem> >(exifContainer)
                        .RegisterInstance <string>(dateTimeStringFormat);

                        for (int watermarkIndex = 0; watermarkIndex < ps.WatermarkCollection.Count; watermarkIndex++)
                        {
                            watermarkContainer.RegisterInstance <int>(watermarkIndex);

                            if (ps.WatermarkCollection[watermarkIndex] is WatermarkText)
                            {
                                // text watermark operation
                                WatermarkText wt = ps.WatermarkCollection[watermarkIndex] as WatermarkText;
                                if (!string.IsNullOrEmpty(wt.Text) && wt.WatermarkTextColor.A > 0)
                                {
#if DEBUG
                                    Debug.WriteLine("Current Thread "
                                                    + Thread.CurrentThread.ManagedThreadId + " Culture "
                                                    + Thread.CurrentThread.CurrentCulture.ToString()
                                                    + " before ApplyWatermarkText.");

                                    Debug.WriteLine("Current Thread: "
                                                    + Thread.CurrentThread.ManagedThreadId + ";"
                                                    + " Image File Name: " + imagePath + ","
                                                    + " Watermark Text index: " + watermarkIndex
                                                    + " before.");
#endif
                                    //process = container.Resolve<IProcess>("WatermarkText");
                                    process = watermarkContainer.Resolve <IProcess>("WatermarkText");
                                    process.ImageFileName = imagePath;
                                    normalImage           = process.ProcessImage(normalImage, this.ps);
                                }
                            }
                            else if (ps.WatermarkCollection[watermarkIndex] is WatermarkImage)
                            {
                                // image watermark operation
                                WatermarkImage wi = ps.WatermarkCollection[watermarkIndex] as WatermarkImage;
                                if (!string.IsNullOrEmpty(wi.WatermarkImageFile) &&
                                    File.Exists(wi.WatermarkImageFile) &&
                                    wi.WatermarkImageOpacity > 0)
                                {
#if DEBUG
                                    System.Diagnostics.Debug.WriteLine("Current Thread: "
                                                                       + System.Threading.Thread.CurrentThread.ManagedThreadId + ";"
                                                                       + " Image File Name: " + imagePath + ","
                                                                       + " Watermark Image index: " + watermarkIndex
                                                                       + " before.");
#endif
                                    process = watermarkContainer.Resolve <IProcess>("WatermarkImage");
                                    process.ImageFileName = imagePath;
                                    normalImage           = process.ProcessImage(normalImage, this.ps);
                                }
                            }
                        }

                        Trace.WriteLine("Thread " + Thread.CurrentThread.ManagedThreadId + " applied watermark(s) for " + imagePath + " at " + DateTime.Now + ".");
                    }

                    // border operation
                    if (ps.BorderSetting.BorderWidth > 0)
                    {
                        process     = container.Resolve <IProcess>("AddBorder");
                        normalImage = process.ProcessImage(normalImage, this.ps);
                        Trace.WriteLine("Thread " + Thread.CurrentThread.ManagedThreadId + " added border for " + imagePath + " at " + DateTime.Now + ".");
                    }

                    // drop shadow operation
                    if (ps.DropShadowSetting.ShadowDepth > 0)
                    {
                        process     = container.Resolve <IProcess>("DropShadow");
                        normalImage = process.ProcessImage(normalImage, this.ps);
                        Trace.WriteLine("Thread " + Thread.CurrentThread.ManagedThreadId + " added dropshadow for " + imagePath + " at " + DateTime.Now + ".");
                    }

                    IFilenameProvider fileNameProvider;

                    if (ps.RenamingSetting.EnableBatchRename)
                    {
                        fileNameProvider = container.Resolve <IFilenameProvider>("BatchRenamedFileName");
                    }
                    else
                    {
                        fileNameProvider = container.Resolve <IFilenameProvider>("NormalFileName");
                    }
                    fileNameProvider.PS             = ps;
                    fileNameProvider.ImageIndex     = imageIndex;
                    fileNameProvider.SourceFileName = imagePath;

                    ISaveImage imageSaver;
                    if (format == ImageFormat.Jpeg)
                    {
                        imageSaver      = container.Resolve <ISaveImage>("SaveCompressedJpgImage");
                        imageSaver.Exif = exif;
                    }
                    else
                    {
                        imageSaver = container.Resolve <ISaveImage>("SaveNormalImage");
                    }
                    imageSaver.SaveImageToDisk(normalImage, format, fileNameProvider);

                    if (thumbImage != null)
                    {
                        // TODO think about applying thumbImage file name to batch renamed original file
                        fileNameProvider                = container.Resolve <IFilenameProvider>("ThumbFileName");
                        fileNameProvider.PS             = ps;
                        fileNameProvider.ImageIndex     = imageIndex;
                        fileNameProvider.SourceFileName = imagePath;
                        //saveImage(imagePath, thumbImage, format, fileNameProvider, imageSaver, imageIndex);
                        imageSaver.SaveImageToDisk(thumbImage, format, fileNameProvider);
                    }
                } catch (Exception ex) {
                    Trace.TraceError(ex.ToString());
                } finally {
                    if (normalImage != null)
                    {
                        // if there is an source image in queue which does not exist any more, this could be null.
                        normalImage.Dispose();
                        normalImage = null;
                    }

                    if (thumbImage != null)
                    {
                        thumbImage.Dispose();
                        thumbImage = null;
                    }

                    ImageProcessedEventArgs args = new ImageProcessedEventArgs(imagePath);
                    OnImageProcessed(args);
                }

                // recursively call itself to go back to check if there are more files waiting to be processed.
                ProcessImage(threadIndex);
            }
        }
        // TODO examine to add text to a transparent GIF image still works.
        public override Image ProcessImage(Image input, ProjectSetting ps)
        {
            try {
                if (ps.WatermarkCollection.Count < watermarkIndex)
                {
                    return(input);
                }

                WatermarkText wt = ps.WatermarkCollection[this.watermarkIndex] as WatermarkText;

                if (wt == null)
                {
                    return(input);
                }

#if DEBUG
                Debug.WriteLine("Current Thread: "
                                + Thread.CurrentThread.ManagedThreadId + ","
                                + " Image File Name: " + this.ImageFileName + ","
                                + " Watermark Text index: " + watermarkIndex);
#endif

                int   iHOffset          = 0;
                int   iVOffset          = 0;
                int   rotatedTextHeight = 0;
                int   rotatedTextWidth  = 0;
                int   iBmpHeight        = 0;
                int   iBmpWidth         = 0;
                float fHRes             = 0;
                float fVRes             = 0;
                int   textWidth         = 0;
                int   textHeight        = 0;
                int   xAfterOffset      = 0;
                int   yAfterOffset      = 0;

                string textToDraw = wt.Text;
                List <ExifContainerItem> tagsFound = this.FindExifTags(textToDraw);

                if (tagsFound != null && tagsFound.Count > 0 && !string.IsNullOrEmpty(this.ImageFileName))
                {
                    // at least one Exif tag is found
                    textToDraw = ConvertExifTagsToText(textToDraw, tagsFound);
                }

                textToDraw = this.ConvertControlTagsToText(textToDraw);

                // create a bitmap we can use to work out the size of the text,
                // we will then create a new bitmap that is the right size.
                // we also use this to record the default resolution
                Bitmap bmp = new Bitmap(1, 1, PixelFormat.Format32bppArgb);
                fHRes = bmp.HorizontalResolution;
                fVRes = bmp.VerticalResolution;
                Graphics     g      = Graphics.FromImage(bmp);
                StringFormat format = new StringFormat();
                format.Alignment = wt.WatermarkTextAlignment;
                SizeF sf = g.MeasureString(textToDraw, wt.WatermarkTextFont,
                                           Int32.MaxValue, format);
                g.Dispose();
                bmp.Dispose();

                // get the width and height of the text
                textWidth  = Math.Max(2, (int)Math.Ceiling(sf.Width));
                textHeight = Math.Max(2, (int)Math.Ceiling(sf.Height));

                RotationSize rs = CalculateRotationSize(textWidth, textHeight, wt.WatermarkRotateAngle);
                iHOffset          = rs.HorizontalOffset;
                iVOffset          = rs.VerticalOffset;
                rotatedTextWidth  = rs.RotatedWidth;
                rotatedTextHeight = rs.RotatedHeight;

                bmp        = new Bitmap(input);
                iBmpWidth  = bmp.Width;
                iBmpHeight = bmp.Height;
                g          = Graphics.FromImage(bmp);

                // determine the offset needed to position the text in the right place
                // in the background if it is not the same size as we calculate was needed for the text
                // adding in the padding where necessary and
                // remembering to adjust for differences in padding between left/right top/bottom etc.
                switch (wt.WatermarkPosition)
                {
                case ContentAlignment.TopLeft:
                case ContentAlignment.TopCenter:
                case ContentAlignment.TopRight:
                    //yAfterOffset = definition.TextPadding.Top;
                    yAfterOffset = wt.Padding;
                    break;

                case ContentAlignment.MiddleLeft:
                case ContentAlignment.MiddleCenter:
                case ContentAlignment.MiddleRight:
                    //yAfterOffset = (bmp.Height - rotatedHeight) / 2 + definition.TextPadding.Top - definition.TextPadding.Bottom;
                    yAfterOffset = (bmp.Height - rotatedTextHeight) / 2 + wt.Padding - wt.Padding;
                    break;

                case ContentAlignment.BottomLeft:
                case ContentAlignment.BottomCenter:
                case ContentAlignment.BottomRight:
                    //yAfterOffset = (bmp.Height - rotatedHeight) - definition.TextPadding.Bottom;
                    yAfterOffset = (bmp.Height - rotatedTextHeight) - wt.Padding;
                    break;
                }
                switch (wt.WatermarkPosition)
                {
                case ContentAlignment.TopLeft:
                case ContentAlignment.MiddleLeft:
                case ContentAlignment.BottomLeft:
                    //xAfterOffset = definition.TextPadding.Left;
                    xAfterOffset = wt.Padding;
                    break;

                case ContentAlignment.TopCenter:
                case ContentAlignment.MiddleCenter:
                case ContentAlignment.BottomCenter:
                    //xAfterOffset = (bmp.Width - rotatedWidth) / 2 + definition.TextPadding.Left - definition.TextPadding.Right;
                    xAfterOffset = (bmp.Width - rotatedTextWidth) / 2 + wt.Padding - wt.Padding;
                    break;

                case ContentAlignment.TopRight:
                case ContentAlignment.MiddleRight:
                case ContentAlignment.BottomRight:
                    //xAfterOffset = (bmp.Width - rotatedWidth) - definition.TextPadding.Right;
                    xAfterOffset = (bmp.Width - rotatedTextWidth) - wt.Padding;
                    break;
                }

                // create a new transformation matrix to do the rotation and corresponding translation
                Matrix matrix = new Matrix();
                // translation to position the text as required by HAlignment and VAlignment
                matrix.Translate(xAfterOffset, yAfterOffset);
                // translation to bring the rotation back to view
                matrix.Translate(iHOffset, iVOffset);
                // transformation to rotate the text
                matrix.Rotate(wt.WatermarkRotateAngle);
                if (wt.WatermarkTextAlignment == StringAlignment.Center)
                {
                    // transformation to cope with non left aligned text
                    matrix.Translate(textWidth / 2, 0);
                }
                else if (wt.WatermarkTextAlignment == StringAlignment.Far)
                {
                    matrix.Translate(textWidth, 0);
                }

                // apply the transformation to the graphics object and write out the text
                g.Transform         = matrix;
                g.SmoothingMode     = SmoothingMode.HighQuality;
                g.TextRenderingHint = TextRenderingHint.AntiAlias;
                // draw a shadow with semi transparent black
                g.DrawString(textToDraw,
                             wt.WatermarkTextFont,
                             new SolidBrush(Color.FromArgb(153, 0, 0, 0)), 1, 1, format);
                // draw the sctual text
                g.DrawString(textToDraw,
                             wt.WatermarkTextFont,
                             new SolidBrush(wt.WatermarkTextColor), 0, 0, format);
                g.Transform = matrix;
                g.Dispose();

                return(bmp);
            } catch (Exception ex) {
                Trace.TraceError(ex.ToString());
                return(input);
            }
        }