public virtual void ExtractByteAlignedG4TiffImageTest() { String inFileName = sourceFolder + "extractByteAlignedG4TiffImage.pdf"; String outImageFileName = destinationFolder + "extractedByteAlignedImage.png"; String cmpImageFileName = sourceFolder + "cmp_extractByteAlignedG4TiffImage.png"; PdfDocument pdfDocument = new PdfDocument(new PdfReader(inFileName)); GetImageBytesTest.ImageExtractor listener = new GetImageBytesTest.ImageExtractor(this); PdfCanvasProcessor processor = new PdfCanvasProcessor(listener); processor.ProcessPageContent(pdfDocument.GetPage(1)); IList <byte[]> images = listener.GetImages(); NUnit.Framework.Assert.AreEqual(1, images.Count); using (FileStream fos = new FileStream(outImageFileName, FileMode.Create)) { fos.Write(images[0], 0, images.Count); } // expected and actual are swapped here for simplicity int expectedLen = images[0].Length; byte[] buf = new byte[expectedLen]; using (FileStream @is = new FileStream(cmpImageFileName, FileMode.Open, FileAccess.Read)) { int read = @is.JRead(buf, 0, buf.Length); NUnit.Framework.Assert.AreEqual(expectedLen, read); read = @is.JRead(buf, 0, buf.Length); NUnit.Framework.Assert.IsTrue(read <= 0); } NUnit.Framework.Assert.AreEqual(images[0], buf); }
public virtual void ExpectedByteAlignedTiffImageExtractionTest() { NUnit.Framework.Assert.That(() => { //Byte-aligned image is expected in pdf file, but in fact it's not String inFileName = sourceFolder + "expectedByteAlignedTiffImageExtraction.pdf"; PdfDocument pdfDocument = new PdfDocument(new PdfReader(inFileName)); GetImageBytesTest.ImageExtractor listener = new GetImageBytesTest.ImageExtractor(this); PdfCanvasProcessor processor = new PdfCanvasProcessor(listener); processor.ProcessPageContent(pdfDocument.GetPage(1)); } , NUnit.Framework.Throws.InstanceOf <iText.IO.IOException>().With.Message.EqualTo(MessageFormatUtil.Format(iText.IO.IOException.ExpectedTrailingZeroBitsForByteAlignedLines))) ; }