Skip to content

constructable-ai/ruby-pdfium

Repository files navigation

Ruby PDFium

A Ruby gem that provides bindings to the PDFium library for PDF manipulation.

Installation

Add this line to your application's Gemfile:

gem 'ruby-pdfium', git: 'https://github.com/constructable-ai/ruby-pdfium'

Usage

Loading a PDF Document

require 'pdfium'

# Load a PDF document
document = Pdfium::Document.new('path/to/your/document.pdf')

# Get the number of pages
puts "Document has #{document.page_count} pages"

# Access individual pages
page = document.page(0) # First page (0-indexed)

Extracting Text

# Extract text from a page
text = page.text
puts text

Rendering Pages

# Render a page to RGB image data
bitmap = page.render(width: 800, height: 600)

# Return a Vips::Image object if Vips is installed
bitmap.vips_image

# Return raw bytes of RGBA data
bitmap.bytes

Requirements

  • Ruby 3.0.0 or later
  • Precompiled PDFium binaries are automatically downloaded during installation for:
    • macOS (x64 and ARM64)
    • Linux (x64 and ARM64)

Binary Installation

PDFium binaries are automatically downloaded and installed during gem installation. No additional steps are required - just install the gem and start using it. The binaries will be installed to vendor/pdfium within the gem directory and will be available immediately when you require the gem in your code.

Development

After checking out the repo, run ./bin/setup to install dependencies and PDFium binaries.

Then, run ./bin/rake test to run the tests.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/constructable-ai/ruby-pdfium.

License

The gem is available as open source under the terms of the MIT License.

About

Ruby bindings for PDFium

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages