All built-in devices have the methods listed below. Any function that accepts a device will also accept a Javascript object with the same methods. Any missing methods are simply ignored, so you only need to create methods for the device calls you care about.
Many of the methods take graphics objects as arguments: Path, Text, Image and Shade.
Colors are specified as arrays with the appropriate number of components for the color space.
The methods that clip graphics, e.g. Device.prototype.clipPath(),
Device.prototype.clipStrokePath(),
Device.prototype.clipText(),
etc., must be balanced with a corresponding Device.prototype.popClip().
Create a Device which calls back to Javascript.
The callback object may provide functions matching the methods on the Device class. Any device calls that don’t have a corresponding function will simply be ignored.
You can create other devices with DrawDevice and DisplayListDevice.
Blend mode
constants for use with Device.prototype.beginGroup:
Tell this device that we are done, and flush any pending output.
Before closing, ensure that there have been as many calls to popClip() as there
have been to the clipping functions: clipPath(), clipStrokePath(),
clipText(),
etc.
device.close()Fill a path.
Path) – Path object.boolean) – Use even-odd rule
or non-zero
winding number rule to fill the path.Matrix) – The transform to
apply.ColorSpace) – The
colorspace of the color to fill with.Color) – The color to fill the
path with.number) – The opacity.device.fillPath(path, false, mupdf.Matrix.identity, mupdf.ColorSpace.DeviceRGB, [1, 0, 0], true)Stroke a path.
Path) – Path object.StrokeState) –
Stroke state.Matrix) – The transform to
apply.ColorSpace) –
Colorspace.Color) – The color to stroke
the path with.number) – The opacity.device.strokePath(path,
{dashes: [5, 10], lineWidth: 3, lineCap: 'Round' },
mupdf.Matrix.identity,
mupdf.ColorSpace.DeviceRGB,
[0, 1, 0],
0.5
)Clip a path.
Path) – Path object.boolean) – Use even-odd rule
or non-zero
winding number rule to fill the path.Matrix) – The transform to
apply.device.clipPath(path, true, mupdf.Matrix.identity)Clip & stroke a path.
Path) – Path object.StrokeState) –
Stroke state.Matrix) – The transform to
apply.device.clipStrokePath(path, true, mupdf.Matrix.identity)Fill a text object.
Text) – Text object.Matrix) – The transform to
apply.ColorSpace) –
ColorspaceColor) – The color used to fill
the text.number) – The opacity.device.fillText(text, mupdf.Matrix.identity, mupdf.ColorSpace.DeviceRGB, [1, 0, 0], 1)Stroke a text object.
Text) – Text object.StrokeState) –
Stroke state.Matrix) – The transform to
apply.ColorSpace) –
ColorspaceColor) – The color used to
stroke the text.number) – The opacity.device.strokeText(text,
{ dashes: [5, 10], lineWidth: 3, lineCap: 'Round' },
mupdf.Matrix.identity,
mupdf.ColorSpace.DeviceRGB,
[1, 0, 0],
1
)Clip a text object.
device.clipText(text, mupdf.Matrix.identity)Clip & stroke a text object.
Text) – Text object.StrokeState) –
stroke state.Matrix) – The transform to
apply.device.clipStrokeText(text,
{ dashes: [5, 10], lineWidth: 3, lineCap: 'Round' },
mupdf.Matrix.identity
)Invisible text that can be searched but should not be visible, such as for overlaying a scanned OCR image.
device.ignoreText(text, mupdf.Matrix.identity)Fill a shading, also known as a gradient.
device.fillShade(shade, mupdf.Matrix.identity, true, { overPrinting: true })Draw an image. An image always fills a unit rectangle [0, 0, 1, 1], so must be transformed to be placed and drawn at the appropriate size.
device.fillImage(image, mupdf.Matrix.identity, false, { overPrinting: true })An image mask is an image without color. Fill with the color where the image is opaque.
Image) – Image object.Matrix) – The transform to
apply.ColorSpace) –
ColorspaceColor) – The color to be
used.number) – The opacity.device.fillImageMask(image, mupdf.Matrix.identity, mupdf.ColorSpace.DeviceRGB, [0, 1, 0], true)Clip graphics using the image to mask the areas to be drawn.
device.clipImageMask(image, mupdf.Matrix.identity)Pop the clip mask installed by the last clipping operation.
device.popClip()Create a soft mask. Any drawing commands between beginMask and endMask are grouped
and used as a clip mask.
Rect) – Mask area.boolean) – If luminosity
is true, the mask is derived from the luminosity (grayscale
value) of the graphics drawn; otherwise the color is ignored completely
and the mask is derived from the alpha of the group.ColorSpace) –
ColorspaceColor) – The color to be
used.device.beginMask([0, 0, 100, 100], true, mupdf.ColorSpace.DeviceRGB, [1, 0, 1])Ends the mask.
device.endMask()Begin a transparency blending group. See knockout and isolation and blend mode in the glossary for a cursory overview of the concepts.
Rect) – The blend area.ColorSpace) –
Colorspaceboolean) – Whether the group
is isolated.boolean) – Whether the group
is knockout.string) – The blend mode
used when compositing this group with its backdrop.number) – The opacity.The blendmode is one of these string values or the corresponding enum constants: Normal, Multiply, Screen, Overlay, Darken, Lighten, ColorDodge, ColorBurn, HardLight, SoftLight, Difference, Exclusion, Hue, Saturation, Color, Luminosity.
You can also use the Device.BLEND_NORMAL
constant:
device.beginGroup(
[0, 0, 100, 100],
mupdf.ColorSpace.DeviceRGB,
true,
true,
"Multiply",
0.5
)Ends the blending group.
device.endGroup()Draw a tiling pattern. Any drawing commands between beginTile and endTile are grouped
and then repeated across the whole page. Apply a clip mask to restrict
the pattern to the desired shape.
Rect) – AreaRect) – Viewnumber) – x step.number) – y step.Matrix) – The transform to
apply.number)number) – The purpose of
id/doc_id is to allow for efficient caching of rendered tiles. If id is
0, then no caching is performed. If it is non-zero, then id/doc_id are
assumed to uniquely identify this tile.device.beginTile([0, 0, 100, 100], [100, 100, 200, 200], 10, 10, mupdf.Matrix.identity, 0)Ends the tiling pattern.
device.endTile()only mutool run
The specified rendering flags are set, and some others are cleared.
Both set and clear are arrays where each element one of these flag names:
“mask”
“color”
“uncacheable”
“fillcolor-undefined”
“strokecolor-undefined”
“startcap-undefined”
“dashcap-undefined”
“endcap-undefined”
“linejoin-undefined”
“miterlimit-undefined”
“linewidth-undefined”
“bbox-defined”
“gridfit-as-tiled”
Arguments:
Array of string) – Rendering
flags to set.Array of string) – Rendering
flags to clear.device.renderFlags(["mask", "startcap-undefined"], [])only mutool run
Change the set of default device colorspaces to one given.
DefaultColorSpaces)
– The new set of default colorspaces.var defaultCS = new DefaultColorSpaces()
defaultCS.setDefaultRGB(defaultCS.getDefaultGray())
device.setDefaultColorSpaces(new DefaultColorSpaces())Begin a marked-content layer with the given name.
string) – Name of this
marked-content layer.device.beginLayer("my tag")End a marked-content layer.
device.endLayer()only mutool run
Begin a standard structure type with the raw tag name and a unique identifier.
string) – One of the
pre-defined structure types in PDF.string) – The tag name.number) – A unique
identifier.device.beginStructure("Document", "my_tag_name", 123)only mutool run
End a standard structure element.
device.endStructure()only mutool run
Begin meta text where meta is either of:
“ActualText”
“Alt”
“Abbreviation”
“Title”
Arguments:
string) – The meta text
typestring) – The text value.device.beginMetatext("Title", "My title")only mutool run
End meta text information.
device.endMetatext()