public void FromPage() { using (var doc = CGPDFDocument.FromFile(NSBundle.MainBundle.PathForResource("Tamarin", "pdf"))) using (var page = doc.GetPage(1)) using (var cs = new CGPDFContentStream(page)) { Assert.That(cs.Handle, Is.Not.EqualTo(IntPtr.Zero), "Handle"); var streams = cs.GetStreams(); Assert.That(streams.Length, Is.EqualTo(1), "GetStreams.Length"); Assert.That(streams [0].Handle, Is.Not.EqualTo(cs.Handle), "GetStreams"); Assert.Null(cs.GetResource("XObject", ""), "GetResource"); } }
public void Tamarin() { using (var table = new CGPDFOperatorTable()) { // note: the native API is horrible as we can't share the same callback and dispatch it to the right // managed method. That force every operator to have one ugly, MonoPInvokeCallback-decorated, per // operator #if WE_HAD_A_NICE_API table.SetCallback("BT", delegate(CGPDFScanner scanner) { bt_count++; }); table.SetCallback("Do", delegate(CGPDFScanner scanner) { // ... drill down to the image }); #elif NET unsafe { // BT == new paragraph table.SetCallback("BT", &BT); // Do == the image is inside it table.SetCallback("Do", &Do); } #else // BT == new paragraph table.SetCallback("BT", BT); // Do == the image is inside it table.SetCallback("Do", Do); #endif using (var doc = CGPDFDocument.FromFile(NSBundle.MainBundle.PathForResource("Tamarin", "pdf"))) using (var page = doc.GetPage(1)) using (var cs = new CGPDFContentStream(page)) using (var scanner = new CGPDFScanner(cs, table, this)) { Assert.That(scanner.Handle, Is.Not.EqualTo(IntPtr.Zero), "Handle"); Assert.That(scanner.GetContentStream().Handle, Is.EqualTo(cs.Handle), "GetContentStream"); bt_count = 0; do_checks = 7; Assert.True(scanner.Scan(), "Scan"); Assert.That(bt_count, Is.EqualTo(45), "new paragraph"); Assert.That(do_checks, Is.EqualTo(0), "found the image"); } } }