Question

Custom font style is not applied in the generated pdf document

A custom font file is uploaded to our Pega Application as a binary file. File directory of the binary file is webwb and the extension is ttf. In the Rich Text Editor(RTE) I have added this font style and applied this style to the content of the RTE. Now when I am generating the pdf out of the content of RTE, the custom font style is not applied to the generated pdf. I am using HTMLToPDF activity for generating the pdf and passing the parameters like pdfstream, pyPDFFontsDirectory and pyPDFEmbedFont as true. PDF is generated properly but not with the desired custom font style. I have tried passing parameter of pyPDFFontsDirectory as webwb, as \webwb and even my local directory path as well like "C:\\Windows\\Fonts". None of them worked. I have gone through many community posts but could not find the desired solution. I feel there is an issue with passing the directory path. Please help!!

***Edited by Moderator Marissa to update platform capability tags****

Correct Answer
November 6, 2019 - 6:25am

I just fixed the issue. For all who are struggling with the same requirement or issue please follow the steps below:

1. First check the Font Embeddability of the custom font that you want to use is set to Editable or Installable. This you can ensure from the properties of the custom font file by right clicking on it and go to details tab.

2. Place all the font files along with the custom font files which you require to a directory in the server. Make sure that the directory folder is accessible. You can check if the directory path is correct and you are able to access all the files in the path folder by writing a Java code (I wrote a function for this to check). webwb as part of App directory won't work because of the limitation as discussed in this post.

3. Restart the server after placing the font files in the server.

4. Make sure you have the font family of the custom font applied to each element be it div or span. Example: <span style="font-family:century gothic;">Dear Sir</span>

5. Pass the Relative Server path or the Absolute path where the font files are placed in the server as a parameter pyPDFFontsDirectory to HTMLToPDF activity. Make sure that you are using the correct server path which you had verified earlier. In my case I used like /data/..../..../..../Fonts. Replace .... with proper folder names of yours.

6. Pass pyPDFEmbedFont parameter as true to HTMLToPDF activity. This will embed the fonts in the PDF document and you will be able to verify that from the Properties Fonts tab of the adobe acrobat.

Thanks everyone for the help!!

Comments

Keep up to date on this post and subscribe to comments

October 26, 2019 - 11:34pm

For using custom font styles in PDF generation, few important things:

- You need to pass pyPDFFontsDirectory parameter to a folder location on Pega Server. I'd suggest use a folder other than c:/windows/fonts, as Pega automatically creates a file named pd4fonts.properties in the fonts directory and in most cases Pega may not have access to create this file under c:/windows/fonts. Also note, to use forward slash (/) for directory separator not backward slash (\).

- The html stream passed to HTMLToPDF activity should have respective css for each part of the HTML using the custom font. For example, the css may have a class defined with font-family and then that class is used for div or table/tr/td tags in html.

- pyPDFEmbedFont parameter must be passed as true for HTMLToPDF activity to embed the custom fonts inside the rendered PDF. Once a PDF is generated, you can check its properties (fonts tab) to check if the custom font was embedded. 

Hope this helps.

 

 

 

October 27, 2019 - 9:28am
Response to PraveenPuri

Hi Praveen,

If I specify my local directory path where my custom font file is located now I am able to generate the pdf with custom font style. But, in this case all the contents are converted to the custom font style even if some of the sentences are in Arial font or Times New Roman font in Rich Text Editor. I feel this is logical because the directory contains only the custom font files. Is there a way to fix this issue without placing all other the font files along with the custom font file in the directory?

Furthermore we are uploading the font file as a binary file in pega under the App Directory as webwb. In that case how to pass the directory path as a parameter to pyPDFFontsDirectory? As far as I know binary files are kept in the database whenever created and placed in the web server under a hashed folder generated from the requestor's ruleset list whenever first referenced and later on retrieved from the server path on subsequent references. Passing /webwb as a parameter to pyPDFFontsDirectory is not working. Please suggest what will be the value of pyPDFFontsDirectory param in case of webwb.

Regards,

Arpan

October 27, 2019 - 5:22pm
Response to ArpanP12

I'd say that easiest solution would be to copy those 9 or 10 fonts (which are used in RTE) from c:\windows\fonts to a local directory and use path to that directory in pyPDFFontsDirectory. However, in my experience if custom font is not found, Arial or sans-serif is used as default font.

Although the fonts would be downloaded to StaticContent folder on your web-server's Pega Temp Dir - I personally would not recommend an approach to point to that folder, as I doubt that all fonts would be downloaded there either and I am not sure how to dynamically calculate the path to StaticContent respective to logged-in user who will attempt to generate the PDF.

Unfortunately, you cannot point pyPDFFontsDirectory to /webwb because this parameter is expecting a local folder path on the web server.

Pega
October 28, 2019 - 1:10am

Hello,

Try creating the font folder at the server directory and give the folder name as Fonts.

November 4, 2019 - 7:26pm

I have already placed the font files in the pega server and have passed the pyPDFFontsDirectory parameter as the relative path of the directory where the font files are located. But it is not working. Maybe at runtime it is not able to locate the folder. I have contacted the server admin to check if the relative path that I am passing is sufficient or I need to pass the absolute path as I don't have the server directory access. Will update this post once I get the answer from them.

November 5, 2019 - 10:04am

From Pega I am able to access the server folder and also able to retrieve the font files. I have written a function for that just to check whether I am passing the correct directory path or whether that folder is accessible. So, the issue now is somehow the intending style is not applied in the generated pdf even if all the parameters are passed correctly in HTMLToPDF activity. My markup is having several span elements with different styles applied.

Example: <span style="font-family:century gothic;">Dear Sir</span>

The above is a part of the markup which contains span element and this is passed as a markup in HTMLToPDF activity. Anyone who have faced this issue, please throw a light on this.

Note: I have placed all the font files required (custom font files and also Arial, Times New Roman etc.) in the Fonts folder in the server directory.

November 6, 2019 - 6:25am

I just fixed the issue. For all who are struggling with the same requirement or issue please follow the steps below:

1. First check the Font Embeddability of the custom font that you want to use is set to Editable or Installable. This you can ensure from the properties of the custom font file by right clicking on it and go to details tab.

2. Place all the font files along with the custom font files which you require to a directory in the server. Make sure that the directory folder is accessible. You can check if the directory path is correct and you are able to access all the files in the path folder by writing a Java code (I wrote a function for this to check). webwb as part of App directory won't work because of the limitation as discussed in this post.

3. Restart the server after placing the font files in the server.

4. Make sure you have the font family of the custom font applied to each element be it div or span. Example: <span style="font-family:century gothic;">Dear Sir</span>

5. Pass the Relative Server path or the Absolute path where the font files are placed in the server as a parameter pyPDFFontsDirectory to HTMLToPDF activity. Make sure that you are using the correct server path which you had verified earlier. In my case I used like /data/..../..../..../Fonts. Replace .... with proper folder names of yours.

6. Pass pyPDFEmbedFont parameter as true to HTMLToPDF activity. This will embed the fonts in the PDF document and you will be able to verify that from the Properties Fonts tab of the adobe acrobat.

Thanks everyone for the help!!