Page 1 of 1

Use font without include or install them

Posted: Mon Mar 01, 2021 10:35 am
by Morgan-
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.

Re: Use font without include or install them

Posted: Tue Mar 02, 2021 11:10 am
by Vadim
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

Re: Use font without include or install them

Posted: Tue Mar 09, 2021 10:07 am
by Morgan-
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 !

Re: Use font without include or install them

Posted: Thu Mar 11, 2021 9:34 am
by Vadim
Hello.

In report you must use font name that described in font file (not in name addResourceFont(String name...))

Re: Use font without include or install them

Posted: Mon Mar 15, 2021 2:54 pm
by Morgan-
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.

Re: Use font without include or install them

Posted: Wed Mar 17, 2021 6:28 pm
by Vadim
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"

Re: Use font without include or install them

Posted: Thu Mar 18, 2021 10:38 am
by Morgan-
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 ? :)

Re: Use font without include or install them

Posted: Mon Mar 22, 2021 6:50 am
by Vadim
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.

Re: Use font without include or install them

Posted: Tue Mar 30, 2021 9:44 am
by Morgan-
Thanks you Vadim, you answer my question.

Subject's closed !

Re: Use font without include or install them

Posted: Wed Mar 31, 2021 1:08 pm
by Lech Kulikowski
Hello,

You are welcome.