public virtual void TestScaleWidthMode() { String testName = "testScaleWidthMode"; String path = PdfHelper.GetDefaultImagePath(); String pdfPath = PdfHelper.GetTargetDirectory() + testName + ".pdf"; FileInfo file = new FileInfo(path); float pageWidthPt = 400f; float pageHeightPt = 400f; Rectangle pageSize = new Rectangle(pageWidthPt, pageHeightPt); OcrPdfCreatorProperties properties = new OcrPdfCreatorProperties(); properties.SetScaleMode(ScaleMode.SCALE_WIDTH); properties.SetPageSize(pageSize); PdfHelper.CreatePdf(pdfPath, file, properties); Rectangle rect = GetImageBBoxRectangleFromPdf(pdfPath); ImageData originalImageData = ImageDataFactory.Create(file.FullName); // page size should be equal to the result image size // result image height should be equal to the value that // was set as page height result image width should be scaled // proportionally according to the provided image height // and original image size NUnit.Framework.Assert.AreEqual(pageHeightPt, rect.GetHeight(), DELTA); NUnit.Framework.Assert.AreEqual(originalImageData.GetWidth() / originalImageData.GetHeight(), rect.GetWidth () / rect.GetHeight(), DELTA); }
public virtual void TestPdfA3uWithNullIntent() { String testName = "testPdfA3uWithNullIntent"; String path = PdfHelper.GetDefaultImagePath(); String pdfPath = PdfHelper.GetTargetDirectory() + testName + ".pdf"; OcrPdfCreatorProperties properties = new OcrPdfCreatorProperties(); properties.SetTextColor(DeviceCmyk.BLACK); properties.SetScaleMode(ScaleMode.SCALE_TO_FIT); PdfHelper.CreatePdfA(pdfPath, new FileInfo(path), properties, null); String result = PdfHelper.GetTextFromPdfLayer(pdfPath, null); NUnit.Framework.Assert.AreEqual(PdfHelper.DEFAULT_TEXT, result); NUnit.Framework.Assert.AreEqual(ScaleMode.SCALE_TO_FIT, properties.GetScaleMode()); }
public virtual void TestFontColor() { String testName = "testFontColor"; String path = PdfHelper.GetImagesTestDirectory() + "multipage.tiff"; String pdfPath = PdfHelper.GetTargetDirectory() + testName + ".pdf"; FileInfo file = new FileInfo(path); OcrPdfCreatorProperties properties = new OcrPdfCreatorProperties(); properties.SetScaleMode(ScaleMode.SCALE_TO_FIT); properties.SetTextLayerName("Text1"); Color color = DeviceCmyk.CYAN; properties.SetTextColor(color); PdfHelper.CreatePdf(pdfPath, file, properties); ExtractionStrategy strategy = PdfHelper.GetExtractionStrategy(pdfPath, "Text1"); Color fillColor = strategy.GetFillColor(); NUnit.Framework.Assert.AreEqual(color, fillColor); }
public virtual void TestInvalidFontWithInvalidDefaultFontFamily() { NUnit.Framework.Assert.That(() => { String testName = "testInvalidFontWithInvalidDefaultFontFamily"; String path = PdfHelper.GetDefaultImagePath(); String pdfPath = PdfHelper.GetTargetDirectory() + testName + ".pdf"; FileInfo file = new FileInfo(path); OcrPdfCreatorProperties properties = new OcrPdfCreatorProperties(); FontProvider pdfOcrFontProvider = new FontProvider("Font"); pdfOcrFontProvider.GetFontSet().AddFont("font.ttf", PdfEncodings.IDENTITY_H, "Font"); properties.SetFontProvider(pdfOcrFontProvider, "Font"); properties.SetScaleMode(ScaleMode.SCALE_TO_FIT); PdfHelper.CreatePdf(pdfPath, file, properties); String result = PdfHelper.GetTextFromPdfLayer(pdfPath, null); NUnit.Framework.Assert.AreEqual(PdfHelper.DEFAULT_TEXT, result); NUnit.Framework.Assert.AreEqual(ScaleMode.SCALE_TO_FIT, properties.GetScaleMode()); } , NUnit.Framework.Throws.InstanceOf <OcrException>().With.Message.EqualTo(MessageFormatUtil.Format(OcrException.CANNOT_CREATE_PDF_DOCUMENT, OcrException.CANNOT_RESOLVE_PROVIDED_FONTS))) ; }
public virtual void TestScaleHeightMode() { String testName = "testScaleHeightMode"; String path = PdfHelper.GetDefaultImagePath(); String pdfPath = PdfHelper.GetTargetDirectory() + testName + ".pdf"; FileInfo file = new FileInfo(path); float pageWidthPt = 400f; float pageHeightPt = 400f; Rectangle pageSize = new Rectangle(pageWidthPt, pageHeightPt); OcrPdfCreatorProperties properties = new OcrPdfCreatorProperties(); properties.SetScaleMode(ScaleMode.SCALE_HEIGHT); properties.SetPageSize(pageSize); PdfHelper.CreatePdf(pdfPath, file, properties); Rectangle rect = GetImageBBoxRectangleFromPdf(pdfPath); ImageData originalImageData = ImageDataFactory.Create(file.FullName); NUnit.Framework.Assert.AreEqual(pageWidthPt, rect.GetWidth(), DELTA); NUnit.Framework.Assert.AreEqual(originalImageData.GetWidth() / originalImageData.GetHeight(), rect.GetWidth () / rect.GetHeight(), DELTA); }