Is it possible to read a PDF file inside a zip file by pdf-reader? I tried this code but it does not work.
require 'zip'
Zip::File.open('/path/to/zipfile') do |zip_file|
zip_file.each do |entry|
if entry.directory?
puts "#{entry.name} is a folder!"
elsif entry.symlink?
puts "#{entry.name} is a symlink!"
elsif entry.file?
puts "#{entry.name} is a regular file!"
reader = PDF::Reader.new("#{entry.name}")
page = reader.pages.each do |page|
puts page.text
end
else
puts "#{entry.name} is something unknown"
end
end
end
Thanks
PDF::Readervalidates that the input is a "IO-like object or a filename" based on 2 criteria.seekandreadFilebased onFile.file?Excerpt Source:
Unfortunately while
Zip::InputStreamemulates anIOobject fairly well it does not defineseekand therefor it does not pass the validation above. What you can do is create a newStringIOfrom the contents of theZip::InputStreamviaThis will guarantee that
PDF::Readersees this as an "IO-like object" and processes it appropriately.