public async Task When_server_only_supports_one_OCR_language() { mockServer .Given(Request.Create().WithPath("/v2/contentConverters").UsingPost()) .RespondWith(Response.Create() .WithStatusCode(480) .WithHeader("Content-Type", "application/json") .WithBody("{\"errorCode\":\"InvalidInput\",\"errorDetails\":{\"in\":\"body\",\"at\":\"input.dest.pdfOptions.ocr.language\",\"expected\":{\"enum\": [\"english\"]}}}")); var dummyInput = new ConversionSourceDocument(new RemoteWorkFile(null, null, null, null)); await UtilAssert.ThrowsExceptionWithMessageAsync <RestApiErrorException>( async() => { await prizmDocServer.ConvertAsync(dummyInput, new DestinationOptions(DestinationFileFormat.Pdf) { PdfOptions = new PdfDestinationOptions { Ocr = new OcrOptions { Language = "hylian", }, }, }); }, "Unsupported OCR language \"hylian\". The remote server only supports the following OCR languages: \"english\"."); }
public async Task Multiple_to_SVG() { await UtilAssert.ThrowsExceptionWithMessageAsync <RestApiErrorException>( async() => { await prizmDocServer.ConvertAsync( new List <ConversionSourceDocument> { new ConversionSourceDocument("documents/example.docx"), new ConversionSourceDocument("documents/example.pdf"), }, new DestinationOptions(DestinationFileFormat.Svg)); }, "Remote server does not support combining multiple ConversionSourceDocument instances to SVG. When converting to SVG, use a single ConversionSourceDocument."); }
public async Task When_requesting_PDF_OCR_but_the_feature_is_not_licensed() { mockServer .Given(Request.Create().WithPath("/v2/contentConverters").UsingPost()) .RespondWith(Response.Create() .WithStatusCode(480) .WithHeader("Content-Type", "application/json") .WithBody("{\"errorCode\":\"FeatureNotLicensed\",\"errorDetails\":{\"in\":\"body\",\"at\":\"input.dest.pdfOptions.ocr\"}}")); var dummyInput = new ConversionSourceDocument(new RemoteWorkFile(null, null, null, null)); await UtilAssert.ThrowsExceptionWithMessageAsync <RestApiErrorException>( async() => { await prizmDocServer.ConvertAsync(dummyInput, new DestinationOptions(DestinationFileFormat.Pdf) { PdfOptions = new PdfDestinationOptions { Ocr = new OcrOptions { Language = "english", }, }, }); }, "Remote server is not licensed to perform OCR when producing PDF output."); }
public async Task With_footer() { PrizmDocServerClient prizmDocServer = Util.CreatePrizmDocServerClient(); ConversionResult result = (await prizmDocServer.ConvertAsync("documents/example.docx", new DestinationOptions(DestinationFileFormat.Tiff) { Footer = new HeaderFooterOptions() { Lines = new List<HeaderFooterLine>() { new HeaderFooterLine() { Left = "Bottom Left", Center = "THIS IS FOOTER CONTENT", Right = "Bottom Right", }, }, }, })).Single(); result = await prizmDocServer.OcrToPdfAsync(new ConversionSourceDocument(result.RemoteWorkFile)); string[] pagesText = await TextUtil.ExtractPagesText(result.RemoteWorkFile); foreach (string page in pagesText) { StringAssert.Contains(page, "Bottom Left"); StringAssert.Contains(page, "THIS IS FOOTER CONTENT"); StringAssert.Contains(page, "Bottom Right"); } }
public async Task When_applying_a_footer_to_multiple_sources() { PrizmDocServerClient prizmDocServer = Util.CreatePrizmDocServerClient(); await UtilAssert.ThrowsExceptionWithMessageAsync <RestApiErrorException>( async() => { await prizmDocServer.ConvertAsync( new List <ConversionSourceDocument> { new ConversionSourceDocument("documents/example.pdf"), new ConversionSourceDocument("documents/example.pdf"), new ConversionSourceDocument("documents/example.pdf"), }, new DestinationOptions(DestinationFileFormat.Pdf) { Footer = new HeaderFooterOptions() { Lines = new List <HeaderFooterLine>() { new HeaderFooterLine() { Left = "Acme" }, }, }, }); }, "Remote server does not support applying headers or footers when using multiple ConversionSourceDocument instances. To apply headers or footers, use a single ConversionSourceDocument instance."); }
private static async Task MainAsync() { File.Delete("thumbnail.png"); var prizmDocServer = new PrizmDocServerClient(Environment.GetEnvironmentVariable("BASE_URL"), Environment.GetEnvironmentVariable("API_KEY")); // PrizmDoc Server does not currently allow you to extract pages // and convert to PNG in a single operation. But you can still get // a first-page thumbnail efficiently as a two-step process: // // 1. Extract just the first page as a PDF (which you never need to download) // 2. Convert that PDF to a thumbnail PNG // Extract the first page as an intermediate PDF. We won't ever bother // downloading this from PrizmDoc Server. ConversionResult tempFirstPagePdf = await prizmDocServer.ConvertToPdfAsync(new ConversionSourceDocument("project-proposal.docx", pages : "1")); // Convert the PDF to PNGs, specifying a max width and height. We'll get // back a collection of results, one per page. In our case, there is only // one page. IEnumerable <ConversionResult> thumbnailPngs = await prizmDocServer.ConvertAsync(new ConversionSourceDocument(tempFirstPagePdf.RemoteWorkFile), new DestinationOptions(DestinationFileFormat.Png) { PngOptions = new PngDestinationOptions() { MaxWidth = "512px", MaxHeight = "512px", }, }); // Save the single result. await thumbnailPngs.Single().RemoteWorkFile.SaveAsync("thumbnail.png"); }
public async Task When_there_are_multiple_source_inputs() { PrizmDocServerClient prizmDocServer = Util.CreatePrizmDocServerClient(); var source1 = new ConversionSourceDocument("documents/example.pdf"); var source2 = new ConversionSourceDocument("documents/example.pdf", pages: "97-99"); var source3 = new ConversionSourceDocument("documents/example.pdf"); IEnumerable <ConversionResult> results = await prizmDocServer.ConvertAsync( new List <ConversionSourceDocument> { source1, source2, source3, }, new DestinationOptions(DestinationFileFormat.Pdf) { PdfOptions = new PdfDestinationOptions() { ForceOneFilePerPage = true, }, }); Assert.AreEqual(7, results.Count()); AssertSuccessResult(results.ElementAt(0), "1", source1); AssertSuccessResult(results.ElementAt(1), "2", source1); AssertErrorResult(results.ElementAt(2), "NoSuchPage", "97", source2); AssertErrorResult(results.ElementAt(3), "NoSuchPage", "98", source2); AssertErrorResult(results.ElementAt(4), "NoSuchPage", "99", source2); AssertSuccessResult(results.ElementAt(5), "1", source3); AssertSuccessResult(results.ElementAt(6), "2", source3); }
public async Task Document_passwords_are_not_included_in_results() { PrizmDocServerClient prizmDocServer = Util.CreatePrizmDocServerClient(); IEnumerable <ConversionResult> results = await prizmDocServer.ConvertAsync(new ConversionSourceDocument("documents/password.docx", password : "******"), new DestinationOptions(DestinationFileFormat.Pdf)); Assert.IsNull(results.Single().Sources.Single().Password); }
public async Task With_local_file_path() { PrizmDocServerClient prizmDocServer = Util.CreatePrizmDocServerClient(); IEnumerable <ConversionResult> results = await prizmDocServer.ConvertAsync("documents/example.docx", DestinationFileFormat.Png); Assert.AreEqual(2, results.Count(), "Wrong number of results"); await this.AssertSinglePagePngResultsAsync(results); }
public async Task When_single_input_work_file_does_not_exist() { mockServer .Given(Request.Create().WithPath("/v2/contentConverters").UsingPost()) .RespondWith(Response.Create() .WithStatusCode(480) .WithHeader("Content-Type", "application/json") .WithBody("{\"input\":{\"dest\":{\"format\":\"pdf\",\"pdfOptions\":{\"forceOneFilePerPage\":false}},\"sources\":[{\"fileId\":\"ML3AbF-qzIH5K9mVVxTlBX\",\"pages\":\"\"}]},\"minSecondsAvailable\":18000,\"errorCode\":\"WorkFileDoesNotExist\",\"errorDetails\":{\"in\":\"body\",\"at\":\"input.sources[0].fileId\"}}")); var originalRemoteWorkFile = new RemoteWorkFile(null, "ML3AbF-qzIH5K9mVVxTlBX", "FCnaLL517YPRAnrcX2wlnKURpNPsp2d2pMPkcvCcpdY=", "docx"); var originalConversionInput = new ConversionSourceDocument(originalRemoteWorkFile); await UtilAssert.ThrowsExceptionWithMessageAsync <RestApiErrorException>( async() => { await prizmDocServer.ConvertAsync(originalConversionInput, new DestinationOptions(DestinationFileFormat.Pdf)); }, "ConversionSourceDocument refers to a remote work file which does not exist. It may have expired."); }
public async Task CAD_to_TIFF() { PrizmDocServerClient prizmDocServer = Util.CreatePrizmDocServerClient(); await UtilAssert.ThrowsExceptionWithMessageAsync <RestApiErrorException>( async() => { await prizmDocServer.ConvertAsync(new ConversionSourceDocument("documents/example.dwg"), new DestinationOptions(DestinationFileFormat.Tiff)); }, "When converting a CAD ConversionSourceDocument to TIFF, you must specify TiffOptions.MaxWidth or TiffOptions.MaxHeight."); }
public async Task When_using_a_single_source_input() { PrizmDocServerClient prizmDocServer = Util.CreatePrizmDocServerClient(); await UtilAssert.ThrowsExceptionWithMessageAsync <RestApiErrorException>( async() => { await prizmDocServer.ConvertAsync(new ConversionSourceDocument("documents/example.pdf", pages: "wat"), new DestinationOptions(DestinationFileFormat.Pdf)); }, "ConversionSourceDocument (\"documents/example.pdf\") has an invalid value for \"pages\". A valid pages value is a string like \"1\", \"1,3,5-10\", or \"2-\" (just like in a print dialog)."); }
public async Task When_using_a_single_password_protected_source_document_and_the_wrong_password_is_given() { PrizmDocServerClient prizmDocServer = Util.CreatePrizmDocServerClient(); await UtilAssert.ThrowsExceptionWithMessageAsync <RestApiErrorException>( async() => { await prizmDocServer.ConvertAsync(new ConversionSourceDocument("documents/password.docx", password: "******"), new DestinationOptions(DestinationFileFormat.Pdf)); }, "Invalid password for ConversionSourceDocument (\"documents/password.docx\")."); }
public async Task When_using_a_single_source_input() { PrizmDocServerClient prizmDocServer = Util.CreatePrizmDocServerClient(); // This assertion is coupled to what is currently supported in the product. It would be better if we used a mock for this test. await UtilAssert.ThrowsExceptionWithMessageAsync <RestApiErrorException>( async() => { await prizmDocServer.ConvertAsync(new ConversionSourceDocument("documents/example.mp3"), new DestinationOptions(DestinationFileFormat.Pdf)); }, "Unsupported file format \"mp3\". The remote server only supports the following input file formats: \"bmp\", \"cal\", \"cals\", \"csv\", \"cur\", \"cut\", \"dcim\", \"dcm\", \"dcx\", \"dgn\", \"dib\", \"dicm\", \"dicom\", \"doc\", \"docm\", \"docx\", \"dot\", \"dotm\", \"dotx\", \"dwf\", \"dwg\", \"dxf\", \"eml\", \"emz\", \"fodg\", \"fodp\", \"fods\", \"fodt\", \"gif\", \"htm\", \"html\", \"ico\", \"img\", \"jp2\", \"jpc\", \"jpeg\", \"jpg\", \"jpx\", \"msg\", \"ncr\", \"odg\", \"odp\", \"ods\", \"odt\", \"otg\", \"otp\", \"ots\", \"ott\", \"pbm\", \"pcd\", \"pct\", \"pcx\", \"pdf\", \"pgm\", \"pic\", \"pict\", \"png\", \"pot\", \"potm\", \"potx\", \"ppm\", \"pps\", \"ppsm\", \"ppsx\", \"ppt\", \"pptm\", \"pptx\", \"psb\", \"psd\", \"ras\", \"rtf\", \"sct\", \"sgi\", \"tga\", \"tif\", \"tiff\", \"tpic\", \"txt\", \"vdx\", \"vsd\", \"vsdm\", \"vsdx\", \"wbmp\", \"wmf\", \"wmz\", \"wpg\", \"xbm\", \"xhtml\", \"xls\", \"xlsm\", \"xlsx\", \"xlt\", \"xltm\", \"xltx\", \"xwd\""); }
private static async Task MainAsync() { var prizmDocServer = new PrizmDocServerClient(Environment.GetEnvironmentVariable("BASE_URL"), Environment.GetEnvironmentVariable("API_KEY")); // Take a DOCX file and convert each of its pages to a PNG. IEnumerable <ConversionResult> results = await prizmDocServer.ConvertAsync("project-proposal.docx", DestinationFileFormat.Png); // Save each result to a PNG file. for (int i = 0; i < results.Count(); i++) { await results.ElementAt(i).RemoteWorkFile.SaveAsync($"page-{i + 1}.png"); } }
public async Task Footer_with_JPEG_output() { PrizmDocServerClient prizmDocServer = Util.CreatePrizmDocServerClient(); await UtilAssert.ThrowsExceptionWithMessageAsync <RestApiErrorException>( async() => { await prizmDocServer.ConvertAsync("documents/example.pdf", new DestinationOptions(DestinationFileFormat.Jpeg) { Footer = this.exampleHeaderFooterContent }); }, "Remote server does not support applying headers or footers when producing JPEG output."); }
public async Task With_local_file_path() { PrizmDocServerClient prizmDocServer = Util.CreatePrizmDocServerClient(); IEnumerable <ConversionResult> results = await prizmDocServer.ConvertAsync("documents/example.docx", new DestinationOptions(DestinationFileFormat.Tiff) { TiffOptions = new TiffDestinationOptions() { ForceOneFilePerPage = true, }, }); Assert.AreEqual(2, results.Count(), "Wrong number of results"); await this.AssertSinglePageTiffResultsAsync(results); }
public async Task With_local_file_path() { PrizmDocServerClient prizmDocServer = Util.CreatePrizmDocServerClient(); ConversionResult result = (await prizmDocServer.ConvertAsync("documents/example.docx", DestinationFileFormat.Tiff)).Single(); Assert.IsTrue(result.IsSuccess); Assert.AreEqual(2, result.PageCount); ConversionSourceDocument resultSourceDocument = result.Sources.ToList()[0]; Assert.IsNotNull(resultSourceDocument.RemoteWorkFile); Assert.IsNull(resultSourceDocument.Password); Assert.AreEqual("1-2", resultSourceDocument.Pages); await result.RemoteWorkFile.SaveAsync("output.tiff"); FileAssert.IsTiff("output.tiff"); }
public async Task TIFF_bad_MaxHeight() { PrizmDocServerClient prizmDocServer = Util.CreatePrizmDocServerClient(); await UtilAssert.ThrowsExceptionWithMessageAsync <RestApiErrorException>( async() => { await prizmDocServer.ConvertAsync("documents/example.pdf", new DestinationOptions(DestinationFileFormat.Tiff) { TiffOptions = new TiffDestinationOptions { MaxHeight = "wat" }, }); }, $"Invalid TiffOptions.MaxHeight for remote server: \"wat\". Try using a CSS-style string, like \"600px\"."); }
public async Task PNG_bad_MaxWidth() { PrizmDocServerClient prizmDocServer = Util.CreatePrizmDocServerClient(); await UtilAssert.ThrowsExceptionWithMessageAsync <RestApiErrorException>( async() => { await prizmDocServer.ConvertAsync("documents/example.pdf", new DestinationOptions(DestinationFileFormat.Png) { PngOptions = new PngDestinationOptions { MaxWidth = "wat" }, }); }, $"Invalid PngOptions.MaxWidth for remote server: \"wat\". Try using a CSS-style string, like \"800px\"."); }
public async Task When_attempting_to_convert_only_page_1_to_PNG() { PrizmDocServerClient prizmDocServer = Util.CreatePrizmDocServerClient(); // In this case, the REST API actually returns 200 and begins the // conversion. However, it does not actually honor the source "pages" // value. To avoid a breaking change for the SDK consumer, the SDK ensures // that the "pages" value was not ignored. If it was, it throws this // artificial error, preventing the caller from getting unexpected // results. await UtilAssert.ThrowsExceptionWithMessageAsync <RestApiErrorException>( async() => { await prizmDocServer.ConvertAsync(new ConversionSourceDocument("documents/example.docx", pages: "1"), DestinationFileFormat.Png); }, $"Remote server does not support taking only specific pages of a source document when the destination type is PNG."); }
public async Task Footer_with_TIFF_output_with_force_one_file_per_page() { PrizmDocServerClient prizmDocServer = Util.CreatePrizmDocServerClient(); await UtilAssert.ThrowsExceptionWithMessageAsync <RestApiErrorException>( async() => { await prizmDocServer.ConvertAsync("documents/example.pdf", new DestinationOptions(DestinationFileFormat.Tiff) { TiffOptions = new TiffDestinationOptions { ForceOneFilePerPage = true }, Footer = this.exampleHeaderFooterContent, }); }, "Remote server does not support applying headers or footers when TiffOptions.ForceOneFilePerPage is set to true."); }
public async Task Just_the_first_page() { PrizmDocServerClient prizmDocServer = Util.CreatePrizmDocServerClient(); ConversionSourceDocument sourceDocument = new ConversionSourceDocument("documents/example.docx", pages: "1"); ConversionResult result = (await prizmDocServer.ConvertAsync(sourceDocument, DestinationFileFormat.Tiff)).Single(); Assert.IsTrue(result.IsSuccess); Assert.AreEqual(1, result.PageCount); ConversionSourceDocument resultSourceDocument = result.Sources.ToList()[0]; Assert.AreEqual(sourceDocument.RemoteWorkFile, resultSourceDocument.RemoteWorkFile); Assert.IsNull(resultSourceDocument.Password); Assert.AreEqual("1", resultSourceDocument.Pages); await result.RemoteWorkFile.SaveAsync("output.tiff"); FileAssert.IsTiff("output.tiff"); }
public async Task When_the_password_protected_source_document_is_one_of_several_source_documents_and_no_password_is_given() { PrizmDocServerClient prizmDocServer = Util.CreatePrizmDocServerClient(); await UtilAssert.ThrowsExceptionWithMessageAsync <RestApiErrorException>( async() => { await prizmDocServer.ConvertAsync( new List <ConversionSourceDocument> { new ConversionSourceDocument("documents/example.pdf"), new ConversionSourceDocument("documents/password.docx"), new ConversionSourceDocument("documents/example.pdf"), }, new DestinationOptions(DestinationFileFormat.Pdf)); }, "Password required for ConversionSourceDocument at index 1 (\"documents/password.docx\")."); }
public async Task When_the_product_is_not_licensed() { mockServer .Given(Request.Create().WithPath("/v2/contentConverters").UsingPost()) .RespondWith(Response.Create() .WithStatusCode(480) .WithHeader("Content-Type", "application/json") .WithBody("{\"errorCode\":\"LicenseCouldNotBeVerified\"}")); var dummyInput = new ConversionSourceDocument(new RemoteWorkFile(null, null, null, null)); await UtilAssert.ThrowsExceptionWithMessageAsync <RestApiErrorException>( async() => { await prizmDocServer.ConvertAsync(dummyInput, new DestinationOptions(DestinationFileFormat.Pdf)); }, "Remote server does not have a valid license."); }
public async Task With_maxHeight_set_to_150px() { PrizmDocServerClient prizmDocServer = Util.CreatePrizmDocServerClient(); ConversionResult result = (await prizmDocServer.ConvertAsync("documents/example.docx", new DestinationOptions(DestinationFileFormat.Tiff) { TiffOptions = new TiffDestinationOptions() { MaxHeight = "150px", }, })).Single(); await result.RemoteWorkFile.SaveAsync("output.tiff"); IEnumerable<ImageDimensions> pagesDimensions = await ImageUtil.GetTiffPagesDimensionsAsync("output.tiff"); foreach (ImageDimensions dimensions in pagesDimensions) { Assert.AreEqual(150, dimensions.Height); } }
public async Task Final_status_is_something_other_than_complete_there_there_is_no_errorCode() { mockServer .Given(Request.Create().WithPath("/v2/contentConverters/fake-process-id").UsingGet()) .RespondWith(Response.Create() .WithStatusCode(200) .WithHeader("Content-Type", "application/json") .WithBody("{\"processId\":\"fake-process-id\",\"expirationDateTime\":\"2020-01-06T16:50:45.637Z\",\"state\":\"dead\",\"percentComplete\":100}")); string[] expectedStringsContainedInErrorMessage = new[] { @"Unexpected conversion state ""dead""", @"{""processId"":""fake-process-id"",""expirationDateTime"":""2020-01-06T16:50:45.637Z"",""state"":""dead"",""percentComplete"":100}", }; await UtilAssert.ThrowsExceptionWithMessageContainingAsync <RestApiErrorException>( async() => { await prizmDocServer.ConvertAsync("documents/example.pdf", DestinationFileFormat.Pdf); }, expectedStringsContainedInErrorMessage); }
public async Task With_maxHeight_set_to_150px() { PrizmDocServerClient prizmDocServer = Util.CreatePrizmDocServerClient(); IEnumerable <ConversionResult> results = await prizmDocServer.ConvertAsync("documents/example.docx", new DestinationOptions(DestinationFileFormat.Png) { PngOptions = new PngDestinationOptions() { MaxHeight = "150px", }, }); Assert.AreEqual(2, results.Count(), "Wrong number of results"); await this.AssertSinglePagePngResultsAsync(results, filename => { ImageDimensions dimensions = ImageUtil.GetImageDimensions(filename); Assert.AreEqual(150, dimensions.Height); }); }
public async Task With_maxWidth_640px_and_maxHeight_480px() { PrizmDocServerClient prizmDocServer = Util.CreatePrizmDocServerClient(); ConversionResult result = (await prizmDocServer.ConvertAsync("documents/example.docx", new DestinationOptions(DestinationFileFormat.Tiff) { TiffOptions = new TiffDestinationOptions() { MaxWidth = "640px", MaxHeight = "480px", }, })).Single(); await result.RemoteWorkFile.SaveAsync("output.tiff"); IEnumerable<ImageDimensions> pagesDimensions = await ImageUtil.GetTiffPagesDimensionsAsync("output.tiff"); foreach (ImageDimensions dimensions in pagesDimensions) { Assert.IsTrue(dimensions.Width <= 640); Assert.IsTrue(dimensions.Height <= 480); } }
public async Task With_maxHeight_set_to_150px() { PrizmDocServerClient prizmDocServer = Util.CreatePrizmDocServerClient(); IEnumerable <ConversionResult> results = await prizmDocServer.ConvertAsync("documents/example.docx", new DestinationOptions(DestinationFileFormat.Tiff) { TiffOptions = new TiffDestinationOptions() { ForceOneFilePerPage = true, MaxHeight = "150px", }, }); Assert.AreEqual(2, results.Count(), "Wrong number of results"); await this.AssertSinglePageTiffResultsAsync(results, async filename => { ImageDimensions dimensions = (await ImageUtil.GetTiffPagesDimensionsAsync(filename)).Single(); Assert.AreEqual(150, dimensions.Height); }); }