/// <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); } }
/// <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); } }
/// <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); } }
/// <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); } }
/// <summary> /// Removes old company logo added as watermark from all the documents in a folder /// </summary> public static void RemoveCompanyLogoWatermarkFromDocuments() { try { //ExStart:RemoveCompanyLogoWatermarkFromDocuments var inputFolder = SourceFolderPath; var outputFolder = SourceFolderPath + "/output"; var logo = @"D:\logo.png"; var files = Directory.GetFiles(inputFolder); ImageSearchCriteria imageSearchCriteria = new ImageDctHashSearchCriteria(logo); var regex = new Regex(@"^Company\sName$", RegexOptions.IgnoreCase); TextSearchCriteria textSearchCriteria = new TextSearchCriteria(regex); foreach (var file in files) { try { using (var doc = Document.Load(file)) { var watermarks = doc.FindWatermarks(textSearchCriteria.Or(imageSearchCriteria)); watermarks.Clear(); doc.Save(Path.Combine(outputFolder, Path.GetFileName(file))); } } catch (UnsupportedFileTypeException) { Console.WriteLine("File format is not supported. File = {0}", Path.GetFileName(file)); } } //ExEnd:RemoveCompanyLogoWatermarkFromDocuments } catch (Exception exp) { Console.Write(exp.Message); } }
/// <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); } }
/// <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); } }