MuPDF on the command line
MuPDF has few command line options available:
mupdf-gl A handy viewer UI.
muraster Can be used to convert PDF pages to raster images.
mutool An all purpose tool for dealing with PDF files. Used in conjunction with the mutool JavaScript API
mupdf-gl
The OpenGL based viewer can read PDF, XPS, CBZ, EPUB, & FB2 documents as well as typical image formats including SVG. It compiles on any platform that has a GLUT library. The latest release builds on Linux, Windows, and MacOS.
Command Line Options
mupdf-gl [options] document [page]
[options]
-p
passwordThe password needed to open a password protected PDF file.
-r
resolutionSet the initial zoom level, specified as DPI. The default value is
72
.-W
widthSet the page width in points for EPUB layout.
-H
heightSet the page height in points for EPUB layout.
-S
sizeSet the default font size in points for EPUB layout.
-U
stylesheetSpecify a CSS file containing user styles to load for EPUB layout.
-X
Ignore publisher styles for EPUB layout.
-J
Disable JavaScript in PDF forms.
-A
levelSet anti-aliasing level or pixel rendering rule.
0
: off.
2
: 4 levels.
4
: 16 levels.
8
: 256 levels.
9
: using centre of pixel rule.
10
: using any part of a pixel rule.-I
Start in inverted color mode.
-B
hex-colorSet black tint color (default
303030
).-C
hex-colorSet white tint color (default
FFFFF0
).-Y
factorSet UI scaling factor (default calculated from screen DPI).
[page]
The initial page number to show.
Example usage #1:
This will open the viewer with a file browser which allows you to choose the file you need.
mupdf-gl
Example usage #1:
This will open a specific file, in inverted color mode, on page 10.
mupdf-gl -I mupdf_explored.pdf 10
Mouse Bindings
The middle mouse button (scroll wheel button) pans the document view.
The right mouse button selects a region and copies the marked text to the clipboard.
Key Bindings
Several commands can take a number argument entered before the key, to modify the command. For example, to zoom to 150 dpi, type “150z”.
F1 |
Display help. |
i |
Show document information. |
o |
Show document outline. |
L |
Highlight links. |
F |
Highlight form fields. |
a |
Show annotation editor. |
r |
Reload document. |
S |
Save document (only for PDF). |
q |
Quit viewer. |
< |
Decrease E-book font size. |
> |
Increase E-book font size. |
I |
Toggle inverted color mode. |
C |
Toggle tinted color mode. |
E |
Toggle ICC color management. |
e |
Toggle spot color emulation. |
A |
Toggle anti-aliasing. |
f |
Toggle fullscreen. |
w |
Shrinkwrap window to fit page. |
W |
Fit page width to window. |
H |
Fit page height to window. |
Z |
Fit page size to window. |
[number] z |
Set zoom resolution in DPI. |
+ |
Zoom in. |
- |
Zoom out. |
[ |
Rotate counter-clockwise. |
] |
Rotate clockwise. |
⬅️➡️⬆️⬇️ or h, j, k, l |
Pan page in small increments. |
b |
Smart move one screenful backward. |
[space] |
Smart move one screenful forward. |
[comma] or [page up] |
Go one page backward. |
[period] or [page down] |
Go one page forward. |
[number] g |
Go to page number. |
G |
Go to last page. |
m |
Save current page to navigation history. |
t |
Go back in navigation history. |
T |
Go forward in navigation history. |
[number] m |
Save current page in numbered bookmark. |
[number] t |
Go to numbered bookmark. |
/ |
Start searching forward. |
? |
Start searching backward. |
n |
Continue searching forward. |
N |
Continue searching backward. |
muraster
This is a much simpler version of mutool draw
command. As such it can be used to quickly rasterize an input file with a set of options.
Command Line Options
muraster [options] file [pages]
[options]
-p
passwordThe password needed to open a password protected PDF file.
-o
filenameThe output file name.
-F
formatThe output format (default inferred from output file name), e.g.
pam
,pbm
,pgm
,pkm
,ppm
.-s
informationShow extra information: -
m
: show memory use. -t
: show timings.-R
rotationSet a rotation for the output (default
auto
): -auto
. -0
. -90
. -180
. -270
. -clockwise
.-r
x,yComma separated x and y resolution in DPI (default: 300,300).
-w
widthPrintable width (in inches) (default: 8.27).
-h
heightPrintable height (in inches) (default: 11.69).
-f
Fit file to page if too large.
-B
heightSet the minimum band height (e.g. 32).
-M
memorySets the maximum band memory (e.g. 655360).
-W
widthPage width for EPUB layout.
-H
heightPage height for EPUB layout.
-S
sizeFont size for EPUB layout.
-U
filenameFile name of user stylesheet for EPUB layout
-X
Disable document styles for EPUB layout
-A
levelSet anti-aliasing level.
0
: off.
2
: 4 levels.
4
: 16 levels.
8
: 256 levels.-A
graphics level / text levelIndependently set the anti-aliasing levels for graphics and text.
e.g.
-A 0/4
.
[pages]
A comma separated list of page numbers and ranges.
Example usage #1:
This will render a raster file from page one of the input file “mupdf_explored.pdf”. The output file will be called “test.ppm”, have a clockwise rotation and specific graphics/text anti-aliasing applied.
muraster -o test.ppm -R clockwise -A 0/8 mupdf_explored.pdf 1
mutool
Note
It is advised to use rlwrap with mutool
for command line history and cursor navigation (this can be also installed via Homebrew or MacPorts).
For rendering and converting documents there are three commands available:
This is the more customizable tool, but also has a more difficult set of command line options. It is primarily used for rendering a document to image files.
This tool is used for converting documents into other formats, and is easier to use.
This is a debugging tool used for printing a trace of the graphics device calls on a page.
There are also several tools specifically for working with PDF files:
A tool for displaying the internal objects in a PDF file.
Extract images and embedded font resources.
Rewrite PDF files. Used to fix broken files, or to make a PDF file human editable.
Merge pages from multiple input files into a new PDF.
Divide pages of a PDF into pieces that can be printed and merged into a large poster.
Create a new PDF file from a text file with graphics commands.
List, verify, and sign digital signatures in PDF files.
Prints details about objects on each page in a PDF file.
Prints the size and rotation of each page in a PDF. Provides information about MediaBox, ArtBox, etc. for each page in a PDF file.
This command allows you to make a modified version of a PDF with content that falls inside or outside of defined boxes removed.
A tool for running JavaScript programs with access to the MuPDF library functions.
mutool JavaScript API
- Global MuPDF methods
- Matrices and Rectangles
- Colors
- Object Protocols
Buffer
Document
Page
StructuredText
ColorSpace
DefaultColorSpaces
Pixmap
new Pixmap()
clear()
bound()
getWidth()
getHeight()
getNumberOfComponents()
getAlpha()
getStride()
getColorSpace()
getXResolution()
getYResolution()
getSample()
setResolution()
saveAsPNG()
saveAsJPEG()
saveAsPAM()
saveAsPNM()
saveAsPBM()
saveAsPKM()
invert()
invertLuminance()
gamma()
tint()
warp()
convertToColorSpace()
DrawDevice
DisplayList
DisplayListDevice
Device
fillPath()
strokePath()
clipPath()
clipStrokePath()
fillText()
strokeText()
clipText()
clipStrokeText()
ignoreText()
fillShade()
fillImage()
fillImageMask()
clipImageMask()
popClip()
beginMask()
endMask()
beginGroup()
endGroup()
beginTile()
endTile()
beginLayer()
endLayer()
renderFlags()
setDefaultColorSpaces()
beginStructure()
endStructure()
beginMetatext()
endMetatext()
close()
Path
Text
Font
Image
DocumentWriter
PDFDocument
new PDFDocument()
new PDFDocument()
getVersion()
save()
canBeSavedIncrementally()
countVersions()
countUnsavedVersions()
validateChangeHistory()
hasUnsavedChanges()
wasPureXFA()
wasRepaired()
setPageLabels()
deletePageLabels()
getTrailer()
countObjects()
createObject()
deleteObject()
enableJS()
disableJS()
isJSSupported()
setJSEventListener()
enableJournal()
getJournal()
beginOperation()
beginImplicitOperation()
endOperation()
canUndo()
canRedo()
undo()
redo()
addObject()
addStream()
addRawStream()
newNull()
newBoolean()
newInteger()
newReal()
newString()
newByteString()
newName()
newIndirect()
newArray()
newDictionary()
countPages()
findPage()
findPageNumber()
deletePage()
insertPage()
addPage()
addSimpleFont()
addCJKFont()
addFont()
addImage()
loadImage()
graftObject()
graftPage()
newGraftMap()
addEmbeddedFile()
getEmbeddedFileParams()
getEmbeddedFileContents()
verifyEmbeddedFileChecksum()
PDFGraftMap
PDFObject
get()
put()
delete()
resolve()
compare()
isArray()
isDictionary()
forEach()
push()
toString()
valueOf()
isIndirect()
asIndirect()
isStream()
readStream()
readRawStream()
writeObject()
writeStream()
writeRawStream()
isNull()
isBoolean()
asBoolean()
isNumber()
asNumber()
isName()
asName()
isString()
asString()
asByteString()
PDFPage
PDFAnnotation
bound()
run()
toPixmap()
toDisplayList()
getObject()
process()
setAppearance()
setAppearance()
update()
getHot()
setHot()
getHiddenForEditing()
setHiddenForEditing()
getType()
getFlags()
setFlags()
getContents()
setContents()
getBorder()
setBorder()
getColor()
setColor()
getOpacity()
setOpacity()
getCreationDate()
setCreationDate()
getModificationDate()
setModificationDate()
getQuadding()
setQuadding()
getLanguage()
setLanguage()
getRect()
setRect()
getDefaultAppearance()
setDefaultAppearance()
hasInteriorColor()
getInteriorColor()
setInteriorColor()
hasAuthor()
getAuthor()
setAuthor()
hasLineEndingStyles()
getLineEndingStyles()
setLineEndingStyles()
hasIcon()
getIcon()
setIcon()
hasLine()
getLine()
setLine()
hasOpen()
isOpen()
setIsOpen()
hasFilespec()
getFilespec()
setFilespec()
hasBorder()
getBorderStyle()
setBorderStyle()
getBorderWidth()
setBorderWidth()
getBorderDashCount()
getBorderDashItem()
setBorderDashPattern()
clearBorderDash()
addBorderDashItem()
hasBorderEffect()
getBorderEffect()
setBorderEffect()
getBorderEffectIntensity()
setBorderEffectIntensity()
hasInkList()
getInkList()
setInkList()
clearInkList()
addInkList()
addInkListStroke()
addInkListStrokeVertex()
hasQuadPoints()
getQuadPoints()
setQuadPoints()
clearQuadPoints()
addQuadPoint()
hasVertices()
getVertices()
setVertices()
clearVertices()
addVertex()
setStampImage()
PDFWidget
getFieldType()
getFieldFlags()
getRect()
setRect()
getMaxLen()
getValue()
setTextValue()
setChoiceValue()
toggle()
getOptions()
layoutTextWidget()
isReadOnly()
getLabel()
getEditingState()
setEditingState()
update()
isSigned()
validateSignature()
checkCertificate()
getSignatory()
previewSignature()
sign()
clearSignature()
eventEnter()
eventExit()
eventDown()
eventUp()
eventFocus()
eventBlur()
PDFPKCS7Signer
OutlineIterator
Archive
MultiArchive
TreeArchive
Story
XML
- PDF Processor
This software is provided AS-IS with no warranty, either express or implied. This software is distributed under license and may not be copied, modified or distributed except as expressly authorized under the terms of that license. Refer to licensing information at artifex.com or contact Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco, CA 94129, USA, for further information.