public virtual void TestLigatureBeforeLigature() { System.Console.Out.WriteLine(new FileInfo(sourceFolder).FullName); PdfDocument pdfDocument = new PdfDocument(new PdfReader(sourceFolder + "ligature.pdf")); // build strategy RegexBasedLocationExtractionStrategy extractionStrategy = new RegexBasedLocationExtractionStrategy("ca"); // get locations IList <IPdfTextLocation> locationList = new List <IPdfTextLocation>(); for (int x = 1; x <= pdfDocument.GetNumberOfPages(); x++) { new PdfCanvasProcessor(extractionStrategy).ProcessPageContent(pdfDocument.GetPage(x)); foreach (IPdfTextLocation location in extractionStrategy.GetResultantLocations()) { if (location != null) { locationList.Add(location); } } } // compare NUnit.Framework.Assert.AreEqual(1, locationList.Count); IPdfTextLocation loc = locationList[0]; NUnit.Framework.Assert.AreEqual("ca", loc.GetText()); Rectangle rect = loc.GetRectangle(); NUnit.Framework.Assert.AreEqual(36, rect.GetX(), 0.0001); NUnit.Framework.Assert.AreEqual(655.4600, rect.GetY(), 0.0001); NUnit.Framework.Assert.AreEqual(25.1000, rect.GetWidth(), 0.0001); NUnit.Framework.Assert.AreEqual(20, rect.GetHeight(), 0.0001); pdfDocument.Close(); }
public virtual void Test01() { System.Console.Out.WriteLine(new FileInfo(sourceFolder).FullName); PdfDocument pdfDocument = new PdfDocument(new PdfReader(sourceFolder + "in01.pdf")); // build strategy RegexBasedLocationExtractionStrategy extractionStrategy = new RegexBasedLocationExtractionStrategy(iText.IO.Util.StringUtil.RegexCompile ("\\{\\{Signature\\}\\}")); // get locations IList <IPdfTextLocation> locationList = new List <IPdfTextLocation>(); for (int x = 1; x <= pdfDocument.GetNumberOfPages(); x++) { new PdfCanvasProcessor(extractionStrategy).ProcessPageContent(pdfDocument.GetPage(x)); foreach (IPdfTextLocation location in extractionStrategy.GetResultantLocations()) { if (location != null) { locationList.Add(location); } } } // compare NUnit.Framework.Assert.AreEqual(1, locationList.Count); IPdfTextLocation loc = locationList[0]; NUnit.Framework.Assert.AreEqual("{{Signature}}", loc.GetText()); NUnit.Framework.Assert.AreEqual(23, (int)loc.GetRectangle().GetX()); NUnit.Framework.Assert.AreEqual(375, (int)loc.GetRectangle().GetY()); NUnit.Framework.Assert.AreEqual(55, (int)loc.GetRectangle().GetWidth()); NUnit.Framework.Assert.AreEqual(11, (int)loc.GetRectangle().GetHeight()); // close pdfDocument.Close(); }