https://github.com/ksylvest/mupdf
A Ruby library for using MuPDF
https://github.com/ksylvest/mupdf
mupdf ruby
Last synced: 10 months ago
JSON representation
A Ruby library for using MuPDF
- Host: GitHub
- URL: https://github.com/ksylvest/mupdf
- Owner: ksylvest
- License: mit
- Created: 2025-01-02T22:35:53.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-06-18T00:00:11.000Z (10 months ago)
- Last Synced: 2025-06-18T01:18:32.048Z (10 months ago)
- Topics: mupdf, ruby
- Language: Ruby
- Homepage: https://mupdf.ksylvest.com/
- Size: 25.4 KB
- Stars: 25
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# MuPDF
[](https://github.com/ksylvest/mupdf/blob/main/LICENSE)
[](https://rubygems.org/gems/mupdf)
[](https://github.com/ksylvest/mupdf)
[](https://mupdf.ksylvest.com)
[](https://circleci.com/gh/ksylvest/mupdf)
## Installation
```bash
gem install mupdf
```
_This project requires `mutool` be installed on your system. To verify ensure the following works:_
```bash
mutool
```
To install `mutool` on MacOS use:
```bash
brew install mupdf
```
To install `mutool` on Ubuntu use:
```bash
apt-get install mupdf
```
## Usage
### Document
A `MuPDF::Document` wraps a PDF file:
```ruby
document = MuPDF::Document.new('./file.pdf')
```
#### Info
The `info` command displays information about the document such as the number of pages:
```ruby
info = document.info
info.pages # e.g. 2
```
#### Pages
The `pages` command finds sizing information about the pages within a document:
```ruby
pages = document.pages
pages.count # e.g. 2
pages.each do |page|
page.number # e.g. 1, 2, ...
page.width # 612
page.height # 792
end
```
#### Draw
The `draw` command is useful for converting a document between formats:
```ruby
document.pages.each do |page|
document.draw(page: page.number, format: "png", path: "./file-#{page.number}.png")
end
```