https://github.com/yob/pdf-reader
The PDF::Reader library implements a PDF parser conforming as much as possible to the PDF specification from Adobe.
https://github.com/yob/pdf-reader
Keywords from Contributors
activerecord activejob mvc rspec authorization rubygems cucumber rubocop ruby-gem feature-flag
Last synced: about 17 hours ago
JSON representation
Repository metadata
The PDF::Reader library implements a PDF parser conforming as much as possible to the PDF specification from Adobe.
- Host: GitHub
- URL: https://github.com/yob/pdf-reader
- Owner: yob
- License: mit
- Created: 2008-06-03T01:11:36.000Z (over 17 years ago)
- Default Branch: main
- Last Pushed: 2025-11-30T04:05:59.000Z (15 days ago)
- Last Synced: 2025-12-13T01:05:42.334Z (1 day ago)
- Language: Ruby
- Homepage:
- Size: 26.4 MB
- Stars: 1,893
- Watchers: 47
- Forks: 283
- Open Issues: 66
- Releases: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG
- License: MIT-LICENSE
README.md
pdf-reader
The PDF::Reader library implements a PDF parser conforming as much as possible
to the PDF specification from Adobe.
It provides programmatic access to the contents of a PDF file with a high
degree of flexibility.
The PDF 1.7 specification is a weighty document and not all aspects are
currently supported. I welcome submission of PDF files that exhibit
unsupported aspects of the spec to assist with improving our support.
This is primarily a low-level library that should be used as the foundation for
higher level functionality - it's not going to render a PDF for you. There are
a few exceptions to support very common use cases like extracting text from a
page.
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
Text Encoding
Regardless of the internal encoding used in the PDF all text will be converted
to UTF-8 before it is passed back from PDF::Reader.
Strings that contain binary data (like font blobs) will be marked as such.
Former API
Version 1.0.0 of PDF::Reader introduced a new page-based API that provides
efficient and easy access to any page.
The pre-1.0 API was deprecated during the 1.x release series, and has been
removed from 2.0.0.
Exceptions
There are two key exceptions that you will need to watch out for when processing a
PDF file:
MalformedPDFError - The PDF appears to be corrupt in some way. If you believe the
file should be valid, or that a corrupt file didn't raise an exception, please
forward a copy of the file to the maintainers (preferably via the google group)
and we will attempt to improve the code.
UnsupportedFeatureError - The PDF uses a feature that PDF::Reader doesn't currently
support. Again, we welcome submissions of PDF files that exhibit these features to help
us with future code improvements.
MalformedPDFError has some subclasses if you want to detect finer grained issues. If you
don't, 'rescue MalformedPDFError' will catch all the subclassed errors as well.
Any other exceptions should be considered bugs in either PDF::Reader (please
report it!).
PDF Integrity
Windows developers may run into problems when running specs due to MalformedPDFError's
This is usually because CRLF characters are automatically added to some of the PDF's in
the spec folder when you checkout a branch from Git.
To remove any invalid CRLF characters added while checking out a branch from Git, run:
rake fix_integrity
Maintainers
- James Healy mailto:jimmy@deefa.com
Licensing
This library is distributed under the terms of the MIT License. See the included file for
more detail.
Mailing List
Any questions or feedback should be sent to the PDF::Reader google group. It's
better that any answers be available for others instead of hiding in someone's
inbox.
http://groups.google.com/group/pdf-reader
Examples
The easiest way to explain how this works in practice is to show some examples.
Check out the examples/ directory for a few files.
Alternate Decoder
For PDF files containing Ascii85 streams, the ascii85_native gem can be used for increased performance. If the ascii85_native gem is detected, pdf-reader will automatically use the gem.
First, run gem install ascii85_native and then require the gem alongside pdf-reader:
require "pdf-reader"
require "ascii85_native"
Another way of enabling native Ascii85 decoding is to place gem 'ascii85_native' in your project's Gemfile.
Known Limitations
Occasionally some text cannot be extracted properly due to the way it has been
stored, or the use of invalid bytes. In these cases PDF::Reader will output a
little UTF-8 friendly box to indicate an unrecognisable character.
Resources
-
PDF::Reader Code Repository: http://github.com/yob/pdf-reader
-
PDF Specification: https://www.adobe.com/content/dam/acom/en/devnet/pdf/pdfs/PDF32000_2008.pdf
-
Adobe PDF Developer Resources: http://www.adobe.com/devnet/pdf/pdf_reference.html
-
PDF Tutorial Slide Presentations: https://web.archive.org/web/20150110042057/http://home.comcast.net/~jk05/presentations/PDFTutorials.html
-
Developing with PDF (book): http://shop.oreilly.com/product/0636920025269.do
Owner metadata
- Name: James Healy
- Login: yob
- Email:
- Kind: user
- Description:
- Website: http://yob.id.au
- Location: Melbourne, Australia
- Twitter:
- Company:
- Icon url: https://avatars.githubusercontent.com/u/8132?u=8d212e5e4a16aced2027f86b19091f8dc211bb5b&v=4
- Repositories: 127
- Last ynced at: 2023-04-10T07:45:58.442Z
- Profile URL: https://github.com/yob
GitHub Events
Total
- Issues event: 7
- Watch event: 73
- Delete event: 15
- Issue comment event: 37
- Push event: 97
- Pull request review event: 7
- Pull request review comment event: 4
- Pull request event: 45
- Fork event: 9
- Create event: 20
Last Year
- Issues event: 6
- Watch event: 57
- Delete event: 12
- Issue comment event: 34
- Push event: 90
- Pull request review event: 7
- Pull request review comment event: 4
- Pull request event: 40
- Fork event: 7
- Create event: 16
Committers metadata
Last synced: 1 day ago
Total Commits: 1,457
Total Committers: 73
Avg Commits per committer: 19.959
Development Distribution Score (DDS): 0.235
Commits in past year: 56
Committers in past year: 7
Avg Commits per committer in past year: 8.0
Development Distribution Score (DDS) in past year: 0.214
| Name | Commits | |
|---|---|---|
| James Healy | j****y@d****m | 1114 |
| jhealy | j****y@3****b | 119 |
| Sebb | s****b@a****g | 28 |
| Bernerd Schaefer | b****r@g****m | 22 |
| James Healy | j****s@y****o | 19 |
| Nathaniel Madura | n****a@u****u | 16 |
| Alex Dowad | a****g@g****m | 11 |
| Stefan Bilharz | s****z@h****e | 9 |
| Gyuchang Jun | g****g@p****m | 9 |
| Lyle Mullican | m****e@m****u | 6 |
| Evan J Brunner | e****n@a****m | 6 |
| Paul Gallagher | g****l@g****m | 5 |
| Akira Matsuda | r****e@d****p | 5 |
| Josch Bockler | 9****r | 4 |
| Kori Roys | k****i@k****m | 4 |
| Peter Suschlik | ps@n****e | 3 |
| Brad Ediger | b****r@m****m | 3 |
| Jasmeet Arora | j****a@n****m | 3 |
| Nathan Broadbent | g****t@n****m | 3 |
| Rowan | r****u@g****m | 3 |
| Brendan Coles | b****s@g****m | 3 |
| javierg | t****e@g****m | 2 |
| _sss_ | s****s@g****m | 2 |
| Lucas Hills | l****s@l****m | 2 |
| Jordon Biondo | j****b@t****m | 2 |
| Ioana Tagirta | i****a@g****m | 2 |
| Daniel Colson | d****n@g****m | 2 |
| Alan deLevie | a****e@g****m | 2 |
| Jesse Zhou | j****u@g****m | 2 |
| ioanatia | i****a@g****m | 2 |
| and 43 more... | ||
Committer domains:
- github.com: 2
- gusto.com: 2
- freelancing-gods.com: 1
- orien.io: 1
- thatch.ai: 1
- freeagent.com: 1
- trainual.com: 1
- lucashills.com: 1
- ndbroadbent.com: 1
- notarize.com: 1
- madriska.com: 1
- neopoly.de: 1
- koriroys.com: 1
- dio.jp: 1
- appittome.com: 1
- mayo.edu: 1
- point.com: 1
- heilmannsoftware.de: 1
- umich.edu: 1
- yob.id.auto: 1
- apache.org: 1
- katontech.com: 1
- graysoftinc.com: 1
- catch22.net: 1
- rusher.com: 1
- elizandro.com.br: 1
- peerstreet.com: 1
- omeara.com: 1
- room118solutions.com: 1
- chipcastle.com: 1
- benjaminfleischer.com: 1
- stefanwienert.de: 1
- 0x2c.org: 1
- railsware.com: 1
- stawarz.com: 1
- getbraintree.com: 1
- benjamins-mbp.attlocal.net: 1
- dokan-yama-kikaku.org: 1
- beefeatingmonkeys.com: 1
- inversepath.com: 1
- hsmove.com: 1
- jameswindows.(none): 1
- deefa.com: 1
Issue and Pull Request metadata
Last synced: 13 days ago
Total issues: 48
Total pull requests: 131
Average time to close issues: almost 3 years
Average time to close pull requests: 1 day
Total issue authors: 43
Total pull request authors: 20
Average comments per issue: 2.4
Average comments per pull request: 0.6
Merged pull request: 119
Bot issues: 0
Bot pull requests: 0
Past year issues: 3
Past year pull requests: 40
Past year average time to close issues: 11 days
Past year average time to close pull requests: 3 days
Past year issue authors: 3
Past year pull request authors: 9
Past year average comments per issue: 0.67
Past year average comments per pull request: 0.95
Past year merged pull request: 35
Past year bot issues: 0
Past year bot pull requests: 0
Top Issue Authors
- bcoles (5)
- lluchez (2)
- deependersingla (1)
- SimonEggert (1)
- ut (1)
- mmatotan (1)
- servn (1)
- hacktivista (1)
- ramyakp (1)
- n-rodriguez (1)
- pickhardt (1)
- ndvo (1)
- nus-kingsley (1)
- petergoldstein (1)
- iMacTia (1)
Top Pull Request Authors
- yob (98)
- jbockler (6)
- composerinteralia (3)
- jordonbiondo (2)
- olivier-thatch (2)
- servn (2)
- bcoles (2)
- cprodhomme (2)
- lomefin (2)
- javierg (2)
- ShockwaveNN (1)
- iMacTia (1)
- Cashaca (1)
- kserhiyus (1)
- amckinnell (1)
Top Issue Labels
Top Pull Request Labels
Package metadata
- Total packages: 5
-
Total downloads:
- rubygems: 190,756,920 total
- Total docker downloads: 115,702,676
- Total dependent packages: 133 (may contain duplicates)
- Total dependent repositories: 4,441 (may contain duplicates)
- Total versions: 184
- Total maintainers: 3
gem.coop: pdf-reader
The PDF::Reader library implements a PDF parser conforming as much as possible to the PDF specification from Adobe
- Homepage: https://github.com/yob/pdf-reader
- Documentation: http://www.rubydoc.info/gems/pdf-reader/
- Licenses: MIT
- Latest release: 2.15.0 (published 4 months ago)
- Last Synced: 2025-12-13T05:32:30.919Z (1 day ago)
- Versions: 63
- Dependent Packages: 0
- Dependent Repositories: 0
- Downloads: 95,373,127 Total
- Docker Downloads: 57,851,338
-
Rankings:
- Dependent repos count: 0.0%
- Dependent packages count: 0.0%
- Average: 0.217%
- Downloads: 0.265%
- Docker downloads count: 0.602%
- Maintainers (2)
rubygems.org: pdf-reader
The PDF::Reader library implements a PDF parser conforming as much as possible to the PDF specification from Adobe
- Homepage: https://github.com/yob/pdf-reader
- Documentation: http://www.rubydoc.info/gems/pdf-reader/
- Licenses: MIT
- Latest release: 2.15.0 (published 4 months ago)
- Last Synced: 2025-12-13T05:32:24.455Z (1 day ago)
- Versions: 63
- Dependent Packages: 133
- Dependent Repositories: 4,441
- Downloads: 95,373,127 Total
- Docker Downloads: 57,851,338
-
Rankings:
- Dependent packages count: 0.26%
- Downloads: 0.334%
- Dependent repos count: 0.473%
- Docker downloads count: 0.716%
- Average: 0.768%
- Stargazers count: 1.218%
- Forks count: 1.606%
- Maintainers (2)
proxy.golang.org: github.com/yob/pdf-reader
- Homepage:
- Documentation: https://pkg.go.dev/github.com/yob/pdf-reader#section-documentation
- Licenses: mit
- Latest release: v2.15.0+incompatible (published 4 months ago)
- Last Synced: 2025-12-11T23:01:45.035Z (3 days ago)
- Versions: 56
- Dependent Packages: 0
- Dependent Repositories: 0
-
Rankings:
- Stargazers count: 1.588%
- Forks count: 1.728%
- Average: 5.696%
- Dependent packages count: 8.899%
- Dependent repos count: 10.567%
gem.coop: panjiva-pdf-reader
The PDF::Reader library implements a PDF parser conforming as much as possible to the PDF specification from Adobe
- Homepage: http://github.com/yob/pdf-reader
- Documentation: http://www.rubydoc.info/gems/panjiva-pdf-reader/
- Licenses: mit
- Latest release: 1.3.0 (published about 12 years ago)
- Last Synced: 2025-12-11T23:01:42.393Z (3 days ago)
- Versions: 1
- Dependent Packages: 0
- Dependent Repositories: 0
- Downloads: 5,333 Total
-
Rankings:
- Dependent repos count: 0.0%
- Dependent packages count: 0.0%
- Average: 22.055%
- Downloads: 66.166%
- Maintainers (1)
rubygems.org: panjiva-pdf-reader
The PDF::Reader library implements a PDF parser conforming as much as possible to the PDF specification from Adobe
- Homepage: http://github.com/yob/pdf-reader
- Documentation: http://www.rubydoc.info/gems/panjiva-pdf-reader/
- Licenses: mit
- Latest release: 1.3.0 (published about 12 years ago)
- Last Synced: 2025-12-11T23:01:42.276Z (3 days ago)
- Versions: 1
- Dependent Packages: 0
- Dependent Repositories: 0
- Downloads: 5,333 Total
-
Rankings:
- Stargazers count: 1.115%
- Forks count: 1.481%
- Dependent packages count: 15.706%
- Average: 26.545%
- Dependent repos count: 46.782%
- Downloads: 67.642%
- Maintainers (1)
Dependencies
- parlour >= 0
- sorbet = 0.5.10001
- cane ~> 3.0 development
- morecane ~> 0.2 development
- pry >= 0 development
- rake < 13.0 development
- rdoc >= 0 development
- rspec ~> 3.5 development
- Ascii85 ~> 1.0
- afm ~> 0.2.1
- hashery ~> 2.0
- ruby-rc4 >= 0
- ttfunk >= 0
Score: 31.411261514848164