A Text object contains text. See the Device.prototype.fillText.
Create a new empty text object.
var text = new mupdf.Text()Get the bounds of the instance.
StrokeState) – The
stroking state.Matrix) – The transformation
matrix.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’.
text.showGlyph(new mupdf.Font("Times-Roman"), mupdf.Matrix.identity, 21, 0x66, 0)
text.showGlyph(new mupdf.Font("Times-Roman"), mupdf.Matrix.identity, -1, 0x69, 0)Add a simple string to this Text object. Will do font substitution if the font does not have all the unicode characters required.
text.showString(new mupdf.Font("Times-Roman"), mupdf.Matrix.identity, "Hello World")TextWalker) –
Function with protocol methods, see example below for details.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 = mupdf.PDFDocument.openDocument(fs.readFileSync("test.pdf"), "application/pdf")
var page = doc.loadPage(0)
var device = new mupdf.Device(traceDevice)
page.run(device, mupdf.Matrix.identity)