Skip to content
This repository has been archived by the owner on Feb 28, 2019. It is now read-only.

FromHTML custom font #37

Open
Zeus6221 opened this issue Apr 17, 2018 · 2 comments
Open

FromHTML custom font #37

Zeus6221 opened this issue Apr 17, 2018 · 2 comments

Comments

@Zeus6221
Copy link

Hi, actually I used the code example, but when I try to use a personalized font, this doesn't work whit fromHTML function.

I saw the code inside jspdf.customfonts.debug.js and I think that the issue can be inside the ResolveFont function, this because this function always returns font-family "times", nevertheless other css properties works correctly (color for example).
this is my code:

I added the PersonalizedFont.ttf file to the fonts folder and also I modified the default_vfs.js file whit my font in base64, in this case the doc.text(15, 15, 'Hello world'); takes the correct font but the, doc.fromHTML does't.

Could you please help whit this problem.

$(document).ready(function () {

            var doc = new jsPDF();

            var specialElementHandlers = {
                '#editor': function (element, renderer) {
                    return true;
                }
            };

            $('#cmd').click(function () {

                var doc = new jsPDF();
                doc.addFont('PersonalizedFont.ttf', 'PersonalizedFont', 'normal');
                doc.setFont('PersonalizedFont');
                var html = "<!DOCTYPE html>\
                                <html>\
                                <head>\
                                        <style>\
                                            @font-face {\
                                                font-family: GamjaFlower;\
                                                src: url('./fonts/PersonalizedFont.ttf');\
                                                font-weight: bold;\
                                            }\
                                            p   {\
                                                    font-family: GamjaFlower;\
                                                    color: blue;\
                                                }\
                                        </style>\
                                </head>\
                                <body>\
                                 <p>\
                                        Lorem ipsum dolor sit amet, consectetur adipisicing elit,\
                                        sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\
                                        Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris\
                                        nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor\
                                        in reprehenderit in voluptate velit esse cillum dolore eu fugiat\
                                        nulla pariatur. Excepteur sint occaecat cupidatat non proident,\
                                        sunt in culpa qui officia deserunt mollit anim id est laborum.\
                                        Hola mundo FromHTML\
                                        </p>\
                                </body>\
                                </html>";
                doc.fromHTML(html, 15, 15, {
                    'width': 170,
                    'elementHandlers': specialElementHandlers
                });


                doc.addFont('PersonalizedFont.ttf', 'PersonalizedFont', 'normal');
                doc.setFont('PersonalizedFont');
                doc.text(15, 15, 'Hello world');
                doc.save('PersonalizedFont.pdf');
            });
        });
@nataliawww
Copy link

+1

1 similar comment
@danielhultman
Copy link

+1

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants