Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gulp not creating vfs_font.js file correctly #828

Closed
ashijay opened this issue Jan 15, 2017 · 9 comments
Closed

Gulp not creating vfs_font.js file correctly #828

ashijay opened this issue Jan 15, 2017 · 9 comments

Comments

@ashijay
Copy link

ashijay commented Jan 15, 2017

Hi,

I have included timesnewroman.tff file in examples/fonts and was able to run the command gulp buildFonts successfully but while using the updated font file in the code I am getting below error:

TypeError: this.name is undefined

And it is not taking the latest ttf name which I am seeing in the JS files.
Below is the code:

            pdfMake.fonts = {
            myFont: {
                normal: 'Times New Roman.ttf',
                bold: 'Times New Roman.ttf',
                italics: 'Times New Roman.ttf',
                bolditalics: 'Times New Roman.ttf'
            }
          };

          var docDefinition = { 
            content: 'this is sample  content',
            defaultStyle: {
              font: 'myFont'
            }
          };

          pdfMake.createPdf(docDefinition).open();

Please help me with the issue.

@liborm85
Copy link
Collaborator

Can you provide download link to font?

@ashijay
Copy link
Author

ashijay commented Jan 15, 2017

here is the link:
http://www.free-fonts-ttf.org/true-type-fonts/times-new-roman-normal-6599-download.htm

I clicked on "Download zip" link

@liborm85
Copy link
Collaborator

I generated from TTF file this VFS file: vfs_fonts_times_new_roman.js.zip and all works correct.
Have you correct defined files for font as say https://github.com/bpampuch/pdfmake/wiki/Custom-Fonts---client-side ?

@ashijay
Copy link
Author

ashijay commented Jan 15, 2017

yeah I have followed up all the steps. Also I tried with yuor zip and getting the same error. So I am not sure exactly where the issue is coming.

Below is the code snippet, its not even complicated yet :)
Please check this on your end if this is working.

<title>PDFMake</title> <script src="pdfmake.min.js"></script> <script src="vfs_fonts_times_new_roman.js"></script> <script type="text/javascript"> function demoFromHTML() {
          //setting local fonts
          pdfMake.fonts = {
            myFont: {
                normal: 'Times_New_Roman_Normal.ttf',
                bold: 'Times_New_Roman_Normal.ttf',
                italics: 'Times_New_Roman_Normal.ttf',
                bolditalics: 'Times_New_Roman_Normal.ttf'
            }
          };
                                      
          var docDefinition = { 
            content: 'This is the test content',
            //applying fonts
            defaultStyle: {
              font: 'myFont'
            }
          };
          
          // open the PDF in a new window
          pdfMake.createPdf(docDefinition).open();
           
          // download the PDF
          pdfMake.createPdf(docDefinition).download();
       
    }
  </script>

</head>
<body>
   <a href="javascript:demoFromHTML()" class="button">Run Code</a>
    <div id="content">
        <h1>  
            Hello world!
        </h1>
     </div>
</body>

@ashijay
Copy link
Author

ashijay commented Jan 16, 2017

i tried to load fonts on page load but that too didn't worked. Could you also paste me the code which worked for you? Am I using the correct name for fonts as mentioned above?

@liborm85
Copy link
Collaborator

Your code does not work. I have long researched why... and the result is surprising...
In <head> must be <meta charset="utf-8"> and then it works.

@ashijay
Copy link
Author

ashijay commented Jan 16, 2017

surprisingly the error went way and the font started to working fine.
Thank you so much!!!

Additionally, I tried some other fonts and those are working like charm as well but in our application, we support some other languages like chinese, japanese and greek letters and I tried to use font Arial unicode for the same but seems that didn't resolve the issue and those characters with some special characters are still not comings fine.

Do PDFMake supports Arial Unicode ?

@ashijay
Copy link
Author

ashijay commented Jan 16, 2017

Have used http://ufonts.com/download/arial-unicode-ms/197925.html link to download arial unicode ttf file

@ashijay
Copy link
Author

ashijay commented Jan 16, 2017

my bad, I resolved it but not without your help! ;)

My html was coded in ANSI since I am using pspad editor on windows. As soon as I converted it in UTF-8, it resolved the issue and I am able to see lots of characters now. Only few are not visible which are special character that I will check.

Thank you for great support through this!!!

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

No branches or pull requests

2 participants