Skip to content

Instantly share code, notes, and snippets.

@janxious
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janxious/55ac6116b9028ca38fdb to your computer and use it in GitHub Desktop.
Save janxious/55ac6116b9028ca38fdb to your computer and use it in GitHub Desktop.
pdf-reader
class DeployTest < ActiveSupport::TestCase
test "large pdf creation" do
time_method do
response = make_pdf(:document_url => "https://gist.github.com/raw/2a258fb00bc28dabe587/a1dbfa3d1b44f5af4041486454ca51514b402fe2/Moby-Dick,or,The%20Whale.html",
:async => true,
:strict => "none")
pdf_file = download(response)
reader = PDF::Reader.new(save_response(pdf_file).path)
beginning = reader.pages.take(10).map(&:text).join("\n")
assert_match /And God created great whales./, beginning
end
end
end
end
#!/usr/bin/env ruby
# coding: utf-8
# Extract all text from a single PDF
require 'rubygems'
require 'pdf/reader'
filename = File.expand_path(File.dirname(__FILE__)) + "/../spec/data/cairo-unicode.pdf"
PDF::Reader.open(filename) do |reader|
reader.pages.each do |page|
puts page.text
end
end
@janxious
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment