Esempio n. 1
0
        public virtual void RedactIPhoneUserManual()
        {
            String input  = inputPath + "iphone_user_guide_untagged.pdf";
            String output = outputPath + "redactIPhoneUserManual.pdf";
            String cmp    = inputPath + "cmp_redactIPhoneUserManual.pdf";
            CompositeCleanupStrategy strategy = new CompositeCleanupStrategy();

            strategy.Add(new RegexBasedCleanupStrategy("(iphone)|(iPhone)"));
            PdfDocument pdf = new PdfDocument(new PdfReader(input), new PdfWriter(output));

            // sweep
            PdfCleaner.AutoSweepCleanUp(pdf, strategy);
            pdf.Close();
            // compare
            CleanUpImagesCompareTool cmpTool = new CleanUpImagesCompareTool();
            String errorMessage = cmpTool.ExtractAndCompareImages(output, cmp, outputPath, "4");
            // TODO DEVSIX-4047 Switch to compareByContent() when the ticket will be resolved
            String compareByContentResult = cmpTool.CompareVisually(output, cmp, outputPath, "diff_redactIPhoneUserManual_"
                                                                    , cmpTool.GetIgnoredImagesAreas());

            if (compareByContentResult != null)
            {
                errorMessage += compareByContentResult;
            }
            if (!errorMessage.Equals(""))
            {
                NUnit.Framework.Assert.Fail(errorMessage);
            }
        }
Esempio n. 2
0
        public virtual void RedactIPhoneUserManualColored()
        {
            String input  = inputPath + "iphone_user_guide_untagged_small.pdf";
            String output = outputPath + "redactIPhoneUserManualColored.pdf";
            String cmp    = inputPath + "cmp_redactIPhoneUserManualColored.pdf";
            CompositeCleanupStrategy strategy = new CompositeCleanupStrategy();

            strategy.Add(new RegexBasedCleanupStrategy("(iphone)|(iPhone)").SetRedactionColor(ColorConstants.GREEN));
            PdfDocument pdf = new PdfDocument(new PdfReader(input), new PdfWriter(output));

            // sweep
            PdfCleaner.AutoSweepCleanUp(pdf, strategy);
            pdf.Close();
            CompareResults(cmp, output, outputPath, "4");
        }
Esempio n. 3
0
        public virtual void CleanUpAreaCalculationPrecisionTest()
        {
            String input  = inputPath + "cleanUpAreaCalculationPrecision.pdf";
            String output = outputPath + "cleanUpAreaCalculationPrecision.pdf";
            String cmp    = inputPath + "cmp_cleanUpAreaCalculationPrecision.pdf";
            CompositeCleanupStrategy strategy = new CompositeCleanupStrategy();

            strategy.Add(new CustomLocationExtractionStrategy("(iphone)|(iPhone)"));
            PdfDocument pdf = new PdfDocument(new PdfReader(input), new PdfWriter(output));

            // sweep
            PdfCleaner.AutoSweepCleanUp(pdf, strategy);
            pdf.Close();
            // compare
            CompareTool compareTool  = new CompareTool();
            String      errorMessage = compareTool.CompareByContent(output, cmp, outputPath);

            NUnit.Framework.Assert.IsNull(errorMessage);
        }
Esempio n. 4
0
        public virtual void RedactTonySoprano()
        {
            String input  = inputPath + "TheSopranos.pdf";
            String output = outputPath + "redactTonySoprano.pdf";
            String cmp    = inputPath + "cmp_redactTonySoprano.pdf";
            CompositeCleanupStrategy strategy = new CompositeCleanupStrategy();

            strategy.Add(new RegexBasedCleanupStrategy("Tony( |_)Soprano"));
            strategy.Add(new RegexBasedCleanupStrategy("Soprano"));
            strategy.Add(new RegexBasedCleanupStrategy("Sopranos"));
            PdfWriter writer = new PdfWriter(output);

            writer.SetCompressionLevel(0);
            PdfDocument pdf = new PdfDocument(new PdfReader(input), writer);

            // sweep
            PdfCleaner.AutoSweepCleanUp(pdf, strategy);
            pdf.Close();
            // compare
            CompareResults(cmp, output, outputPath, "4");
        }
        public virtual void AutoCleanWithStreamParamsSendsCleanUpEventTest()
        {
            String input  = INPUT_PATH + "fontCleanup.pdf";
            String output = OUTPUT_PATH + "autoCleanWithStreamParamsSendsCleanUpEventTest.pdf";
            CompositeCleanupStrategy strategy = new CompositeCleanupStrategy();

            strategy.Add(new RegexBasedCleanupStrategy("leonard"));
            PdfCleaner.AutoSweepCleanUp(new FileStream(input, FileMode.Open, FileAccess.Read), new FileStream(output,
                                                                                                              FileMode.Create), strategy);
            IList <ConfirmEvent> events = handler.GetEvents();

            NUnit.Framework.Assert.AreEqual(1, events.Count);
            NUnit.Framework.Assert.AreEqual(PdfSweepProductEvent.CLEANUP_PDF, events[0].GetEvent().GetEventType());
            using (PdfDocument outDoc = new PdfDocument(new PdfReader(output))) {
                using (PdfDocument inputDoc = new PdfDocument(new PdfReader(input))) {
                    String expectedProdLine = CreateExpectedProducerLine(new ConfirmedEventWrapper[] { GetCleanUpEvent() }, inputDoc
                                                                         .GetDocumentInfo().GetProducer());
                    NUnit.Framework.Assert.AreEqual(expectedProdLine, outDoc.GetDocumentInfo().GetProducer());
                }
            }
        }
        public virtual void AutoSweepCleanUpSendsCoreAndCleanUpEventsTest()
        {
            ByteArrayOutputStream    baos     = new ByteArrayOutputStream();
            PdfDocument              document = new PdfDocument(new PdfReader(INPUT_PATH + "fontCleanup.pdf"), new PdfWriter(baos));
            CompositeCleanupStrategy strategy = new CompositeCleanupStrategy();

            strategy.Add(new RegexBasedCleanupStrategy("leonard"));
            PdfCleaner.AutoSweepCleanUp(document, strategy);
            String oldProducer = document.GetDocumentInfo().GetProducer();

            document.Close();
            IList <ConfirmEvent> events = handler.GetEvents();

            NUnit.Framework.Assert.AreEqual(2, events.Count);
            NUnit.Framework.Assert.AreEqual(ITextCoreProductEvent.PROCESS_PDF, events[0].GetEvent().GetEventType());
            NUnit.Framework.Assert.AreEqual(PdfSweepProductEvent.CLEANUP_PDF, events[1].GetEvent().GetEventType());
            using (PdfDocument pdfDocument = new PdfDocument(new PdfReader(new MemoryStream(baos.ToArray())))) {
                String expectedProdLine = CreateExpectedProducerLine(new ConfirmedEventWrapper[] { GetCoreEvent(), GetCleanUpEvent
                                                                                                       () }, oldProducer);
                NUnit.Framework.Assert.AreEqual(expectedProdLine, pdfDocument.GetDocumentInfo().GetProducer());
            }
        }