public static void Run()
        {
            var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
            var apiInstance   = new ParseApi(configuration);

            try
            {
                var options = new ImagesOptions()
                {
                    FileInfo = new FileInfo
                    {
                        FilePath    = "slides/three-slides.pptx",
                        StorageName = Common.MyStorage
                    },
                    StartPageNumber     = 1,
                    CountPagesToExtract = 2
                };

                var request  = new ImagesRequest(options);
                var response = apiInstance.Images(request);
                foreach (var page in response.Pages)
                {
                    Console.WriteLine($"Images from {page.PageIndex} page.");
                    foreach (var image in page.Images)
                    {
                        Console.WriteLine($"Image path in storage: {image.Path}. Download url: {image.DownloadUrl}");
                        Console.WriteLine($"File format: {image.FileFormat}. Page index: {image.PageIndex}");
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception while calling ParseApi: " + e.Message);
            }
        }
예제 #2
0
        public void TestGetImage_FileNotFoundResult()
        {
            var testFile = TestFiles.NotExist;
            var options  = new ImagesOptions
            {
                FileInfo = testFile.ToFileInfo(),
            };
            var request = new ImagesRequest(options);
            var ex      = Assert.Throws <ApiException>(() => { ParseApi.Images(request); });

            Assert.AreEqual($"Can't find file located at '{testFile.FullName}'.", ex.Message);
        }
예제 #3
0
        public void ImageExtractTest_Pdf_Container_FromPages_Error()
        {
            var testFile = TestFiles.Zip;
            var options  = new ImagesOptions
            {
                FileInfo            = testFile.ToFileInfo(),
                StartPageNumber     = 1,
                CountPagesToExtract = 2
            };

            var request = new ImagesRequest(options);
            var ex      = Assert.Throws <ApiException>(() => { ParseApi.Images(request); });

            Assert.AreEqual($"The specified file '{testFile.FullName}' has type which is not currently supported.", ex.Message);
        }
예제 #4
0
        public void ImageExtractTest_Pdf_FromPages_OutOfThePageRange()
        {
            var testFile = TestFiles.Pdf;
            var options  = new ImagesOptions
            {
                FileInfo            = testFile.ToFileInfo(),
                StartPageNumber     = 3,
                CountPagesToExtract = 5
            };

            var request = new ImagesRequest(options);
            var ex      = Assert.Throws <ApiException>(() => { ParseApi.Images(request); });

            Assert.AreEqual("Request parameters missing or have incorrect format", ex.Message);
        }
예제 #5
0
        public void TestGetImage_IncorrectPassword()
        {
            var testFile = TestFiles.PasswordProtected;
            var options  = new ImagesOptions
            {
                FileInfo = new FileInfo {
                    FilePath = testFile.FullName, Password = "******"
                },
            };
            var request = new ImagesRequest(options);

            var ex = Assert.Throws <ApiException>(() => { ParseApi.Images(request); });

            Assert.AreEqual($"Password provided for file '{testFile.FullName}' is incorrect.", ex.Message);
        }
예제 #6
0
        public void TestGetImage_Docx()
        {
            var testFile = TestFiles.FourPages;
            var options  = new ImagesOptions
            {
                FileInfo = testFile.ToFileInfo(),
            };
            var request = new ImagesRequest(options);
            var result  = ParseApi.Images(request);

            Assert.IsNotNull(result);
            int i = 0;

            foreach (var image in result.Images)
            {
                Assert.AreEqual($"parser/images/words/docx/four-pages_docx/image_{i}.jpeg", image.Path);
                Assert.NotNull(image.DownloadUrl);
                i++;
            }
        }
예제 #7
0
        public void TestGetImage_Pdf_FromPages()
        {
            var testFile = TestFiles.Pdf;
            var options  = new ImagesOptions
            {
                FileInfo            = testFile.ToFileInfo(),
                StartPageNumber     = 1,
                CountPagesToExtract = 2
            };

            var request = new ImagesRequest(options);
            var result  = ParseApi.Images(request);

            Assert.IsNotNull(result);
            Assert.IsNotEmpty(result.Pages);
            Assert.AreEqual(2, result.Pages.Count);

            Assert.AreEqual("parser/images/pdf/template-document_pdf/page_1/image_0.jpeg", result.Pages[0].Images[0].Path);
            Assert.AreEqual("parser/images/pdf/template-document_pdf/page_2/image_0.jpeg", result.Pages[1].Images[0].Path);
        }
예제 #8
0
        public void TestGetImage_Email()
        {
            var testFile = TestFiles.ImageAndAttachment;
            var options  = new ImagesOptions
            {
                FileInfo = testFile.ToFileInfo(),
            };
            var request = new ImagesRequest(options);
            var result  = ParseApi.Images(request);

            Assert.IsNotNull(result);
            var paths = new[]
            {
                "parser/images/email/eml/embedded-image-and-attachment_eml/",
            };

            foreach (var image in result.Images)
            {
                Assert.IsTrue(paths.Any(image.Path.Contains));
            }
        }
        public static void Run()
        {
            var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
            var apiInstance   = new ParseApi(configuration);

            try
            {
                var options = new ImagesOptions()
                {
                    FileInfo = new FileInfo
                    {
                        FilePath    = "pdf/PDF with attachements.pdf",
                        Password    = "******",
                        StorageName = Common.MyStorage
                    },
                    ContainerItemInfo = new ContainerItemInfo {
                        RelativePath = "template-document.pdf"
                    },
                    StartPageNumber     = 2,
                    CountPagesToExtract = 1
                };

                var request  = new ImagesRequest(options);
                var response = apiInstance.Images(request);
                foreach (var page in response.Pages)
                {
                    Console.WriteLine($"Images from {page.PageIndex} page.");
                    foreach (var image in page.Images)
                    {
                        Console.WriteLine($"Image path in storage: {image.Path}. Download url: {image.DownloadUrl}");
                        Console.WriteLine($"File format: {image.FileFormat}. Page index: {image.PageIndex}");
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception while calling ParseApi: " + e.Message);
            }
        }
예제 #10
0
        public void TestGetImage_Container()
        {
            var testFile = TestFiles.ZipWithEmailImagePdf;
            var options  = new ImagesOptions
            {
                FileInfo = testFile.ToFileInfo(),
            };
            var request = new ImagesRequest(options);
            var result  = ParseApi.Images(request);

            Assert.IsNotNull(result);
            var paths = new[]
            {
                "parser/images/containers/archive/zip-eml-jpg-pdf_zip/",
                "parser/images/containers/archive/zip-eml-jpg-pdf_zip/embedded-image-and-attachment_eml/",
                "parser/images/containers/archive/zip-eml-jpg-pdf_zip/template-document_pdf/"
            };

            foreach (var image in result.Images)
            {
                Assert.IsTrue(paths.Any(image.Path.Contains));
            }
        }
예제 #11
0
        public void ImageExtractTest_Pdf_ContainerItem_FromPages()
        {
            var testFile = TestFiles.PdfContainer;
            var options  = new ImagesOptions
            {
                FileInfo            = testFile.ToFileInfo(),
                StartPageNumber     = 1,
                CountPagesToExtract = 2,
                ContainerItemInfo   = new ContainerItemInfo {
                    RelativePath = "template-document.pdf"
                }
            };

            var request = new ImagesRequest(options);
            var result  = ParseApi.Images(request);

            Assert.IsNotNull(result);
            Assert.IsNotEmpty(result.Pages);
            Assert.AreEqual(2, result.Pages.Count);

            Assert.AreEqual("parser/images/template-document_pdf/page_1/image_0.jpeg", result.Pages[0].Images[0].Path);
            Assert.AreEqual("parser/images/template-document_pdf/page_2/image_0.jpeg", result.Pages[1].Images[0].Path);
        }