diff --git a/src/jspdf.js b/src/jspdf.js index 7b281b139..a887774db 100644 --- a/src/jspdf.js +++ b/src/jspdf.js @@ -3404,6 +3404,7 @@ function jsPDF(options) { * @param {number|Matrix} [options.angle=0] - Rotate the text clockwise or counterclockwise. Expects the angle in degree. * @param {number} [options.rotationDirection=1] - Direction of the rotation. 0 = clockwise, 1 = counterclockwise. * @param {number} [options.charSpace=0] - The space between each letter. + * @param {number} [options.horizontalScale=1] - Horizontal scale of the text as a factor of the regular size. * @param {number} [options.lineHeightFactor=1.15] - The lineheight of each line. * @param {Object} [options.flags] - Flags for to8bitStream. * @param {boolean} [options.flags.noBOM=true] - Don't add BOM to Unicode-text. @@ -3440,7 +3441,7 @@ function jsPDF(options) { */ options = options || {}; var scope = options.scope || this; - var payload, da, angle, align, charSpace, maxWidth, flags; + var payload, da, angle, align, charSpace, maxWidth, flags, horizontalScale; // Pre-August-2012 the order of arguments was function(x, y, text, flags) // in effort to make all calls have similar signature like @@ -3707,6 +3708,11 @@ function jsPDF(options) { this.setCharSpace(this.getCharSpace() || 0); } + horizontalScale = options.horizontalScale; + if (typeof horizontalScale !== "undefined") { + xtra += hpf(horizontalScale * 100) + " Tz\n"; + } + //lang var lang = options.lang; diff --git a/test/reference/text-horizontal-scaling.pdf b/test/reference/text-horizontal-scaling.pdf new file mode 100644 index 000000000..18cf105b2 Binary files /dev/null and b/test/reference/text-horizontal-scaling.pdf differ diff --git a/test/specs/text.spec.js b/test/specs/text.spec.js index f5044db01..168eb31ff 100644 --- a/test/specs/text.spec.js +++ b/test/specs/text.spec.js @@ -211,6 +211,15 @@ break` comparePdf(doc.output(), "letter-spacing.pdf", "text"); }); + it("should render horizontally scaled text", () => { + const doc = jsPDF({ floatPrecision: 2 }); + doc.text("hello", 10, 10, { horizontalScale: 0.5 }); + doc.text("hello", 10, 20, { horizontalScale: 0.75 }); + doc.text("hello", 10, 30, { horizontalScale: 1 }); + doc.text("hello", 10, 40, { horizontalScale: 1.5 }); + comparePdf(doc.output(), "text-horizontal-scaling.pdf", "text"); + }); + it("should respect autoencode and noBOM flags", () => { const doc = jsPDF({ floatPrecision: 2 }); diff --git a/types/index.d.ts b/types/index.d.ts index af7f204af..78543dc0c 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -549,6 +549,7 @@ declare module "jspdf" { }; rotationDirection?: 0 | 1; charSpace?: number; + horizontalScale?: number; lineHeightFactor?: number; maxWidth?: number; renderingMode?: