Beispiel #1
0
        public void Search_Watermark()
        {
            var testFile = TestFiles.PdfWithWatermarks;
            var options  = new SearchOptions
            {
                FileInfo            = testFile.ToFileInfo(),
                ImageSearchCriteria = new ImageSearchCriteria
                {
                    ImageFileInfo = TestFiles.SampleWatermarkTransparent.ToFileInfo()
                },
                TextSearchCriteria = new TextSearchCriteria
                {
                    SearchText = "Watermark text"
                },
                SaveFoundImages = true,
                OutputFolder    = "found_image_watermarks"
            };
            var request = new SearchRequest(options);
            var result  = WatermarkApi.Search(request);

            Assert.IsNotNull(result);
            var urlTemplate    = "watermark/storage/file/found_image_watermarks/sample_pdf/watermark_image_{0}";
            var itemsWithImage = result.Watermarks.Where(x => x.ImageUrl != null).ToList();

            for (int i = 0; i < itemsWithImage.Count; i++)
            {
                Assert.IsTrue(itemsWithImage.Any(x => x.ImageUrl.Contains(string.Format(urlTemplate, i))));
            }

            var text = result.Watermarks.First(x => !string.IsNullOrWhiteSpace(x.Text));

            Assert.AreEqual("Watermark text", text.Text);
        }
Beispiel #2
0
        public void Replace_Watermark_Test()
        {
            var testFile = TestFiles.PdfWithWatermarks;
            var options  = new ReplaceOptions
            {
                FileInfo            = testFile.ToFileInfo(),
                ImageSearchCriteria = new ImageSearchCriteria
                {
                    ImageFileInfo = TestFiles.SampleWatermarkTransparent.ToFileInfo()
                },
                TextSearchCriteria = new TextSearchCriteria
                {
                    SearchText = "Watermark text"
                },
                ReplaceTextOptions = new ReplaceTextOptions
                {
                    Text = "New watermark text",
                },
                ReplaceImageOptions = new ReplaceImageOptions
                {
                    Image = TestFiles.Jpg.ToFileInfo()
                }
            };
            var request = new ReplaceRequest(options);
            var result  = WatermarkApi.Replace(request);

            CheckIfWatermarkExist(result.Path, "Watermark text", TestFiles.Jpg.ToFileInfo());
        }
Beispiel #3
0
        public void Add_Watermark_Without_Options()
        {
            var request = new AddRequest(null);
            var ex      = Assert.Throws <ApiException>(() => { WatermarkApi.Add(request); });

            Assert.AreEqual("Missing required parameter 'options' when calling Add", ex.Message);
        }
Beispiel #4
0
        public void Add_Watermark_Incorrect_Password()
        {
            var testFile = TestFiles.PasswordProtected;
            var options  = new WatermarkOptions
            {
                FileInfo = new FileInfo
                {
                    FilePath = testFile.FullName,
                    Password = "******"
                },
                WatermarkDetails = new List <WatermarkDetails>
                {
                    new WatermarkDetails
                    {
                        ImageWatermarkOptions = new ImageWatermarkOptions
                        {
                            Image = TestFiles.SampleWatermarkTransparent.ToFileInfo()
                        }
                    }
                },
            };

            var request = new AddRequest(options);
            var ex      = Assert.Throws <ApiException>(() => { WatermarkApi.Add(request); });

            Assert.AreEqual($"Password provided for file '{testFile.FullName}' is incorrect.", ex.Message);
        }
Beispiel #5
0
        public void Add_Watermark_File_Not_Supported()
        {
            var testFile = TestFiles.Zip;
            var options  = new WatermarkOptions
            {
                FileInfo         = testFile.ToFileInfo(),
                WatermarkDetails = new List <WatermarkDetails>
                {
                    new WatermarkDetails
                    {
                        TextWatermarkOptions = new TextWatermarkOptions
                        {
                            Text           = "Text",
                            FontFamilyName = "Arial",
                            FontSize       = 18
                        }
                    }
                },
            };

            var request = new AddRequest(options);
            var ex      = Assert.Throws <ApiException>(() => { WatermarkApi.Add(request); });

            Assert.AreEqual($"The specified file '{testFile.FullName}' has type which is not currently supported.", ex.Message);
        }
Beispiel #6
0
        public void Replace_Watermark_Incorrect_Password()
        {
            var testFile = TestFiles.PasswordProtected;
            var options  = new ReplaceOptions
            {
                FileInfo = new FileInfo
                {
                    FilePath = testFile.FullName,
                    Password = "******"
                },
                ImageSearchCriteria = new ImageSearchCriteria
                {
                    ImageFileInfo = TestFiles.SampleWatermarkTransparent.ToFileInfo()
                },
                TextSearchCriteria = new TextSearchCriteria
                {
                    SearchText = "Watermark text"
                }
            };

            var request = new ReplaceRequest(options);
            var ex      = Assert.Throws <ApiException>(() => { WatermarkApi.Replace(request); });

            Assert.AreEqual($"Password provided for file '{testFile.FullName}' is incorrect.", ex.Message);
        }
Beispiel #7
0
        public static void Run()
        {
            var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
            var apiInstance   = new WatermarkApi(configuration);

            try
            {
                var fileInfo = new FileInfo
                {
                    FilePath    = "with_watermarks/sample.pdf",
                    StorageName = Common.MyStorage
                };

                var options = new SearchOptions
                {
                    FileInfo            = fileInfo,
                    ImageSearchCriteria = new ImageSearchCriteria
                    {
                        ImageFileInfo = new FileInfo {
                            FilePath = "watermark_images/sample_watermark.png", StorageName = Common.MyStorage
                        }
                    },
                    TextSearchCriteria = new TextSearchCriteria
                    {
                        SearchText = "Watermark text"
                    },
                    SaveFoundImages = true,
                    OutputFolder    = "found_image_watermarks"
                };

                var request = new SearchRequest(options);

                var response = apiInstance.Search(request);
                foreach (var watermark in response.Watermarks)
                {
                    Console.WriteLine(
                        $"Id: {watermark.Id}, Type: {watermark.PossibleWatermarkType}, Height: {watermark.Height}, Width: {watermark.Width}");
                    if (!string.IsNullOrEmpty(watermark.Text))
                    {
                        Console.WriteLine($"Text: {watermark.Text}");
                    }

                    if (!string.IsNullOrEmpty(watermark.ImageUrl))
                    {
                        Console.WriteLine($"ImageUrl: {watermark.ImageUrl}");
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception while calling WatermarkApi: " + e.Message);
            }
        }
Beispiel #8
0
        public void Replace_Watermark_No_Search_Criteria()
        {
            var testFile = TestFiles.Xlsx;
            var options  = new ReplaceOptions
            {
                FileInfo     = testFile.ToFileInfo(),
                OutputFolder = "found_image_watermarks"
            };

            var request = new ReplaceRequest(options);
            var ex      = Assert.Throws <ApiException>(() => { WatermarkApi.Replace(request); });

            Assert.AreEqual("Request parameters missing or have incorrect format", ex.Message);
        }
Beispiel #9
0
        public void Add_Watermark_No_Details()
        {
            var testFile = TestFiles.Docx;
            var options  = new WatermarkOptions
            {
                FileInfo         = testFile.ToFileInfo(),
                WatermarkDetails = new List <WatermarkDetails>()
            };

            var request = new AddRequest(options);
            var ex      = Assert.Throws <ApiException>(() => { WatermarkApi.Add(request); });

            Assert.AreEqual("Request parameters missing or have incorrect format", ex.Message);
        }
        public void BeforeAllTests()
        {
            var config = new Configuration(_appSid, _appKey)
            {
                ApiBaseUrl = _apiBaseUrl
            };

            WatermarkApi = new WatermarkApi(config);
            InfoApi      = new InfoApi(config);
            FileApi      = new FileApi(config);
            FolderApi    = new FolderApi(config);
            StorageApi   = new StorageApi(config);

            UploadTestFiles();
        }
Beispiel #11
0
        public static void Run()
        {
            var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
            var apiInstance   = new WatermarkApi(configuration);

            try
            {
                var fileInfo = new FileInfo
                {
                    FilePath    = "with_watermarks/sample.pdf",
                    StorageName = Common.MyStorage
                };

                var options = new ReplaceOptions
                {
                    FileInfo            = fileInfo,
                    ImageSearchCriteria = new ImageSearchCriteria
                    {
                        ImageFileInfo = new FileInfo {
                            FilePath = "watermark_images/sample_watermark.png", StorageName = Common.MyStorage
                        }
                    },
                    TextSearchCriteria = new TextSearchCriteria
                    {
                        SearchText = "Watermark text"
                    },
                    ReplaceTextOptions = new ReplaceTextOptions
                    {
                        Text = "New watermark text",
                    },
                    ReplaceImageOptions = new ReplaceImageOptions
                    {
                        Image = new FileInfo {
                            FilePath = "images/sample.jpg", StorageName = Common.MyStorage
                        }
                    }
                };

                var request = new ReplaceRequest(options);

                var response = apiInstance.Replace(request);
                Console.WriteLine("Resultant file path: " + response.Path);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception while calling WatermarkApi: " + e.Message);
            }
        }
Beispiel #12
0
        public static void Run()
        {
            var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
            var apiInstance   = new WatermarkApi(configuration);

            try
            {
                var fileInfo = new FileInfo
                {
                    FilePath    = "documents/sample.docx",
                    StorageName = Common.MyStorage
                };

                var options = new WatermarkOptions()
                {
                    FileInfo         = fileInfo,
                    WatermarkDetails = new List <WatermarkDetails>
                    {
                        new WatermarkDetails
                        {
                            ImageWatermarkOptions = new ImageWatermarkOptions()
                            {
                                Image = new FileInfo {
                                    FilePath = "watermark_images/sample_watermark.png", StorageName = Common.MyStorage
                                }
                            }
                        }
                    },
                    ProtectLevel = WatermarkOptions.ProtectLevelEnum.DocumentAndImages
                };

                var request = new AddRequest(options);

                var response = apiInstance.Add(request);
                Console.WriteLine("Resultant file path: " + response.Path);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception while calling WatermarkApi: " + e.Message);
            }
        }
Beispiel #13
0
        public void Replace_Watermark_File_Not_Found()
        {
            var testFile = TestFiles.NotExist;
            var options  = new ReplaceOptions()
            {
                FileInfo            = testFile.ToFileInfo(),
                ImageSearchCriteria = new ImageSearchCriteria
                {
                    ImageFileInfo = TestFiles.SampleWatermarkTransparent.ToFileInfo()
                },
                TextSearchCriteria = new TextSearchCriteria
                {
                    SearchText = "Watermark text"
                }
            };

            var request = new ReplaceRequest(options);
            var ex      = Assert.Throws <ApiException>(() => { WatermarkApi.Replace(request); });

            Assert.AreEqual($"Can't find file located at '{testFile.FullName}'.", ex.Message);
        }
Beispiel #14
0
        public void Replace_Watermark_File_Not_Supported()
        {
            var testFile = TestFiles.Zip;
            var options  = new ReplaceOptions
            {
                FileInfo            = testFile.ToFileInfo(),
                ImageSearchCriteria = new ImageSearchCriteria
                {
                    ImageFileInfo = TestFiles.SampleWatermarkTransparent.ToFileInfo()
                },
                TextSearchCriteria = new TextSearchCriteria
                {
                    SearchText = "Watermark text"
                }
            };

            var request = new ReplaceRequest(options);
            var ex      = Assert.Throws <ApiException>(() => { WatermarkApi.Replace(request); });

            Assert.AreEqual($"The specified file '{testFile.FullName}' has type which is not currently supported.", ex.Message);
        }
        public void Remove_Watermark()
        {
            var testFile = TestFiles.PdfWithWatermarks;
            var options  = new RemoveOptions
            {
                FileInfo            = testFile.ToFileInfo(),
                ImageSearchCriteria = new ImageSearchCriteria
                {
                    ImageFileInfo = TestFiles.SampleWatermarkTransparent.ToFileInfo()
                },
                TextSearchCriteria = new TextSearchCriteria
                {
                    SearchText = "Watermark text"
                },
                OutputFolder = "removed_watermarks"
            };
            var request = new RemoveRequest(options);
            var result  = WatermarkApi.Remove(request);

            CheckIfWatermarkNotExist(result.Path, "Watermark text", TestFiles.SampleWatermarkTransparent.ToFileInfo());
        }
        public static void Run()
        {
            var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
            var apiInstance   = new WatermarkApi(configuration);

            try
            {
                var fileInfo = new FileInfo
                {
                    FilePath    = "documents/sample.docx",
                    StorageName = Common.MyStorage
                };

                var options = new WatermarkOptions()
                {
                    FileInfo         = fileInfo,
                    WatermarkDetails = new List <WatermarkDetails>
                    {
                        new WatermarkDetails
                        {
                            TextWatermarkOptions = new TextWatermarkOptions
                            {
                                Text           = "New watermark text",
                                FontFamilyName = "Arial",
                                FontSize       = 12d,
                            }
                        }
                    }
                };

                var request = new AddRequest(options);

                var response = apiInstance.Add(request);
                Console.WriteLine("Resultant file path: " + response.Path);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception while calling WatermarkApi: " + e.Message);
            }
        }
Beispiel #17
0
        public void Add_Watermark_No_Text_And_Image()
        {
            var testFile = TestFiles.Docx;
            var options  = new WatermarkOptions
            {
                FileInfo         = testFile.ToFileInfo(),
                WatermarkDetails = new List <WatermarkDetails>
                {
                    new WatermarkDetails
                    {
                        TextWatermarkOptions = new TextWatermarkOptions
                        {
                            FontFamilyName = "Arial",
                            FontSize       = 18
                        }
                    }
                }
            };

            var request = new AddRequest(options);
            var ex      = Assert.Throws <ApiException>(() => { WatermarkApi.Add(request); });

            Assert.AreEqual("Request parameters missing or have incorrect format", ex.Message);
        }
Beispiel #18
0
        static void Main(string[] args)
        {
            string testFile = null;

            try
            {
                // ** Make sure an api key has been entered
                if (API_KEY == string.Empty)
                {
                    Console.WriteLine("[ERROR] Please update the sample code and enter the API Key that came with your subscription.");
                    return;
                }

                // ** Was a 'file to watermark' specified on the command line?
                if (args.Count() == 0)
                {
                    Console.WriteLine("[INFO] No file to watermark specified, using default file.");
                    testFile = Directory.GetFiles(".", "*.pdf")[0];
                }
                else
                {
                    testFile = args[0];
                }

                // ** Specify the API key associated with your subscription.
                Configuration.Default.AddApiKey("api_key", API_KEY);

                // ** Accept all SSL Certificates, this makes life under mono a lot easier. This line is not needed on Windows
                ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); };

                // ** The service's host name is already set, but for debugging purposes you may want to switch between 'http' and 'https'.'
                Configuration.Default.ApiClient.RestClient.BaseUrl = new Uri("https://api.muhimbi.com/api");

                // ** We are dealing with watermarking, so instantiate the relevant class
                WatermarkApi watermarkAPI = new WatermarkApi();

                // ** Read the file we wish to watermark
                byte[] sourceFile = File.ReadAllBytes(testFile);

                // ** Fill out the data for the watermark operation.
                CompositeWatermarkData inputData = new CompositeWatermarkData(
                    SourceFileName: testFile,                           // ** Always specify a file name with the correct extension (file must be a PDF file when watermarking)
                    SourceFileContent: sourceFile,                      // ** The file content to watermark
                    WatermarkData: File.ReadAllText("watermark.xml")    // ** Load the XML Definition for the composite watermark
                    );

                // ** Watermark the file
                Console.WriteLine("[INFO] Watermarking...");
                var response = watermarkAPI.CompositeWatermark(inputData);

                // ** Write the results back to the file system
                File.WriteAllBytes(@"result.pdf", response.ProcessedFileContent);

                Console.WriteLine("[INFO] 'result.pdf' written to output folder.");

                // ** On Windows open the generated file in the system PDF viewer
                Process.Start(@"result.pdf");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
Beispiel #19
0
        static void Main(string[] args)
        {
            string testFile = null;

            try
            {
                // ** Make sure an api key has been entered
                if (API_KEY == string.Empty)
                {
                    Console.WriteLine("[ERROR] Please update the sample code and enter the API Key that came with your subscription.");
                    return;
                }

                // ** Was a 'file to watermark' specified on the command line?
                if (args.Count() == 0)
                {
                    Console.WriteLine("[INFO] No file to watermark specified, using default file.");
                    testFile = Directory.GetFiles(".", "*.pdf")[0];
                }
                else
                {
                    testFile = args[0];
                }

                // ** Specify the API key associated with your subscription.
                Configuration.Default.AddApiKey("api_key", API_KEY);

                // ** Accept all SSL Certificates, this makes life under mono a lot easier. This line is not needed on Windows
                ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); };

                // ** The service's host name is already set, but for debugging purposes you may want to switch between 'http' and 'https'.'
                Configuration.Default.ApiClient.RestClient.BaseUrl = new Uri("https://api.muhimbi.com/api");

                // ** We are dealing with watermarking, so instantiate the relevant class
                WatermarkApi watermarkAPI = new WatermarkApi();

                // ** Read the file we wish to watermark
                byte[] sourceFile = File.ReadAllBytes(testFile);

                // ** Fill out the data for the watermark operation.
                LineWatermarkData inputData = new LineWatermarkData(
                    SourceFileName: testFile,                                       // ** Always specify a file name with the correct extension (file must be a PDF file when watermarking)
                    SourceFileContent: sourceFile,                                  // ** The file content to watermark
                    Position: LineWatermarkData.PositionEnum.MiddleCenter,          // ** The location where the watermark will be positioned on the page.
                    X: "72",                                                        // ** The x-coordinate of the watermark. Only used when Position is set to Absolute.
                    Y: "72",                                                        // ** The y-coordinate of the watermark. Only used when Position is set to Absolute.
                    EndX: "523",                                                    // ** The end x-coordinate of the line in pts (1/72nd of an inch).
                    EndY: "770",                                                    // ** The end y-coordinate of the line in pts (1/72nd of an inch).
                    Layer: LineWatermarkData.LayerEnum.Foreground,                  // ** Position the watermark in front of the page's content, or behind it
                    Rotation: "0",                                                  // ** Rotate the watermark, specify a value in degrees. Negative values are accepted.
                    Opacity: "50",                                                  // ** A value between 0 (completely transparent) and 100 (fully visible)
                    LineColor: "#000000",                                           // ** The (out)line color of the watermark in #RRGGBB notation.
                    LineWidth: "10",                                                // ** The width of the line in pts (1/72nd of an inch). 0 = hairline, -1 = no line
                    StartPage: 0,                                                   // ** The first page in the document the watermark applies to.
                    EndPage: 0,                                                     // ** The last page in the document the watermark applies to.
                    PageInterval: 1,                                                // ** Which pages to apply the watermark on (1 = every page, 2 = every other page etc).
                    PageOrientation: LineWatermarkData.PageOrientationEnum.Both     // ** The page orientation the watermark applies to.
                    );

                // ** Watermark the file
                Console.WriteLine("[INFO] Watermarking...");
                var response = watermarkAPI.LineWatermark(inputData);

                // ** Write the results back to the file system
                File.WriteAllBytes(@"result.pdf", response.ProcessedFileContent);

                Console.WriteLine("[INFO] 'result.pdf' written to output folder.");

                // ** On Windows open the generated file in the system PDF viewer
                Process.Start(@"result.pdf");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
Beispiel #20
0
 public void Init()
 {
     instance = new WatermarkApi();
 }