MuPDF
Installation
gem install mupdf
This project requires mutool
be installed on your system. To verify ensure the following works:
mutool
To install mutool
on MacOS use:
brew install mupdf
To install mutool
on Ubuntu use:
apt-get install mupdf
Usage
Document
A MuPDF::Document
wraps a PDF file:
document = MuPDF::Document.new('./file.pdf')
Info
The info
command displays information about the document such as the number of pages:
info = document.info
info.pages # e.g. 2
Pages
The pages
command finds sizing information about the pages within a document:
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:
document.pages.each do |page|
document.draw(page: page.number, format: "png", path: "./file-#{page.number}.png")
end