Пример #1
0
        /// <summary>
        /// Removes hyperlinks with a particular URL
        /// </summary>
        public static void RemoveHyperlinksWithParticularURL()
        {
            try
            {
                //ExStart:RemoveHyperlinksWithParticularURL
                using (Document doc = Document.Load(Utilities.MapSourceFilePath(DOC_FILE_PATH)))
                {
                    PossibleWatermarkCollection watermarks = doc.FindWatermarks(new TextSearchCriteria(new Regex(@"someurl\.com")));
                    for (int i = watermarks.Count - 1; i >= 0; i--)
                    {
                        // Ensure that only hyperlinks will be removed.
                        if (watermarks[i] is HyperlinkPossibleWatermark)
                        {
                            // Output the full url of the hyperlink
                            Console.WriteLine(watermarks[i].Text);

                            // Remove hyperlink from the document
                            watermarks.RemoveAt(i);
                        }
                    }
                    doc.Save();
                }
                //ExEnd:RemoveHyperlinksWithParticularURL
            }
            catch (Exception exp)
            {
                Console.Write(exp.Message);
            }
        }
Пример #2
0
        /// <summary>
        /// Updates text with formatting in the found watermarks
        /// </summary>
        public static void EditTextWithFormattingInFoundWatermarks()
        {
            try
            {
                //ExStart:EditTextWithFormattingInFoundWatermarks_18.3
                using (Document doc = Document.Load(Utilities.MapSourceFilePath(DOC_FILE_PATH)))
                {
                    TextSearchCriteria          searchCriteria = new TextSearchCriteria("test", false);
                    PossibleWatermarkCollection watermarks     = doc.FindWatermarks(searchCriteria);
                    foreach (PossibleWatermark watermark in watermarks)
                    {
                        try
                        {
                            // Edit text
                            watermark.FormattedTextFragments.Clear();
                            watermark.FormattedTextFragments.Add("passed", new Font("Calibri", 19, FontStyle.Bold), Color.Red, Color.Aqua);
                        }
                        catch (Exception e)
                        {
                            // Found entity may not support text editing
                            // Passed arguments can have inappropriate value
                            // Process such cases here
                        }
                    }

                    // Save document
                    doc.Save();
                }
                //ExEnd:EditTextWithFormattingInFoundWatermarks_18.3
            }
            catch (Exception exp)
            {
                Console.Write(exp.Message);
            }
        }
Пример #3
0
        /// <summary>
        /// Removes watermark with a prticular text formatting
        /// </summary>
        public static void RemoveWatermarkWithParticularTextFormatting()
        {
            try
            {
                //ExStart:RemoveWatermarkWithParticularTextFormatting
                using (Document doc = Document.Load(Utilities.MapSourceFilePath(DOC_FILE_PATH)))
                {
                    TextFormattingSearchCriteria criteria = new TextFormattingSearchCriteria();
                    criteria.ForegroundColorRange               = new ColorRange();
                    criteria.ForegroundColorRange.MinHue        = -5;
                    criteria.ForegroundColorRange.MaxHue        = 10;
                    criteria.ForegroundColorRange.MinBrightness = 0.01f;
                    criteria.ForegroundColorRange.MaxBrightness = 0.99f;
                    criteria.BackgroundColorRange               = new ColorRange();
                    criteria.BackgroundColorRange.IsEmpty       = true;
                    criteria.FontName    = "Arial";
                    criteria.MinFontSize = 19;
                    criteria.MaxFontSize = 42;
                    criteria.FontBold    = true;

                    PossibleWatermarkCollection watermarks = doc.FindWatermarks(criteria);
                    watermarks.Clear();
                    doc.Save();
                }
                //ExEnd:RemoveWatermarkWithParticularTextFormatting
            }
            catch (Exception exp)
            {
                Console.Write(exp.Message);
            }
        }
Пример #4
0
        /// <summary>
        /// Updates text in the found watermarks
        /// </summary>
        public static void EditTextInFoundWatermarks()
        {
            try
            {
                //ExStart:EditTextInFoundWatermarks_18.3
                using (Document doc = Document.Load(Utilities.MapSourceFilePath(PPT_FILE_PATH)))
                {
                    TextSearchCriteria          searchCriteria = new TextSearchCriteria("test", false);
                    PossibleWatermarkCollection watermarks     = doc.FindWatermarks(searchCriteria);
                    foreach (PossibleWatermark watermark in watermarks)
                    {
                        try
                        {
                            // Edit text
                            watermark.Text = "passed";
                        }
                        catch (Exception e)
                        {
                            // Found entity may not support text editing
                            // Passed argument can have inappropriate value
                            // Process such cases here
                        }
                    }

                    // Save document
                    doc.Save();
                }
                //ExEnd:EditTextInFoundWatermarks_18.3
            }
            catch (Exception exp)
            {
                Console.Write(exp.Message);
            }
        }
Пример #5
0
        /// <summary>
        /// Searches for watermark with combination of different search criterias
        /// </summary>
        public static void SearchWatermarkWithCombinedSearch()
        {
            try
            {
                //ExStart:SearchWatermarkWithCombinedSearch
                using (Document doc = Document.Load(Utilities.MapSourceFilePath(DOC_FILE_PATH)))
                {
                    ImageSearchCriteria imageSearchCriteria = new ImageDctHashSearchCriteria(@"D:\logo.png");
                    imageSearchCriteria.MaxDifference = 0.9;

                    TextSearchCriteria textSearchCriteria = new TextSearchCriteria("Company Name");

                    RotateAngleSearchCriteria rotateAngleSearchCriteria = new RotateAngleSearchCriteria(30, 60);

                    SearchCriteria combinedSearchCriteria          = imageSearchCriteria.Or(textSearchCriteria).And(rotateAngleSearchCriteria);
                    PossibleWatermarkCollection possibleWatermarks = doc.FindWatermarks(combinedSearchCriteria);

                    // ...
                }
                //ExEnd:SearchWatermarkWithCombinedSearch
            }
            catch (Exception exp)
            {
                Console.Write(exp.Message);
            }
        }
Пример #6
0
 /// <summary>
 /// Searches for watermark in a document
 /// </summary>
 public static void SearchWatermark()
 {
     try
     {
         //ExStart:SearchWatermark
         using (Document doc = Document.Load(Utilities.MapSourceFilePath(DOC_FILE_PATH)))
         {
             PossibleWatermarkCollection possibleWatermarks = doc.FindWatermarks();
             foreach (PossibleWatermark possibleWatermark in possibleWatermarks)
             {
                 if (possibleWatermark.ImageData != null)
                 {
                     Console.WriteLine(possibleWatermark.ImageData.Length);
                 }
                 Console.WriteLine(possibleWatermark.Text);
                 Console.WriteLine(possibleWatermark.X);
                 Console.WriteLine(possibleWatermark.Y);
                 Console.WriteLine(possibleWatermark.RotateAngle);
                 Console.WriteLine(possibleWatermark.Width);
                 Console.WriteLine(possibleWatermark.Height);
             }
         }
         //ExEnd:SearchWatermark
     }
     catch (Exception exp)
     {
         Console.Write(exp.Message);
     }
 }
Пример #7
0
        /// <summary>
        /// Searches for watermark with a particular text
        /// <param name="SearchString">Search String</param>
        /// </summary>
        public static void SearchWatermark(string SearchString)
        {
            try
            {
                //ExStart:SearchWatermarkWithSearchString
                using (Document doc = Document.Load(Utilities.MapSourceFilePath(PPT_FILE_PATH)))
                {
                    // Search by exact string
                    TextSearchCriteria textSearchCriteria = new TextSearchCriteria("© 2017");

                    // Find all possible watermarks containing some specific text
                    PossibleWatermarkCollection possibleWatermarks = doc.FindWatermarks(textSearchCriteria);

                    // ...
                }
                //ExEnd:SearchWatermarkWithSearchString
            }
            catch (Exception exp)
            {
                Console.Write(exp.Message);
            }
        }
Пример #8
0
        /// <summary>
        /// Replaces image in the found watermarks
        /// </summary>
        public static void ReplacesImageInFoundWatermarks()
        {
            try
            {
                //ExStart:ReplacesImageInFoundWatermarks_18.3

                byte[] imageData = File.ReadAllBytes(Utilities.MapSourceFilePath(PNG_FILE_PATH));

                using (Document doc = Document.Load(Utilities.MapSourceFilePath(PDF_FILE_PATH)))
                {
                    // Search watermark matching a particular image
                    SearchCriteria searchCriteria          = new ImageDctHashSearchCriteria(@"D:\logo.bmp");
                    PossibleWatermarkCollection watermarks = doc.FindWatermarks(searchCriteria);
                    foreach (PossibleWatermark watermark in watermarks)
                    {
                        try
                        {
                            // Replace image
                            watermark.ImageData = imageData;
                        }
                        catch (Exception e)
                        {
                            // Found entity may not support image replacment
                            // Passed image can have inappropriate format
                            // Process such cases here
                        }
                    }

                    // Save document
                    doc.Save();
                }
                //ExEnd:ReplacesImageInFoundWatermarks_18.3
            }
            catch (Exception exp)
            {
                Console.Write(exp.Message);
            }
        }
Пример #9
0
        /// <summary>
        /// Removes watermark
        /// </summary>
        public static void RemoveWatermark()
        {
            try
            {
                //ExStart:RemoveWatermark
                using (Document doc = Document.Load(Utilities.MapSourceFilePath(XLS_FILE_PATH)))
                {
                    PossibleWatermarkCollection possibleWatermarks = doc.FindWatermarks();

                    // Remove possible watermark at the specified index from the document.
                    possibleWatermarks.RemoveAt(0);

                    // Remove specified possible watermark from the document.
                    possibleWatermarks.Remove(possibleWatermarks[0]);

                    doc.Save();
                }
                //ExEnd:RemoveWatermark
            }
            catch (Exception exp)
            {
                Console.Write(exp.Message);
            }
        }
Пример #10
0
        /// <summary>
        /// Searches for image watermark
        /// </summary>
        public static void SearchImageWatermark()
        {
            try
            {
                //ExStart:SearchImageWatermark
                using (Document doc = Document.Load(Utilities.MapSourceFilePath(PPT_FILE_PATH)))
                {
                    // Initialize criteria with the image
                    ImageSearchCriteria imageSearchCriteria = new ImageDctHashSearchCriteria(@"D:\watermark.jpg");

                    //Set maximum allowed difference between images
                    imageSearchCriteria.MaxDifference = 0.9;

                    PossibleWatermarkCollection possibleWatermarks = doc.FindWatermarks(imageSearchCriteria);

                    // ...
                }
                //ExEnd:SearchImageWatermark
            }
            catch (Exception exp)
            {
                Console.Write(exp.Message);
            }
        }
Пример #11
0
        /// <summary>
        /// Searches for watermark with a regular expression
        /// <param name="RegularExpression">Regular Expression</param>
        /// </summary>
        public static void SearchWatermark(Regex RegularExpression)
        {
            try
            {
                //ExStart:SearchWatermarkWithRegularExpression
                using (Document doc = Document.Load(Utilities.MapSourceFilePath(DOC_FILE_PATH)))
                {
                    Regex regex = new Regex(@"^© \d{4}$");

                    // Search by regular expression
                    TextSearchCriteria textSearchCriteria = new TextSearchCriteria(regex);

                    // Find possible watermarks using regular expression
                    PossibleWatermarkCollection possibleWatermarks = doc.FindWatermarks(textSearchCriteria);

                    // ...
                }
                //ExEnd:SearchWatermarkWithRegularExpression
            }
            catch (Exception exp)
            {
                Console.Write(exp.Message);
            }
        }
Пример #12
0
        /// <summary>
        /// Searches for text watermark skipping unreadable characters
        /// </summary>
        public static void SearchTextWatermarkSkippingUnreadableCharacters()
        {
            try
            {
                //ExStart:SearchTextWatermarkSkippingUnreadableCharacters_18.8
                using (Document doc = Document.Load(Utilities.MapSourceFilePath(PPT_FILE_PATH)))
                {
                    string             watermarkText = "Company name";
                    TextSearchCriteria criterion     = new TextSearchCriteria(watermarkText);

                    // Enabling skipping of unreadable characters
                    criterion.SkipUnreadableCharacters = true;

                    PossibleWatermarkCollection result = doc.FindWatermarks(criterion);

                    // ...
                }
                //ExEnd:SearchTextWatermarkSkippingUnreadableCharacters_18.8
            }
            catch (Exception exp)
            {
                Console.Write(exp.Message);
            }
        }