Use font without include or install them

Stimulsoft Reports.Java discussion
Post Reply
Morgan-
Posts: 5
Joined: Mon Mar 01, 2021 10:17 am

Use font without include or install them

Post by Morgan- » Mon Mar 01, 2021 10:35 am

Hello,
I have some reports to print both on Windows and Linux servers. For performances issues, i can’t include font inside the reports.
I found an option: public static void addResourceFont(java.lang.String p1, byte[] p2, java.lang.String p3). This option seems to allow using font without include them in the report and without installed them on the server.
But I didn’t found informations to use it. Someone know how to do that ?
Thanks you ! :)
Version : 2020.4.1.
Vadim
Posts: 273
Joined: Tue Apr 23, 2013 11:23 am

Re: Use font without include or install them

Post by Vadim » Tue Mar 02, 2021 11:10 am

Hello.

com.stimulsoft.base.StiFontCollection.addResourceFont(String name, byte[] content, String extension)

This method register font in LocalGraphicsEnvironment, you can use it by putting font file content into parameter byte[] content
Morgan-
Posts: 5
Joined: Mon Mar 01, 2021 10:17 am

Re: Use font without include or install them

Post by Morgan- » Tue Mar 09, 2021 10:07 am

Hi again,
Thanks for the answer !
I've try to use this method, but it don't works in my case. This is what i've done :

In java :

StiFontCollection.addResourceFont("testfont", FileUtils.readFileToByteArray(new File(C:\times.ttf)), "ttf");
{...}
StiExportManager.exportPdf(_reportStimulsoft, setting, byteArrayOutputStream);

In mrt file i've modified all font name in <Font></Font> by testfont.
like :
<Font>testfont,8</Font>

I have no error but the font in the pdf looks like a "default" font, not the one i defined.

What i've done wrong ?
Thanks you !
Vadim
Posts: 273
Joined: Tue Apr 23, 2013 11:23 am

Re: Use font without include or install them

Post by Vadim » Thu Mar 11, 2021 9:34 am

Hello.

In report you must use font name that described in font file (not in name addResourceFont(String name...))
Morgan-
Posts: 5
Joined: Mon Mar 01, 2021 10:17 am

Re: Use font without include or install them

Post by Morgan- » Mon Mar 15, 2021 2:54 pm

I’ve try with this font: https://www.dafont.com/fr/wolf-in-the-city.font
In the font file, the name is “Wolf in the City”.
In mrt file, i've modified all font name in <Font></Font> by Wolf in the City
Like:
<Font>Wolf in the City, 8</Font>
The font in the generated pdf file is not the “Wolf in the City”.

Any idea? Any option to enable or disable?
Thanks you.
Vadim
Posts: 273
Joined: Tue Apr 23, 2013 11:23 am

Re: Use font without include or install them

Post by Vadim » Wed Mar 17, 2021 6:28 pm

Hello.

We use next code
StiFontCollection.addResourceFont("testfont", FileUtils.readFileToByteArray(new File("C:/234/Wolf in the City.ttf")), "ttf");
StiReport report2 = StiSerializeManager.deserializeReport(new FileInputStream("c:/234/font.mrt"));
report2.render();
StiExportManager.exportPdf(report2, new FileOutputStream("c:/234/out.pdf"));

Font in mrt is : <Font>Wolf in the City,8</Font>
And it works as expected, PDF exported with font "Wolf in the City"
Attachments
out.pdf
(18.79 KiB) Downloaded 39 times
font.mrt
(3.15 KiB) Downloaded 58 times
Morgan-
Posts: 5
Joined: Mon Mar 01, 2021 10:17 am

Re: Use font without include or install them

Post by Morgan- » Thu Mar 18, 2021 10:38 am

Thanks you, i've find the issue.
I use the StiPdfExportSettings in my code and this one is EmbeddedFonts = true by default but i set him to false. That's why it's don't works.

If i set him to true that's works, but it's will include the font into the pdf and growth the size of the pdf ?

If i understand well, it's works like that :
EmbeddedFonts = false : i must install the font on the server
EmbeddedFonts = true : it will growth the size of the pdf by included the font

There is another way ? i must generate a lot of pdf so i can't include font in each of them, and i have to manage a lot of server, so i can't install manually each font on each servers.
I already use Compressed = true but pdf generate with font are still too big.

Any idea ? :)
Vadim
Posts: 273
Joined: Tue Apr 23, 2013 11:23 am

Re: Use font without include or install them

Post by Vadim » Mon Mar 22, 2021 6:50 am

Hello.

If i set him to true that's works, but it's will include the font into the pdf and growth the size of the pdf ? - Yes.

To display font there is two ways: embedded this font into PDF or install font to system.
Morgan-
Posts: 5
Joined: Mon Mar 01, 2021 10:17 am

Re: Use font without include or install them

Post by Morgan- » Tue Mar 30, 2021 9:44 am

Thanks you Vadim, you answer my question.

Subject's closed !
Lech Kulikowski
Posts: 3569
Joined: Tue Mar 20, 2018 5:34 am

Re: Use font without include or install them

Post by Lech Kulikowski » Wed Mar 31, 2021 1:08 pm

Hello,

You are welcome.
Post Reply