Jspdf: Problem Date with jspdf.text() in IE and EDGE

Created on 31 Oct 2016  Â·  12Comments  Â·  Source: MrRio/jsPDF

I tried to use the jsPDF to write a date but I can't write correctly.

The code is :

var pdf = new jsPDF('p', 'pt');
var dateOptions = {
                day: "numeric",
                month: "numeric",
                year: "numeric"
            };
pdf.text("in "+ new Date("28/12/2015").toLocaleString("fr-fr", dateOptions), 40, 100);
pdf.text("in 28/12/2015", 40, 125);
pdf.text("in "+new Date("28/12/2015").toString, 40, 150);

The result is :

 i  n     2 8   /   1 2   /   2 0 1 5
in 28/12/2015
in Mon Dec 28 2015 01:00:00 GMT+0100 (Paris, Madrid)

The problem is that insert many blank space between letters. This problem appear if I use date toLocaleString function and the Browers IE or EDGE.
Is there any solution?

thanks in advance

Most helpful comment

I found the solution. I detected the character and I replaced it.

text = text.replace(/[\u200E]/g, '');

All 12 comments

Strange. When I want to use your format "dd/mm/yyyy" in chrome i get "Invalid Date". In IE it shows me a date in 2017...

the right order should be mm/dd/yyyy..

Sorry but I use the datepicker. It give me a "dd/mm/yyyy". But the problem is not the entred format but the result in pdf. It write it with many spaces between numbers and letters in IE and EDGE.

Do you use Font_metrics.js?

No, I use
"jspdf.js"
"jspdf.plugin.autotable.js"
and a personalized library : "jspdf.personalizedApi.js" to place a text centre and right
it contains :

(function (API) {
    API.myText = function (txt, options, x, y) {
        options = options || {};
        if (options.align == "center") {
            var fontSize = this.internal.getFontSize();
            var pageWidth = this.internal.pageSize.width;
            txtWidth = this.getStringUnitWidth(txt) * fontSize / this.internal.scaleFactor;
            x = (pageWidth - txtWidth) / 2;
        }
        if (options.align == "right") {
            var fontSize = this.internal.getFontSize();
            var pageWidth = this.internal.pageSize.width;
            txtWidth = this.getStringUnitWidth(txt) * fontSize / this.internal.scaleFactor;
            x = pageWidth - txtWidth - x;
        }
        this.text(txt, x, y);
    }
})(jsPDF.API);

I get it from stackoverflow issue

What happens if you use font metrics and not the aligning Plugin?

Am 02.11.2016 13:55 schrieb "ahmedmahdi" [email protected]:

No, I use
"jspdf.js"
"jspdf.plugin.autotable.js"
and a personalized library : "jspdf.personalizedApi.js" to place a text
centre and right
it contains :

(function (API) {
API.myText = function (txt, options, x, y) {
options = options || {};
if (options.align == "center") {
var fontSize = this.internal.getFontSize();
var pageWidth = this.internal.pageSize.width;
txtWidth = this.getStringUnitWidth(txt) * fontSize /
this.internal.scaleFactor;
x = (pageWidth - txtWidth) / 2;
}
if (options.align == "right") {
var fontSize = this.internal.getFontSize();
var pageWidth = this.internal.pageSize.width;
txtWidth = this.getStringUnitWidth(txt) * fontSize /
this.internal.scaleFactor;
x = pageWidth - txtWidth - x;
}
this.text(txt, x, y);
}
})(jsPDF.API);

I get it from stackoverflow issue

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/MrRio/jsPDF/issues/937#issuecomment-257856143, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AE0yHKDmBtRdv5VmczDxxYqv-CZTQr2Eks5q6IhPgaJpZM4KlP_H
.

how use it?
I don't find any documentation of Font_metrics.js

Just include the file to your html

Am 02.11.2016 15:56 schrieb "ahmedmahdi" [email protected]:

how use it?
I don't find any documentation of Font_metrics.js

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/MrRio/jsPDF/issues/937#issuecomment-257889482, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AE0yHIAFIg54ig0B9WPmzZ3MmjVB6v0xks5q6KSngaJpZM4KlP_H
.

I do it but it is the same things. I have analyzed more, and I discover that IE and EDGE insert invisible character in the string.
I don't know if this post retranscribe the character: in <<"IN ‎28‎">> between <<8>> and <<">> there is an invisible character.

Please provide sample code

Am 02.11.2016 17:51 schrieb "ahmedmahdi" [email protected]:

I do it but it is the same things. I have analyzed more, and I discover
that IE and EDGE insert invisible character in the string.
I don't know if this post retranscribe the character: in <<"IN ‎28‎">>
between <<8>> and <<">> there is an invisible character.

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/MrRio/jsPDF/issues/937#issuecomment-257925946, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AE0yHIz_iHlHDlabm7oO6YgPJYtVpmfdks5q6L-XgaJpZM4KlP_H
.

I found the solution. I detected the character and I replaced it.

text = text.replace(/[\u200E]/g, '');

thank you very much arasabbasi for your help :)

I found the solution. I detected the character and I replaced it.

text = text.replace(/[\u200E]/g, '');
Hi Ahmed,

Found this very helpful

Regards,
Sagarika

Was this page helpful?
0 / 5 - 0 ratings

Related issues

andmaltes picture andmaltes  Â·  4Comments

mackersD picture mackersD  Â·  4Comments

MaxCodeDE picture MaxCodeDE  Â·  4Comments

centurianii picture centurianii  Â·  4Comments

sayo96 picture sayo96  Â·  3Comments