public void TestParse_RawTemplate() { var testFile = TestFiles.TemplateDocumentDocx; var options = new ParseOptions { FileInfo = testFile.ToFileInfo(), Template = GetTemplate() }; var request = new ParseRequest(options); var result = ParseApi.Parse(request); Assert.IsNotNull(result); Assert.IsNotEmpty(result.FieldsData); Assert.AreEqual(4, result.Count); var dataFieldNames = new[] { "FIELD1", "RELATEDFIELD2", "REGEX", "TABLECELLS" }; foreach (var field in result.FieldsData) { Assert.IsTrue(dataFieldNames.Contains(field.Name)); } var table = result.FieldsData.First(x => string.Equals(x.Name, "TABLECELLS")).PageArea.PageTableArea; if (table != null) { Assert.AreEqual(4, table.ColumnCount); Assert.AreEqual(3, table.RowCount); Assert.AreEqual( "Cell 12", table.PageTableAreaCells.First(x => x.ColumnIndex == 2 && x.RowIndex == 1).PageArea.PageTextArea.Text); } }
public void TestParse_WithoutOptions() { var testFile = TestFiles.JpegFile; var options = new ParseOptions { FileInfo = testFile.ToFileInfo(), }; var request = new ParseRequest(options); var ex = Assert.Throws <ApiException>(() => { ParseApi.Parse(request); }); Assert.AreEqual("Request parameters missing or have incorrect format", ex.Message); }
public void TestParse_FileNotFoundResult() { var testFile = TestFiles.NotExist; var options = new ParseOptions { FileInfo = testFile.ToFileInfo(), TemplatePath = "templates/document-template.json", Template = GetTemplate() }; var request = new ParseRequest(options); var ex = Assert.Throws <ApiException>(() => { ParseApi.Parse(request); }); Assert.AreEqual($"Can't find file located at '{testFile.FullName}'.", ex.Message); }
public void TestParse_NotSupportedFile() { var testFile = TestFiles.JpegFile; var options = new ParseOptions { FileInfo = testFile.ToFileInfo(), TemplatePath = "templates/document-template.json", Template = GetTemplate() }; var request = new ParseRequest(options); var ex = Assert.Throws <ApiException>(() => { ParseApi.Parse(request); }); Assert.AreEqual($"The specified file '{testFile.FullName}' has type which is not currently supported.", ex.Message); }
public void TestParse_IncorrectPassword() { var testFile = TestFiles.PasswordProtected; var options = new ParseOptions { FileInfo = testFile.ToFileInfo(), TemplatePath = "templates/document-template.json", Template = GetTemplate() }; options.FileInfo.Password = "******"; var request = new ParseRequest(options); var ex = Assert.Throws <ApiException>(() => { ParseApi.Parse(request); }); Assert.AreEqual($"Password provided for file '{testFile.FullName}' is incorrect.", ex.Message); }
public static void Run() { var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey); var apiInstance = new ParseApi(configuration); try { var options = new ParseOptions { FileInfo = new FileInfo { FilePath = "containers/archive/companies.zip", StorageName = Common.MyStorage }, ContainerItemInfo = new ContainerItemInfo { RelativePath = "companies.docx" }, Template = TemplateUtils.GetTemplate() }; var request = new ParseRequest(options); var response = apiInstance.Parse(request); foreach (var data in response.FieldsData) { if (data.PageArea.PageTextArea != null) { Console.WriteLine($"Field name: {data.Name}. Text : {data.PageArea.PageTextArea.Text}"); } if (data.PageArea.PageTableArea != null) { Console.WriteLine($"Table name: {data.Name}."); foreach (var cell in data.PageArea.PageTableArea.PageTableAreaCells) { Console.WriteLine( $"Table cell. Row {cell.RowIndex} column {cell.ColumnIndex}. Text: {cell.PageArea.PageTextArea.Text}"); } } } } catch (Exception e) { Console.WriteLine("Exception while calling ParseApi: " + e.Message); } }
public static void Run() { // For example purposes create template if not exists. TemplateUtils.CreateIfNotExist("templates/companies.json"); var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey); var apiInstance = new ParseApi(configuration); try { var options = new ParseOptions { FileInfo = new FileInfo { FilePath = "words-processing/docx/companies.docx", StorageName = Common.MyStorage }, TemplatePath = "templates/companies.json" }; var request = new ParseRequest(options); var response = apiInstance.Parse(request); foreach (var data in response.FieldsData) { if (data.PageArea.PageTextArea != null) { Console.WriteLine($"Field name: {data.Name}. Text : {data.PageArea.PageTextArea.Text}"); } if (data.PageArea.PageTableArea != null) { Console.WriteLine($"Table name: {data.Name}."); foreach (var cell in data.PageArea.PageTableArea.PageTableAreaCells) { Console.WriteLine( $"Table cell. Row {cell.RowIndex} column {cell.ColumnIndex}. Text: {cell.PageArea.PageTextArea.Text}"); } } } } catch (Exception e) { Console.WriteLine("Exception while calling ParseApi: " + e.Message); } }