plugins.VelocityReport.installFonts(); returning false

Questions and answers on designing your Servoy solutions, database modelling and other 'how do I do this' that don't fit in any of the other categories

plugins.VelocityReport.installFonts(); returning false

Postby roddy » Tue Aug 03, 2021 3:48 am

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,
roddy
 
Posts: 100
Joined: Mon Oct 26, 2020 12:32 am

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

Postby ptalbot » Tue Aug 03, 2021 8:50 pm

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.
Patrick Talbot
Freelance - Open Source - Servoy Valued Professional
https://www.servoyforge.net
Velocity rules! If you don't use it, you don't know what you're missing!
User avatar
ptalbot
 
Posts: 1654
Joined: Wed Mar 11, 2009 5:13 am
Location: Montreal, QC

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

Postby roddy » Wed Aug 04, 2021 2:25 am

Thanks, that is great to know. Really appreciate the feedback.
roddy
 
Posts: 100
Joined: Mon Oct 26, 2020 12:32 am

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

Postby ptalbot » Wed Aug 04, 2021 4:16 am

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.
Patrick Talbot
Freelance - Open Source - Servoy Valued Professional
https://www.servoyforge.net
Velocity rules! If you don't use it, you don't know what you're missing!
User avatar
ptalbot
 
Posts: 1654
Joined: Wed Mar 11, 2009 5:13 am
Location: Montreal, QC

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

Postby roddy » Tue Oct 19, 2021 4:39 am

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>
roddy
 
Posts: 100
Joined: Mon Oct 26, 2020 12:32 am

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

Postby ptalbot » Tue Oct 19, 2021 5:40 am

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).
Patrick Talbot
Freelance - Open Source - Servoy Valued Professional
https://www.servoyforge.net
Velocity rules! If you don't use it, you don't know what you're missing!
User avatar
ptalbot
 
Posts: 1654
Joined: Wed Mar 11, 2009 5:13 am
Location: Montreal, QC

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

Postby roddy » Tue Oct 19, 2021 7:26 am

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?
roddy
 
Posts: 100
Joined: Mon Oct 26, 2020 12:32 am

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

Postby roddy » Tue Oct 19, 2021 7:36 am

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?
roddy
 
Posts: 100
Joined: Mon Oct 26, 2020 12:32 am

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

Postby ptalbot » Tue Oct 19, 2021 8:01 pm

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.
Attachments
pdfProperties.png
PDF properties
pdfProperties.png (20.35 KiB) Viewed 2504 times
Test.pdf
PDF with Montserrat regular embedded
(7.6 KiB) Downloaded 134 times
Patrick Talbot
Freelance - Open Source - Servoy Valued Professional
https://www.servoyforge.net
Velocity rules! If you don't use it, you don't know what you're missing!
User avatar
ptalbot
 
Posts: 1654
Joined: Wed Mar 11, 2009 5:13 am
Location: Montreal, QC

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

Postby roddy » Tue Oct 19, 2021 11:37 pm

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
roddy
 
Posts: 100
Joined: Mon Oct 26, 2020 12:32 am


Return to Programming with Servoy

Who is online

Users browsing this forum: No registered users and 9 guests