public virtual void CleanUpWithStreamArgumentsSendsCleanUpEventTest() { IList <iText.PdfCleanup.PdfCleanUpLocation> cleanUpLocations = new List <iText.PdfCleanup.PdfCleanUpLocation >(); iText.PdfCleanup.PdfCleanUpLocation lineLoc = new iText.PdfCleanup.PdfCleanUpLocation(1, new Rectangle(100 , 560, 200, 30)); cleanUpLocations.Add(lineLoc); String @in = INPUT_PATH + "page229.pdf"; String @out = OUTPUT_PATH + "cleanUpWithStreamArgumentTest.pdf"; Stream file = new FileStream(@in, FileMode.Open, FileAccess.Read); Stream output = new FileStream(@out, FileMode.Create); PdfCleaner.CleanUp(file, output, cleanUpLocations, new CleanUpProperties()); 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 pdfDocument = new PdfDocument(new PdfReader(@out))) { using (PdfDocument inputDoc = new PdfDocument(new PdfReader(@in))) { String expectedProdLine = CreateExpectedProducerLine(new ConfirmedEventWrapper[] { GetCleanUpEvent() }, inputDoc .GetDocumentInfo().GetProducer()); NUnit.Framework.Assert.AreEqual(expectedProdLine, pdfDocument.GetDocumentInfo().GetProducer()); } } }
private void CleanUp(String input, String output, IList <iText.PdfCleanup.PdfCleanUpLocation> cleanUpLocations ) { PdfDocument pdfDocument = new PdfDocument(new PdfReader(input), new PdfWriter(output)); PdfCleaner.CleanUp(pdfDocument, cleanUpLocations); pdfDocument.Close(); }
private static void CleanFirstPageAndDrawCleanupRegion(Rectangle cleanupRegion, String input, String output ) { using (PdfDocument pdfDocument = new PdfDocument(new PdfReader(input), new PdfWriter(output))) { PdfCleaner.CleanUp(pdfDocument, JavaCollectionsUtil.SingletonList(new iText.PdfCleanup.PdfCleanUpLocation( 1, cleanupRegion))); DrawCleanupRegionOnPage(pdfDocument, cleanupRegion); } }
private byte[] RemoverCarimboLateral(byte[] arquivo, float largura, float limiteMaximo) { using MemoryStream readingStream = new MemoryStream(arquivo); using PdfReader pdfReader = new PdfReader(readingStream); using MemoryStream writingStream = new MemoryStream(); using PdfWriter pdfWriter = new PdfWriter(writingStream); using PdfDocument pdfDocument = new PdfDocument(pdfReader, pdfWriter); int numberOfPages = pdfDocument.GetNumberOfPages(); for (int i = 1; i <= numberOfPages; i++) { PdfPage page = pdfDocument.GetPage(i); page.SetIgnorePageRotationForContent(true); Rectangle pageSize = pdfDocument.GetPage(i).GetPageSizeWithRotation(); float offset = pageSize.GetWidth() * largura; if (offset > limiteMaximo) { offset = limiteMaximo; } float numeroLinhas = 4f; float intervalo = offset / (numeroLinhas + 1f); float posicaoIncicial = pageSize.GetWidth() - offset; IList <PdfCleanUpLocation> cleanUpLocations = new List <PdfCleanUpLocation>(); for (int j = 1; j <= numeroLinhas; j++) { Rectangle rectangle = new Rectangle( posicaoIncicial + intervalo, 0, 0.1f, pageSize.GetHeight() ); PdfCleanUpLocation location = new PdfCleanUpLocation(i, rectangle); posicaoIncicial = posicaoIncicial + intervalo; cleanUpLocations.Add(location); } PdfCleaner.CleanUp(pdfDocument, cleanUpLocations); } pdfDocument.Close(); return(writingStream.ToArray()); }
private void CleanUp(String input, String output, IList <iText.PdfCleanup.PdfCleanUpLocation> cleanUpLocations ) { PdfDocument pdfDocument = new PdfDocument(new PdfReader(input), new PdfWriter(output)); if (cleanUpLocations == null) { PdfCleaner.CleanUpRedactAnnotations(pdfDocument); } else { PdfCleaner.CleanUp(pdfDocument, cleanUpLocations); } pdfDocument.Close(); }
public virtual void CleanCircularReferencesInResourcesTest() { NUnit.Framework.Assert.That(() => { String input = inputPath + "circularReferencesInResources.pdf"; PdfDocument pdfDocument = new PdfDocument(new PdfReader(input), new PdfWriter(new MemoryStream())); IList <iText.PdfCleanup.PdfCleanUpLocation> cleanUpLocations = new List <iText.PdfCleanup.PdfCleanUpLocation >(); cleanUpLocations.Add(new iText.PdfCleanup.PdfCleanUpLocation(1, pdfDocument.GetPage(1).GetPageSize(), null )); PdfCleaner.CleanUp(pdfDocument, cleanUpLocations); pdfDocument.Close(); } , NUnit.Framework.Throws.InstanceOf <OutOfMemoryException>()) ; }
public virtual void ImageTransparencyTextOnTransparentField() { String fileName = "textOnTransparentField"; String input = inputPath + fileName + ".pdf"; String output = outputPath + fileName + "_cleaned.pdf"; String cmp = inputPath + "cmp_" + fileName + ".pdf"; IList <iText.PdfCleanup.PdfCleanUpLocation> cleanUpLocations = JavaCollectionsUtil.SingletonList(new iText.PdfCleanup.PdfCleanUpLocation (1, new Rectangle(280, 360, 200, 75))); PdfDocument pdfDocument = new PdfDocument(new PdfReader(input), new PdfWriter(output)); PdfCleaner.CleanUp(pdfDocument, cleanUpLocations); new PdfCanvas(pdfDocument.GetFirstPage().NewContentStreamBefore(), pdfDocument.GetFirstPage().GetResources (), pdfDocument).SetColor(ColorConstants.LIGHT_GRAY, true).Rectangle(0, 0, 1000, 1000).Fill().SetColor (ColorConstants.BLACK, true); pdfDocument.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(output, cmp, outputPath)); }
public virtual void NoWhiteColorTest() { String input = inputPath + "indexedImageNoWhite.pdf"; String output = outputPath + "indexedImageNoWhite.pdf"; String cmp = inputPath + "cmp_indexedImageNoWhite.pdf"; using (PdfDocument pdfDocument = new PdfDocument(new PdfReader(input), new PdfWriter(output))) { PdfCleaner.CleanUp(pdfDocument, JavaUtil.ArraysAsList(new iText.PdfCleanup.PdfCleanUpLocation(1, new Rectangle (150, 250, 100, 100)))); } /* * Result in Java and .NET is different. * * Java is able to process images with indexed colorspace same as others and * doesn't preserve indexed colorspace. .NET requires special processing for * indexed colorspace images, but preserves indexed colorspace. * * In .NET color of cleaned area is the first color of indexed color palette. * In Java color of cleaned area is white. */ NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(output, cmp, outputPath)); }
public virtual void OpenDocumentAndCleanUpSendsCoreAndCleanUpEventsTest() { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfDocument document = new PdfDocument(new PdfReader(INPUT_PATH + "page229.pdf"), new PdfWriter(baos)); String oldProducer = document.GetDocumentInfo().GetProducer(); IList <iText.PdfCleanup.PdfCleanUpLocation> cleanUpLocations = new List <iText.PdfCleanup.PdfCleanUpLocation >(); iText.PdfCleanup.PdfCleanUpLocation lineLoc = new iText.PdfCleanup.PdfCleanUpLocation(1, new Rectangle(100 , 560, 200, 30), ColorConstants.GREEN); cleanUpLocations.Add(lineLoc); PdfCleaner.CleanUp(document, cleanUpLocations, new CleanUpProperties()); 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()); } }
private static void RunTest(String fileName, String fuzzValue) { String input = inputPath + fileName + ".pdf"; String output = outputPath + fileName + "_cleaned.pdf"; String cmp = inputPath + "cmp_" + fileName + ".pdf"; IList <iText.PdfCleanup.PdfCleanUpLocation> cleanUpLocations = JavaCollectionsUtil.SingletonList(new iText.PdfCleanup.PdfCleanUpLocation (1, new Rectangle(308, 520, 200, 75))); PdfDocument pdfDocument = new PdfDocument(new PdfReader(input), new PdfWriter(output)); PdfCleaner.CleanUp(pdfDocument, cleanUpLocations); pdfDocument.Close(); CleanUpImagesCompareTool cmpTool = new CleanUpImagesCompareTool(); String errorMessage = cmpTool.ExtractAndCompareImages(output, cmp, outputPath, fuzzValue); String compareByContentResult = cmpTool.CompareByContent(output, cmp, outputPath); if (compareByContentResult != null) { errorMessage += compareByContentResult; } if (!errorMessage.Equals("")) { NUnit.Framework.Assert.Fail(errorMessage); } }
private void CleanUp(PdfDocument pdfDocument, IList <iText.PdfCleanup.PdfCleanUpLocation> cleanUpLocations) { PdfCleaner.CleanUp(pdfDocument, cleanUpLocations); pdfDocument.Close(); }