Text#
A Text object contains text. See the fillText()
method on Device for more.
CONSTRUCTOR METHODS
INSTANCE METHODS
- getBounds(strokeState: StrokeState, transform: Matrix)#
Get the bounds of the instance.
- Parameters:
strokeState – StrokeState.
transform – Matrix.
- showGlyph(font: Font, trm: Matrix, gid: number, uni: number, wmode: number = 0)#
Add a glyph to the text object.
Transform is the text matrix, specifying font size and glyph location. For example:
[size,0,0,-size,x,y]
.Glyph and unicode may be
-1
for n-to-m cluster mappings. For example, the “fi” ligature would be added in two steps: first the glyph for the ‘fi’ ligature and the unicode value for ‘f’; then glyph-1
and the unicode value for ‘i’.- Parameters:
EXAMPLE
text.showGlyph(new mupdfjs.Font("Times-Roman"), mupdfjs.Matrix.identity, 21, 0x66, 0); text.showGlyph(new mupdfjs.Font("Times-Roman"), mupdfjs.Matrix.identity, -1, 0x69, 0);
- showString(font: Font, trm: Matrix, str: string, wmode: number = 0)#
Add a simple string to the Text object. Will do font substitution if the font does not have all the unicode characters required.
- Parameters:
EXAMPLE
text.showString(new mupdfjs.Font("Times-Roman"), mupdfjs.Matrix.identity, "Hello World");
- walk(walker: TextWalker)#
- Parameters:
walker –
TextWalker
. Function with protocol methods, see example below for details.
EXAMPLE
function print(...args) { console.log(args.join(" ")) } var textPrinter = { beginSpan: function (f,m,wmode, bidi, dir, lang) { print("beginSpan",f,m,wmode,bidi,dir,Q(lang)); }, showGlyph: function (f,m,g,u,v,b) { print("glyph",f,m,g,String.fromCodePoint(u),v,b)}, endSpan: function () { print("endSpan"); } } var traceDevice = { fillText: function (text, ctm, colorSpace, color, alpha) { print("fillText", ctm, colorSpace, color, alpha) text.walk(textPrinter) }, clipText: function (text, ctm) { print("clipText", ctm) text.walk(textPrinter) }, strokeText: function (text, stroke, ctm, colorSpace, color, alpha) { print("strokeText", Q(stroke), ctm, colorSpace, color, alpha) text.walk(textPrinter) }, clipStrokeText: function (text, stroke, ctm) { print("clipStrokeText", Q(stroke), ctm) text.walk(textPrinter) }, ignoreText: function (text, ctm) { print("ignoreText", ctm) text.walk(textPrinter) } } var doc = mupdfjs.PDFDocument.openDocument(fs.readFileSync("test.pdf"), "application/pdf") var page = doc.loadPage(0) var device = new mupdfjs.Device(traceDevice) page.run(device, mupdfjs.Matrix.identity)
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"