diff --git a/src/jspdf.js b/src/jspdf.js index 5c73920ed..39b25569c 100644 --- a/src/jspdf.js +++ b/src/jspdf.js @@ -3777,7 +3777,8 @@ function jsPDF(options) { maxWidth = options.maxWidth || 0; var lineWidths; - flags = {}; + flags = Object.assign({ autoencode: true, noBOM: true }, options.flags); + var wordSpacingPerLine = []; if (Object.prototype.toString.call(text) === "[object Array]") { diff --git a/test/reference/text-encoding-flags.pdf b/test/reference/text-encoding-flags.pdf new file mode 100644 index 000000000..c7fb6a2ef Binary files /dev/null and b/test/reference/text-encoding-flags.pdf differ diff --git a/test/specs/text.spec.js b/test/specs/text.spec.js index 34e6b5bfa..f5044db01 100644 --- a/test/specs/text.spec.js +++ b/test/specs/text.spec.js @@ -210,4 +210,24 @@ break` doc.text("hello", 10, 40, { charSpace: 10 }); comparePdf(doc.output(), "letter-spacing.pdf", "text"); }); + + it("should respect autoencode and noBOM flags", () => { + const doc = jsPDF({ floatPrecision: 2 }); + + doc.text("Default:", 10, 10); + doc.text("é'\"´`'\u2019", 150, 10); + + doc.text("autoencode=false:", 10, 30); + doc.text("é'\"´`'\u2019", 150, 30, { flags: { autoencode: false } }); + + doc.text("noBOM=false:", 10, 60); + doc.text("é'\"´`'\u2019", 150, 60, { flags: { noBOM: false } }); + + doc.text("noBOM=false,autoencode=false (garbled):", 10, 90); + doc.text("é'\"´`'\u2019", 150, 90, { + flags: { autoencode: false, noBOM: false } + }); + + comparePdf(doc.output(), "text-encoding-flags.pdf", "text"); + }); });