🔍RepoLensrepolens.ru
  • /trending
  • /top500
  • /weekly
  • /categories
  • /about

© 2026 RepoLens · repolens.ru

root@repolens:~# updating the stack

@exvadimka

Данные обновляются автоматически через GitHub API

← к каталогу

📦 pdf-reader/ yob

The PDF::Reader library implements a PDF parser conforming as much as possible to the PDF specification from Adobe.

Открыть на GitHub ↗обновлён 1нед назад
Звёзды
★ 1.9k
Форки
287
За неделю
—
За месяц
—
Рост %
—
Язык
Ruby

Установка и запуск

Installation

The recommended installation method is via Rubygems.

gem install pdf-reader

Usage

Begin by creating a PDF::Reader instance that points to a PDF file. Document level information (metadata, page count, bookmarks, etc) is available via this object.

reader = PDF::Reader.new("somefile.pdf")

puts reader.pdf_version
puts reader.info
puts reader.metadata
puts reader.page_count

PDF::Reader.new accepts an IO stream or a filename. Here's an example with an IO stream:

require 'open-uri'

io     = open('http://example.com/somefile.pdf')
reader = PDF::Reader.new(io)
puts reader.info

If you open a PDF with File#open or IO#open, I strongly recommend using "rb" mode to ensure the file isn't mangled by ruby being 'helpful'. This is particularly important on windows and MRI >= 1.9.2.

File.open("somefile.pdf", "rb") do |io|
  reader = PDF::Reader.new(io)
  puts reader.info
end

PDF is a page based file format, so most visible information is available via page-based iteration

reader = PDF::Reader.new("somefile.pdf")

reader.pages.each do |page|
  puts page.fonts
  puts page.text
  puts page.raw_content
end

If you need to access the full program for rendering a page, use the walk() method of PDF::Reader::Page.

class RedGreenBlue
  def set_rgb_color_for_nonstroking(r, g, b)
    puts "R: #{r}, G: #{g}, B: #{b}"
  end
end

reader   = PDF::Reader.new("somefile.pdf")
page     = reader.page(1)
receiver = RedGreenBlue.new
page.walk(receiver)

For low level access to the objects in a PDF file, use the ObjectHash class like so:

reader  = PDF::Reader.new("somefile.pdf")
puts reader.objects.inspect

Из README репозитория · полный README на GitHub

Категории

🗃️Базы данных