Device#
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 must be balanced with a corresponding popClip
.
CONSTRUCTOR METHODS
- constructor(callbacks: DeviceFunctions)#
Create a Device with callback functions.
- Parameters:
callbacks – object containing optional functions which conform to the
DeviceFunctions
interface.
INSTANCE METHODS
- fillPath(path: Path, evenOdd: boolean, ctm: Matrix, colorspace: ColorSpace, color: Color, alpha: number)#
Fill a path.
- Parameters:
path – Path object.
evenOdd –
boolean
. The even odd rule to use.ctm – Matrix.
colorspace – The ColorSpace.
color – Color.
alpha –
number
. The alpha.
EXAMPLE
device.fillPath(path, false, mupdfjs.Matrix.identity, mupdfjs.ColorSpace.DeviceRGB, [1,0,0], true);
- strokePath(path: Path, stroke: StrokeState, ctm: Matrix, colorspace: ColorSpace, color: Color, alpha: number)#
Stroke a path.
- Parameters:
path – Path object.
stroke – StrokeState.
ctm – Matrix.
colorspace – The ColorSpace.
color – Color.
alpha –
number
. The alpha.
EXAMPLE
device.strokePath(path, {dashes:[5,10], lineWidth:3, lineCap:'Round'}, mupdfjs.Matrix.identity, mupdfjs.ColorSpace.DeviceRGB, [0,1,0], 0.5);
- clipPath(path: Path, evenOdd: boolean, ctm: Matrix)#
Clip a path.
- Parameters:
path – Path object.
evenOdd –
boolean
. The even odd rule to use.ctm – Matrix.
EXAMPLE
device.clipPath(path, true, mupdfjs.Matrix.identity);
- clipStrokePath(path: Path, stroke: StrokeState, ctm: Matrix)#
Clip & stroke a path.
- Parameters:
path – Path object.
stroke – StrokeState object.
ctm – Matrix.
EXAMPLE
device.clipStrokePath(path, true, mupdfjs.Matrix.identity);
- fillText(text: Text, ctm: Matrix, colorspace: ColorSpace, color: Color, alpha: number)#
Fill a text object.
- Parameters:
text – Text object.
ctm – Matrix.
colorspace – The ColorSpace.
color – Color.
alpha –
number
. The alpha.
EXAMPLE
device.fillText(text, mupdfjs.Matrix.identity, mupdfjs.ColorSpace.DeviceRGB, [1,0,0], 1);
- strokeText(text: Text, stroke: StrokeState, ctm: Matrix, colorspace: ColorSpace, color: Color, alpha: number)#
Stroke a text object.
- Parameters:
text – Text object.
stroke – StrokeState object.
ctm – Matrix.
colorspace – The ColorSpace.
color – Color.
alpha –
number
. The alpha.
EXAMPLE
device.strokeText(text, {dashes:[5,10], lineWidth:3, lineCap:'Round'}, mupdfjs.Matrix.identity, mupdfjs.ColorSpace.DeviceRGB, [1,0,0], 1);
- clipText(text: Text, ctm: Matrix)#
Clip a text object.
EXAMPLE
device.clipText(text, mupdfjs.Matrix.identity);
- clipStrokeText(text: Text, stroke: StrokeState, ctm: Matrix)#
Clip & stroke a text object.
- Parameters:
text – Text object.
stroke – StrokeState object.
ctm – Matrix.
EXAMPLE
device.clipStrokeText(text, {dashes:[5,10], lineWidth:3, lineCap:'Round'}, mupdfjs.Matrix.identity);
- ignoreText(text: Text, ctm: Matrix)#
Invisible text that can be searched but should not be visible, such as for overlaying a scanned OCR image.
EXAMPLE
device.ignoreText(text, mupdfjs.Matrix.identity);
- fillShade(shade: Shade, ctm: Matrix, alpha: number)#
Fill a shade (a.k.a. gradient).
Note
The details of gradient fills are not exposed to JavaScript yet.
EXAMPLE
device.fillShade(shade, mupdfjs.Matrix.identity, true, {overPrinting:true});
- fillImage(image: Image, ctm: Matrix, alpha: number)#
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.EXAMPLE
device.fillImage(image, mupdfjs.Matrix.identity, false, {overPrinting:true});
- fillImageMask(image: Image, ctm: Matrix, colorspace: ColorSpace, color: Color, alpha: number)#
An image mask is an image without color. Fill with the color where the image is opaque.
- Parameters:
image – Image object.
ctm – Matrix.
colorspace – The ColorSpace.
color – Color.
alpha –
number
. The alpha.
EXAMPLE
device.fillImageMask(image, mupdfjs.Matrix.identity, mupdfjs.ColorSpace.DeviceRGB, [0,1,0], true);
- clipImageMask(image: Image, ctm: Matrix)#
Clip graphics using the image to mask the areas to be drawn.
EXAMPLE
device.clipImageMask(image, mupdfjs.Matrix.identity);
- popClip()#
Pop the clip mask installed by the last clipping operation.
EXAMPLE
device.popClip();
- beginMask(area: Rect, luminosity: boolean, colorspace: ColorSpace, color: Color)#
Create a soft mask. Any drawing commands between
beginMask
andendMask
are grouped and used as a clip mask.- Parameters:
area – Rect. Mask area.
luminosity –
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 – ColorSpace.
color – Color.
EXAMPLE
device.beginMask([0,0,100,100], true, mupdfjs.ColorSpace.DeviceRGB, [1,0,1]);
- endMask()#
Ends the mask.
EXAMPLE
device.endMask();
- beginGroup(area: Rect, colorspace: ColorSpace, isolated: boolean, knockout: boolean, blendmode: BlendMode, alpha: number)#
Push/pop a transparency blending group. See the PDF reference for details on
isolated
andknockout
.- Parameters:
area – Rect. The blend area.
colorspace – ColorSpace.
isolated –
boolean
.knockout –
boolean
.blendmode – BlendMode is one of the standard PDF blend modes.
alpha –
nu,ber
. The alpha.
EXAMPLE
device.beginGroup([0,0,100,100], mupdfjs.ColorSpace.DeviceRGB, true, true, "Multiply", 0.5);
- endGroup()#
Ends the blending group.
EXAMPLE
device.endGroup();
- beginTile(area: Rect, view: Rect, xstep: number, ystep: number, ctm: Matrix, id: number)#
Draw a tiling pattern. Any drawing commands between
beginTile
andendTile
are grouped and then repeated across the whole page. Apply a clip mask to restrict the pattern to the desired shape.- Parameters:
area – Rect.
view – Rect.
xstep –
number
representingx
step.ystep –
number
representingy
step.ctm – Matrix.
id –
number
. The purpose ofid
is to allow for efficient caching of rendered tiles. Ifid
is0
, then no caching is performed. If it is non-zero, then it assumed to uniquely identify this tile.
EXAMPLE
device.beginTile([0,0,100,100], [100,100,200,200], 10, 10, mupdfjs.Matrix.identity, 0);
- endTile()#
Ends the tiling pattern.
EXAMPLE
device.endTile();
- beginLayer(name: string)#
Begin a marked-content layer with the given name.
- Parameters:
name –
string
.
EXAMPLE
device.beginLayer("my tag");
- endLayer()#
End a marked-content layer.
EXAMPLE
device.endLayer();
- close()#
Tell the device that we are done, and flush any pending output. Ensure that no items are left on the stack before closing.
EXAMPLE
device.close();
Code samples
Code samples are in TypeScript and assume that the following requirements are defined in your TypeScript file header as follows:
import * as fs from "fs"
import * as mupdfjs from "mupdf/mupdfjs"