Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

pdf-reader:

- expanded RegisterReceiver to log extra information about the callbacks a file triggers. Useful for debugging
- bumped version to 0.5.2 
- added to the TODO 
- added known limitations to the README


git-svn-id: https://pmade.com/svn/oss/pdf-reader/trunk@1208 3db89d08-1e44-db11-a2a8-0014220fd31b
  • Loading branch information...
commit 3e9b0bf1267abc3693b89fb4afc39825a4601037 1 parent f4f6a39
jhealy authored
View
10 README
@@ -117,6 +117,10 @@ it through less or to a text file.
alias :move_to_next_line_and_show_text :show_text
alias :set_spacing_next_line_show_text :show_text
+ def show_text_with_positioning(*params)
+ params = params.first
+ params.each { |str| show_text(str) }
+ end
end
context "My generated PDF" do
@@ -183,6 +187,12 @@ Requires the rbook-isbn gem.
receiver = ISBNReceiver.new
PDF::Reader.file("somefile.pdf", receiver)
+= Known Limitations
+
+The order of the callbacks is unpredicable, and is dependent on the internal
+layout of the file, not the order objects are displayed to the user. As a
+consequence of this it is highly unlikely that text will be completely in
+order.
= Resources
View
2  Rakefile
@@ -6,7 +6,7 @@ require 'rake/testtask'
require "rake/gempackagetask"
require 'spec/rake/spectask'
-PKG_VERSION = "0.5.1"
+PKG_VERSION = "0.5.2"
PKG_NAME = "pdf-reader"
PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
View
2  TODO
@@ -8,3 +8,5 @@ Some ideas for future work
- Improve metadata support
- Add support for additional filters: ASCIIHexDecode, ASCII85Decode, LZWDecode, RunLengthDecode, CCITTFaxDecode, JBIG2Decode, DCTDecode, JPXDecode, Crypt?
+
+- Text that is specified with a ToUnicode mapping isn't extracted properly. The untranslated values are passed to the callback.
View
2  bin/pdf_list_callbacks
@@ -13,5 +13,5 @@ else
end
receiver.callbacks.each do |callback|
- puts callback
+ puts "#{callback[:name]} - #{callback[:args].inspect}"
end
View
49 lib/pdf/reader/register_receiver.rb
@@ -12,7 +12,54 @@ def respond_to?(meth)
end
def method_missing(methodname, *args)
- callbacks << methodname.to_sym
+ callbacks << {:name => methodname.to_sym, :args => args}
+ end
+
+ # count the number of times a callback fired
+ def count(methodname)
+ counter = 0
+ callbacks.each { |cb| counter += 1 if cb[:name] == methodname}
+ return counter
+ end
+
+ # return the details for the first time the specified callback was fired
+ def first_occurance_of(methodname)
+ callbacks.each do |cb|
+ return cb if cb[:name] == methodname
+ end
+ return nil
+ end
+
+ # return the details for the final time the specified callback was fired
+ def final_occurance_of(methodname)
+ returnme = nil
+ callbacks.each do |cb|
+ returnme = cb if cb[:name] == methodname
+ end
+ return returnme
+ end
+
+ # return the first occurance of a particular series of callbacks
+ def series(*methods)
+ return nil if methods.empty?
+
+ indexes = (0..(callbacks.size-1-methods.size))
+ method_indexes = (0..(methods.size-1))
+ match = nil
+
+ indexes.each do |idx|
+ count = methods.size
+ method_indexes.each do |midx|
+ count -= 1 if callbacks[idx+midx][:name] == methods[midx]
+ end
+ match = idx and break if count == 0
+ end
+
+ if match
+ return callbacks[match, methods.size]
+ else
+ return nil
+ end
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.