MuPDF
Installation
gem install mupdfThis project requires mutool be installed on your system. To verify ensure the following works:
mutoolTo install mutool on MacOS use:
brew install mupdfTo install mutool on Ubuntu use:
apt-get install mupdfUsage
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. 2Pages
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
endDraw
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