Пример #1
0
        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);
        }
Пример #2
0
        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.");
        }
        public async Task With_footer()
        {
            PrizmDocServerClient prizmDocServer = Util.CreatePrizmDocServerClient();
            ConversionResult     result         = await prizmDocServer.ConvertToPdfAsync("documents/example.docx", footer : new HeaderFooterOptions()
            {
                Lines = new List <HeaderFooterLine>()
                {
                    new HeaderFooterLine()
                    {
                        Left   = "Bottom Left",
                        Center = "THIS IS FOOTER CONTENT",
                        Right  = "Bottom Right",
                    },
                },
            });

            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");
            }
        }
Пример #4
0
        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");
        }
Пример #5
0
        public async Task With_header()
        {
            PrizmDocServerClient prizmDocServer = Util.CreatePrizmDocServerClient();
            ConversionResult result = (await prizmDocServer.ConvertAsync("documents/example.docx", new DestinationOptions(DestinationFileFormat.Tiff)
            {
                Header = new HeaderFooterOptions()
                {
                    Lines = new List<HeaderFooterLine>()
                    {
                        new HeaderFooterLine()
                        {
                            Left = "Top Left",
                            Center = "THIS IS HEADER CONTENT",
                            Right = "Top 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, "Top Left");
                StringAssert.Contains(page, "THIS IS HEADER CONTENT");
                StringAssert.Contains(page, "Top Right");
            }
        }
        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 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 RedactToPlainTextAsync_fails_with_a_useful_error_message_when_an_unsupported_line_ending_is_used()
        {
            PrizmDocServerClient prizmDocServer = Util.CreatePrizmDocServerClient();

            await UtilAssert.ThrowsExceptionWithMessageAsync <RestApiErrorException>(
                async() =>
            {
                await prizmDocServer.RedactToPlainTextAsync("documents/confidential-contacts.pdf", "documents/confidential-contacts.pdf.markup.json", "wat");
            }, "Unsupported line ending \"wat\". The remote server only supports the following values: \"\\n\", \"\\r\\n\".");
        }
Пример #10
0
        public async Task RedactToPlainTextAsync_fails_with_a_useful_error_message_when_the_markup_json_file_is_not_actually_JSON()
        {
            PrizmDocServerClient prizmDocServer = Util.CreatePrizmDocServerClient();

            await UtilAssert.ThrowsExceptionWithMessageAsync <RestApiErrorException>(
                async() =>
            {
                await prizmDocServer.RedactToPlainTextAsync("documents/confidential-contacts.pdf", "documents/example.docx", "\n");
            }, "The remove server was unable to burn the markup file into the document because the markup file was not valid JSON.");
        }
Пример #11
0
        public async Task BurnMarkupAsync_fails_with_a_useful_error_message_when_the_markup_json_file_is_not_actually_JSON()
        {
            PrizmDocServerClient prizmDocServer = Util.CreatePrizmDocServerClient();

            await UtilAssert.ThrowsExceptionWithMessageAsync <RestApiErrorException>(
                async() =>
            {
                await prizmDocServer.BurnMarkupAsync("documents/confidential-contacts.pdf", "documents/example.docx");
            }, "The remote server was unable to burn the markup file into the document. It is possible there is a problem with the markup JSON or with the document itself.");
        }
        public async Task BurnMarkupAsync_fails_with_a_useful_error_message_when_the_source_document_is_unusable()
        {
            PrizmDocServerClient prizmDocServer = Util.CreatePrizmDocServerClient();

            await UtilAssert.ThrowsExceptionWithMessageAsync <RestApiErrorException>(
                async() =>
            {
                await prizmDocServer.BurnMarkupAsync("documents/corrupted-page-count.pdf", "documents/confidential-contacts.pdf.markup.json");
            }, "The remote server was unable to burn the markup file into the document. It is possible there is a problem with the markup JSON or with the document itself.");
        }
Пример #13
0
        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).");
        }
Пример #14
0
        public async Task BurnMarkupAsync_fails_with_a_useful_error_message_when_the_markup_json_file_contains_content_which_does_not_pass_schema_validation()
        {
            PrizmDocServerClient prizmDocServer = Util.CreatePrizmDocServerClient();

            await UtilAssert.ThrowsExceptionWithMessageAsync <RestApiErrorException>(
                async() =>
            {
                await prizmDocServer.BurnMarkupAsync("documents/confidential-contacts.pdf", "documents/content-fails-schema-validation.markup.json");
            }, "The remote server rejected the given markup JSON because it contained content which did not conform to its allowed markup JSON schema. See the markup JSON schema documentation for your version of PrizmDoc Viewer (such as https://help.accusoft.com/PrizmDoc/latest/HTML/webframe.html#markup-json-specification.html).");
        }
        public async Task CreateRedactionsAsync_fails_with_a_useful_error_message_when_the_source_document_is_unusable()
        {
            PrizmDocServerClient prizmDocServer = Util.CreatePrizmDocServerClient();

            await UtilAssert.ThrowsExceptionWithMessageAsync <RestApiErrorException>(
                async() =>
            {
                await prizmDocServer.CreateRedactionsAsync("documents/corrupted-page-count.pdf", new[] { new RegexRedactionMatchRule("wat") });
            }, "The remote server encountered an error when trying to create redactions for the given document. There may be a problem with the document itself.");
        }
        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\"");
        }
Пример #18
0
        public async Task Can_use_local_file_paths_for_both_document_and_markup_JSON()
        {
            // Arrange
            PrizmDocServerClient prizmDocServer = Util.CreatePrizmDocServerClient();

            // Act
            RemoteWorkFile result = await prizmDocServer.RedactToPlainTextAsync("documents/confidential-contacts.pdf", "documents/confidential-contacts.pdf.markup.json", "\n");

            // Assert
            await this.AssertPlainTextRedactionOccurredFor(result, "\n");
        }
Пример #19
0
        public async Task Can_use_carriage_return_and_newline_for_line_endings()
        {
            // Arrange
            PrizmDocServerClient prizmDocServer = Util.CreatePrizmDocServerClient();

            // Act
            RemoteWorkFile result = await prizmDocServer.RedactToPlainTextAsync("documents/confidential-contacts.pdf", "documents/confidential-contacts.pdf.markup.json", "\r\n");

            // Assert
            await this.AssertPlainTextRedactionOccurredFor(result, "\r\n");
        }
Пример #20
0
        private static async Task MainAsync()
        {
            File.Delete("output.pdf");

            var prizmDocServer = new PrizmDocServerClient(Environment.GetEnvironmentVariable("BASE_URL"), Environment.GetEnvironmentVariable("API_KEY"));

            // Take a DOCX file and convert it to a PDF.
            ConversionResult result = await prizmDocServer.ConvertToPdfAsync("project-proposal.docx");

            // Save the result to "output.pdf".
            await result.RemoteWorkFile.SaveAsync("output.pdf");
        }
        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.");
        }
Пример #22
0
        public async Task UploadAsync_with_local_file_path_followed_by_SaveAsync_roundtrip_works()
        {
            PrizmDocServerClient prizmDocServer = Util.CreatePrizmDocServerClient();

            const string INPUT_FILENAME  = "documents/example.docx";
            const string OUTPUT_FILENAME = "downloaded.docx";

            RemoteWorkFile remoteWorkFile = await prizmDocServer.UploadAsync(INPUT_FILENAME);

            await remoteWorkFile.SaveAsync(OUTPUT_FILENAME);

            CollectionAssert.AreEqual(File.ReadAllBytes(INPUT_FILENAME), File.ReadAllBytes(OUTPUT_FILENAME));
        }
Пример #23
0
        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");
            }
        }
Пример #24
0
        private static async Task MainAsync()
        {
            File.Delete("output.pdf");

            var prizmDocServer = new PrizmDocServerClient(Environment.GetEnvironmentVariable("BASE_URL"), Environment.GetEnvironmentVariable("API_KEY"));

            Console.WriteLine("Performing OCR on \"chaucer-scan-3-pages.pdf\"... (this may take a while)");
            ConversionResult result = await prizmDocServer.OcrToPdfAsync("chaucer-scan-3-pages.pdf");

            Console.WriteLine("Saving to \"output.pdf\"...");
            await result.RemoteWorkFile.SaveAsync("output.pdf");

            Console.WriteLine("Done!");
        }
Пример #25
0
        public async Task Can_use_RemoteWorkFile_for_document_and_local_file_path_for_markup_JSON()
        {
            // Arrange
            PrizmDocServerClient prizmDocServer = Util.CreatePrizmDocServerClient();

            AffinitySession affinitySession = Util.RestClient.CreateAffinitySession();
            RemoteWorkFile  document        = await affinitySession.UploadAsync("documents/confidential-contacts.pdf");

            // Act
            RemoteWorkFile result = await prizmDocServer.RedactToPlainTextAsync(document, "documents/confidential-contacts.pdf.markup.json", "\n");

            // Assert
            await this.AssertPlainTextRedactionOccurredFor(result, "\n");
        }
Пример #26
0
        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);
        }
Пример #27
0
        public async Task When_work_file_does_not_exist()
        {
            PrizmDocServerClient prizmDocServer = Util.CreatePrizmDocServerClient();

            AffinitySession affinitySession = Util.RestClient.CreateAffinitySession();
            RemoteWorkFile  validWorkFile   = await affinitySession.UploadAsync("documents/confidential-contacts.pdf");

            RemoteWorkFile invalidWorkFile = new RemoteWorkFile(affinitySession, "non-existent-id", validWorkFile.AffinityToken, "pdf");

            await UtilAssert.ThrowsExceptionWithMessageAsync <RestApiErrorException>(
                async() =>
            {
                await prizmDocServer.CreateRedactionsAsync(invalidWorkFile, new[] { new RegexRedactionMatchRule("dummy rule") });
            }, "Could not use the given RemoteWorkFile as the source document: the work file resource could not be found on the remote server. It may have expired.");
        }
Пример #28
0
        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\".");
        }
Пример #29
0
        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\".");
        }
Пример #30
0
        public async Task BurnMarkupAsync_fails_with_a_useful_error_message_when_the_source_document_cannot_be_found()
        {
            PrizmDocServerClient prizmDocServer = Util.CreatePrizmDocServerClient();

            AffinitySession affinitySession    = Util.RestClient.CreateAffinitySession();
            RemoteWorkFile  existingMarkupFile = await affinitySession.UploadAsync("documents/confidential-contacts.pdf.markup.json");

            RemoteWorkFile nonExistentSourceDocument = new RemoteWorkFile(affinitySession, "non-existent-id", existingMarkupFile.AffinityToken, "pdf");

            await UtilAssert.ThrowsExceptionWithMessageAsync <RestApiErrorException>(
                async() =>
            {
                await prizmDocServer.BurnMarkupAsync(nonExistentSourceDocument, existingMarkupFile);
            }, "Could not use the given RemoteWorkFile as the source document: the work file resource could not be found on the remote server. It may have expired.");
        }