Page 1 of 1

plugins.VelocityReport.installFonts(); returning false

PostPosted: Tue Aug 03, 2021 3:48 am
by roddy
I have copied a TTF font file into the fonts/ subfolder of the velocityreport.reportfolder setting. When I call
Code: Select all
plugins.VelocityReport.installFonts();
it is returning false. The file does not appear in the home .servoy directory (there should be a fonts folder).

Would anyone know if there is any way of determining what is going wrong? Is there a step I'm missing?

Thanks in advance,

Re: plugins.VelocityReport.installFonts(); returning false

PostPosted: Tue Aug 03, 2021 8:50 pm
by ptalbot
This method is useful for Smart Client only. It pushes the font on the client's machine to be used in PDF reports.
For all other types of clients Web/NG/Velocity/headless this method does nothing.

For a font (other than system fonts) to be used in a report it has to be installed on the system where the PDF is generated.
For all clients except Smart, this is the server system, so the font has to be installed on the server.

Re: plugins.VelocityReport.installFonts(); returning false

PostPosted: Wed Aug 04, 2021 2:25 am
by roddy
Thanks, that is great to know. Really appreciate the feedback.

Re: plugins.VelocityReport.installFonts(); returning false

PostPosted: Wed Aug 04, 2021 4:16 am
by ptalbot
No problem! Glad to hear you're giving the plugin a try, I'm pretty proud of this project which is more than 10 years old and that I've maintained and grown to be a real Swiss tool with many applications making it an essential addition to any Servoy install.
There's tons you can do with it, more than just its reporting capabilities, like building REST APIs, or even creating entire web apps with Velocity Web Client giving you total freedom on the templating/framework you use client-side.

Re: plugins.VelocityReport.installFonts(); returning false

PostPosted: Tue Oct 19, 2021 4:39 am
by roddy
Sorry for the delay in this...

I have installed the font onto my local machine and it is not being picked up when I render the PDF using plugins.VelocityReport.getPDFReport(). However, it is being picked up if I open the page directly in a browser.

I've used the following CSS to set it:
Code: Select all
<head>
   <style type="text/css"> 
      body {
         font-family: 'Montserrat', serif;
         font-size: 14px;
      }
   </style>
</head>

Re: plugins.VelocityReport.installFonts(); returning false

PostPosted: Tue Oct 19, 2021 5:40 am
by ptalbot
Please try with the latest version of the Velocity plugin (v3.5.91) where I have fixed a few things.
You will have to put the fonts file (in either .ttf/.otf/.ttc format) in a /fonts folder inside your velocity reports folder (the velocity reports folder is the one that is pointed at by the velocityreport.reportFolder property in servoy-admin)
Also make sure you use the correct case for your font in the font-family CSS (the iText lib is embedding the fonts in the PDF based on their internal name which is case sensitive).

Re: plugins.VelocityReport.installFonts(); returning false

PostPosted: Tue Oct 19, 2021 7:26 am
by roddy
Thanks for that :-)

I've upgraded to the latest version; you mentioned previously that the instructions were for the Web Client and not NG Client? So we still need to copy the font even for NG Client?

Re: plugins.VelocityReport.installFonts(); returning false

PostPosted: Tue Oct 19, 2021 7:36 am
by roddy
Not getting any love yet :-(

I've installed the font and tried copying across the Montserrat ttf files to the fonts sub-folder. I put the Montserrat-Regular.ttf, Montserrat-Bold.ttf and Montserrat-Italic.ttf; then I just removed them and put the regular one in as Montserra.ttf. I restarted the app each time. And restarted Servoy too but to no avail.

When we specify the font family in the CSS as above; does it look for the exact name in the fonts folder or as an installed font?

Re: plugins.VelocityReport.installFonts(); returning false

PostPosted: Tue Oct 19, 2021 8:01 pm
by ptalbot
Yes, you need to put the fonts in a/fonts folder, this is what I've changed when realizing that iText doesn't pick system installed fonts apart from a few standard one.
So when the PDF is produced, I force all fonts found in the fonts folder into the iText context, then they are available if they are used in your CSS.

Now I did a simple test, putting the "Montserrat-Regular.ttf" file into the $REPORTS_FOLDER$/fonts/ folder, with this simple HTML template:
Code: Select all
<!DOCTYPE html>
<!-- HTML5 -->
<html lang="en">
   <head>
      <title>Font test</title>      
      <style>
         .container {
            margin: auto;
         }
         
         .montserrat {
            font-family: 'Montserrat', serif;
            font-size: 24pt;
         }
      
         @page {
            size: letter landscape;
            margin: 1.4in .4in .6in .4in;
         }
      </style>
   </head>
   <body>

      <div class="container">
         <p class="monserrat">Monserrat font</p>
      </div>

   </body>
</html>

And got a resulting PDF with the Montserrat font embedded.

So perhaps, check that you are pointing to the correct velocity reports folder, and that you have your fonts in a folder called "fonts" (case sensitive) at the root of the velocity reports folder, like reports/fonts/Montserrat-regular.ttf and it should work.

Re: plugins.VelocityReport.installFonts(); returning false

PostPosted: Tue Oct 19, 2021 11:37 pm
by roddy
Thanks :-)

I reviewed everything and noticed one of the updates had a typo in the font-family; it is now all up and running. Much appreciated :D