diff --git a/test/pdf/reader/find_text_test.rb b/test/pdf/reader/find_text_test.rb index 2d1ca5b..e9f1b1e 100644 --- a/test/pdf/reader/find_text_test.rb +++ b/test/pdf/reader/find_text_test.rb @@ -7,7 +7,30 @@ class PDF::Reader::FindTextTest < Minitest::Test refute_nil ::PDF::Reader::FindText::VERSION end - def test_it_does_something_useful - assert false + def test_that_it_finds_single_text_in_pdf + reader = PDF::Reader.new File.open('test/test.pdf') + + results = reader.pages.first.find_text('MICHELANGELO') + assert_equal 1, results.size + assert_equal 25, results.first.x + assert_equal 25, results.first.y + end + + def test_that_it_finds_multiple_text_in_pdf + reader = PDF::Reader.new File.open('test/test.pdf') + + results = reader.pages.first.find_text('Cowabunga') + assert_equal 3, results.size + assert_equal 247.64, results.first.x + assert_equal 420.945, results.first.y + end + + def test_that_it_finds_complicated_text_in_pdf + reader = PDF::Reader.new File.open('test/test.pdf') + + results = reader.pages.first.find_text('Cowabunga, le cri des ninjas !') + assert_equal 3, results.size + assert_equal 247.64, results.first.x + assert_equal 420.945, results.first.y end end diff --git a/test/test.pdf b/test/test.pdf new file mode 100644 index 0000000..628807d --- /dev/null +++ b/test/test.pdf @@ -0,0 +1,115 @@ +%PDF-1.3 +%ÿÿÿÿ +1 0 obj +<< /Creator +/Producer +>> +endobj +2 0 obj +<< /Type /Catalog +/Pages 3 0 R +>> +endobj +3 0 obj +<< /Type /Pages +/Count 1 +/Kids [5 0 R] +>> +endobj +4 0 obj +<< /Length 648 +>> +stream +q + +BT +25.0 25.0 Td +/F1.0 12 Tf +[<4d494348454c414e47454c4f>] TJ +ET + + +BT +25.0 804.89 Td +/F1.0 12 Tf +[<4c454f4e4152444f>] TJ +ET + + +BT +490.28 804.89 Td +/F1.0 12 Tf +[<444f4e41> 120 <54454c4c4f>] TJ +ET + + +BT +490.28 25.0 Td +/F1.0 12 Tf +[<5241504841454c>] TJ +ET + + +BT +247.64 420.945 Td +/F1.0 12 Tf +[<436f> 15 <77> 15 <6162> 20 <756e67612c206c65206372> -15 <6920646573206e696e6a61732021>] TJ +ET + + +BT +247.64 440.945 Td +/F1.0 12 Tf +[<436f> 15 <77> 15 <6162> 20 <756e67612c206c65206372> -15 <6920646573206e696e6a61732021>] TJ +ET + + +BT +247.64 460.945 Td +/F1.0 12 Tf +[<436f> 15 <77> 15 <6162> 20 <756e67612c206c65206372> -15 <6920646573206e696e6a61732021>] TJ +ET + +Q + +endstream +endobj +5 0 obj +<< /Type /Page +/Parent 3 0 R +/MediaBox [0 0 595.28 841.89] +/CropBox [0 0 595.28 841.89] +/BleedBox [0 0 595.28 841.89] +/TrimBox [0 0 595.28 841.89] +/ArtBox [0 0 595.28 841.89] +/Contents 4 0 R +/Resources << /ProcSet [/PDF /Text /ImageB /ImageC /ImageI] +/Font << /F1.0 6 0 R +>> +>> +>> +endobj +6 0 obj +<< /Type /Font +/Subtype /Type1 +/BaseFont /Helvetica +/Encoding /WinAnsiEncoding +>> +endobj +xref +0 7 +0000000000 65535 f +0000000015 00000 n +0000000109 00000 n +0000000158 00000 n +0000000215 00000 n +0000000914 00000 n +0000001210 00000 n +trailer +<< /Size 7 +/Root 2 0 R +/Info 1 0 R +>> +startxref +1307 +%%EOF