Esempio n. 1
0
        public void RenderWithGsNetTest_WithTextOverPages_ResultedFileNotChanged()
        {
            string inPdfPath = Directory.GetCurrentDirectory() + "/BlackRectanglesWithAllText.pdf";

            PdfProcessorTests.FlushResourceToFile(Resources + "BlackRectanglesWithAllText.pdf", inPdfPath);
            string outPdfPath = inPdfPath + ".out.pdf";

            Assert.IsFalse(target.RenderSpecialCsPagesWithGsNet(inPdfPath, outPdfPath, 150));
        }
Esempio n. 2
0
        public void CheckActions_ResultedFileContainsOnlyImages_ProperlyRotated()
        {
            string inPdfPath = Directory.GetCurrentDirectory() + @"\BlackRectangles1.pdf";

            PdfProcessorTests.FlushResourceToFile(Resources + "BlackRectangles.pdf", inPdfPath);
            string outPdfPath = inPdfPath + ".out.pdf";

            using (var reader = new PdfReader(inPdfPath))
            {
                using (var fs = new FileStream(outPdfPath, FileMode.Create))
                {
                    using (var stamper = new PdfStamper(reader, fs))
                    {
                        using (var render = new GsNetPdfRender(inPdfPath, 150))
                        {
                            var andFilter = new AndFilter(
                                new HasSpecialCsResourceFilter(reader),
                                new NotFilter(new HasFontResourceFilter(reader)),
                                new NotFilter(
                                    new PageHasSpecificKeyFilter(
                                        reader,
                                        RenderPageAction.EstPageRendered,
                                        new PdfBoolean(true))));
                            using (var action = new RenderPageAction(reader, stamper, andFilter, render))
                            {
                                var processor = new PdfProcessor(new List <IPdfAction> {
                                    action
                                });
                                for (int i = 1; i <= reader.NumberOfPages; i++)
                                {
                                    processor.Execute(i);
                                }
                            }
                        }
                    }
                }
            }

            using (var reader = new PdfReader(outPdfPath))
            {
                AssertPageRotation(reader, 1, 0);
                AssertOnlyImageAndImageSize(reader, 1, 1275, 1650);
                AssertPageRotation(reader, 2, 90);
                AssertOnlyImageAndImageSize(reader, 2, 1275, 1650);
                AssertPageRotation(reader, 3, 180);
                AssertOnlyImageAndImageSize(reader, 3, 1275, 1650);
            }
        }
Esempio n. 3
0
        public void RenderWithGsNetTest_ResultedFileContainsOnlyImages_ProperlyRotated()
        {
            string inPdfPath = Directory.GetCurrentDirectory() + "/BlackRectangles2.pdf";

            PdfProcessorTests.FlushResourceToFile(Resources + "BlackRectangles.pdf", inPdfPath);
            string outPdfPath = inPdfPath + ".out.pdf";

            Assert.IsTrue(target.RenderSpecialCsPagesWithGsNet(inPdfPath, outPdfPath, 150));

            using (var reader = new PdfReader(outPdfPath))
            {
                AssertPageRotation(reader, 1, 0);
                AssertOnlyImageAndImageSize(reader, 1, 1275, 1650);
                AssertPageRotation(reader, 2, 90);
                AssertOnlyImageAndImageSize(reader, 2, 1275, 1650);
                AssertPageRotation(reader, 3, 180);
                AssertOnlyImageAndImageSize(reader, 3, 1275, 1650);
            }
        }
Esempio n. 4
0
        public void CheckIfDocumentWasScannedAndFixIfNecessary_Stream_ResultedFileContainsOnlyImages_ProperlyRotated()
        {
            string inPdfPath = Directory.GetCurrentDirectory() + "/BlackRectangles5.pdf";

            PdfProcessorTests.FlushResourceToFile(Resources + "BlackRectangles.pdf", inPdfPath);
            byte[] buffer = File.ReadAllBytes(inPdfPath);
            var    result = target.CheckIfDocumentWasScannedAndFixIfNecessary(new MemoryStream(buffer));

            Assert.IsTrue(result.Length != buffer.Length); // was modified

            using (var reader = new PdfReader(result))
            {
                AssertPageRotation(reader, 1, 0);
                AssertOnlyImageAndImageSize(reader, 1, 1275, 1650);
                AssertPageRotation(reader, 2, 90);
                AssertOnlyImageAndImageSize(reader, 2, 1275, 1650);
                AssertPageRotation(reader, 3, 180);
                AssertOnlyImageAndImageSize(reader, 3, 1275, 1650);
            }
        }
Esempio n. 5
0
        public void CheckIfDocumentWasScannedAndFixIfNecessary_File_DocumentWasFixed()
        {
            string pdfPath = Directory.GetCurrentDirectory() + "/BlackRectangles4.pdf";

            PdfProcessorTests.FlushResourceToFile(Resources + "BlackRectangles.pdf", pdfPath);
            DateTime lastWrite = File.GetLastWriteTime(pdfPath);

            target.CheckIfDocumentWasScannedAndFixIfNecessary(pdfPath);
            bool wasModified = lastWrite != File.GetLastWriteTime(pdfPath);

            Assert.IsTrue(wasModified); // file was modified
            using (var reader = new PdfReader(pdfPath))
            {
                AssertPageRotation(reader, 1, 0);
                AssertOnlyImageAndImageSize(reader, 1, 1275, 1650);
                AssertPageRotation(reader, 2, 90);
                AssertOnlyImageAndImageSize(reader, 2, 1275, 1650);
                AssertPageRotation(reader, 3, 180);
                AssertOnlyImageAndImageSize(reader, 3, 1275, 1650);
            }
        }
Esempio n. 6
0
 public void CheckIfDocumentWasScannedAndFixIfNecessary_ResultedBufferNotChanged()
 {
     byte[] buffer = PdfProcessorTests.GetResourceBytes(Resources + "BlackRectanglesWithRenderedKey.pdf");
     byte[] result = target.CheckIfDocumentWasScannedAndFixIfNecessary(buffer);
     Assert.IsTrue(result.Length == buffer.Length);
 }