Fallback font not working

Product: webviewer server

Product Version: Docker images (2.0.0 ,2.1.0)

Please give a brief summary of your issue:
Converting html to pdf through webviewer server and fallback font working

Please describe your issue and provide steps to reproduce it:
We are converting html to pdf through webviewer server by using API’s. We are first uploading the html file to server and then using “GetPDF” API to convert to PDF. It does the job however there are some fonts which we want to fallback to some “Default” font lets say “Arial”.

I have added some fonts in /usr/share/fonts/truetype
and added fonts.json containing fallback font in /usr/share/fonts

{
“target”:“arial1”,
“type”:“All”
}

but its not working.
Html

<p style="margin:0px 0px 0.3em;"><span style="font-family:abc;">Test comic sans - default </span></p>

This text is not getting converted to default font as provided in fonts.json file.

Hello harish0000,

Are you able to provide any code samples that we can take a look at to try and reproduce the issue?

Best Regards,

Carlo Mendoza
Web Developer
Apryse

Run the docker image

docker run --name webviewer-server -p 8090:8090 --net pdftron-network -e TRN_PDFNET_KEY=XXXX -e TRN_MAX_CACHED_MB=50000 pdftron/webviewer-server:2.1.0

Upload fonts in /usr/share/fonts/truetype
Upload the fonts.json in /usr/share/fonts and /usr/share/fonts/truetype

Now Upload the attached html file

curl --location ‘http://localhost:8090/blackbox/AuxUpload?type=upload&ext=html’ \

–header ‘Cookie: JSESSIONID=40CA106AAA011205C2D8E9EDA8D300ED’ \

–form ‘file=@“/C:/Users/XXX/Downloads/test_fonts.html”’

Response

{
“uri”: “cid://test_fonts.htmlkwCxQbqjKWBj1VQ8pxp-onhtml”,
“name”: “test_fonts.htmlkwCxQbqjKWBj1VQ8pxp-onhtml.html”,
“share_id”: “”,
“doc_id”: “1EhGKyzqoJWAPGfH3xPJO-gX6YQ-zVvDHut70DV0Sg0=”,
“pswd”: “”,
“extraHash”: “”,
“thumb”: “Image/Uploaded/1EhGKyzqoJWAPGfH3xPJO-gX6YQ-zVvDHut70DV0Sg0=.html_dir/pageimg0_320.jpg”,
“mOfficeOptions”: {
“applyPageBreaksToSheet”: false,
“displayChangeTracking”: false,
“excelDefaultCellBorderWidth”: -1,
“excelMaxAllowedCellCount”: -1
}
}

Copy the uri from response and hit below GetPDF url

curl --location ‘http://localhost:8090/blackbox/GetPDF?uri=cid://test_fonts.htmlkwCxQbqjKWBj1VQ8pxp-onhtml&fmt=data&ext=html
–header ‘Cookie: JSESSIONID=40CA106AAA011205C2D8E9EDA8D300ED’

Download the response and open in acrobat reader

Actual Result : Last text showing in Times new roman and not in Arial
Expected Result : Last text should be converted to Default font which is “Arial”

test_fonts.html (1.3 KB)
fonts.json (11.5 KB)

@cmendoza

Any updates ?

Hello harish0000,

Our team is currently investigating and will keep you up to date, in the meantime, thank you for your patience.

Best Regards,

Carlo Mendoza
Web Developer
Apryse

@cmendoza

Any updates on this ?

While we look at getting you this information, could you elaborate on what exactly the issue is with the current default?

How exactly does it affect your users?

Hi @Ryan

The current defaults to Times New Roman… which is not as per the rules defined in fonts.json. We don’t want to show the text in PDF in Times New Roman.

I am not sure how its picking the default as Times New Roman ?

Hello Harish,

WebViewer Server uses fonts based on what are installed on the docker container, and does not accept external font links or paths. Given that Arial is a windows font, it would not be installed with the docker. You would have to install it via a custom Dockerfile or flags yourself. You can find out how to do that via this FAQ.

@Ramzi_Chennafi

We have already installed the fonts ,the same is mentioned in this comment

from pdftron/webviewer-server:2.0.0

COPY fonts/ttf/*.ttf /usr/share/fonts/truetype/

RUN fc-cache

Also Arial font is already there in the list. So why its not picking the as per the fonts.json rules ?

@Ramzi_Chennafi

Any updates ?

Hello Harish,

WebViewer Server does not respect fonts.json and currently provides no way to use that file. fonts.json is meant only as a solution for client side rendering only (no WebViewer Server).

@Ramzi_Chennafi

ok, then how we can change the default font from times new roman to Arial in a webviewer server ?

Currently for any unknown font its default to times new roman.

Hello Harish,

The server is not defaulting to times new roman in this case, but DejaVuSans as far as I can tell. WebViewer Server does not even include times new roman in its font set.

There are ways to manually make fontconfig use specified fonts in the container. This guide specifies what to modify in Linux to make changes like this. I would apply these changes inside of the container in a similar way to how you added Arial.

You can use this in addition to fonts.json for WebViewer to achieve what you want.