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- »

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: 362
Joined: Tue Apr 23, 2013 11:23 am

Re: Use font without include or install them

Post 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
Morgan-
Posts: 5
Joined: Mon Mar 01, 2021 10:17 am

Re: Use font without include or install them

Post 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 !
Vadim
Posts: 362
Joined: Tue Apr 23, 2013 11:23 am

Re: Use font without include or install them

Post by Vadim »

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- »

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: 362
Joined: Tue Apr 23, 2013 11:23 am

Re: Use font without include or install them

Post 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"
Attachments
out.pdf
(18.79 KiB) Downloaded 267 times
font.mrt
(3.15 KiB) Downloaded 272 times
Morgan-
Posts: 5
Joined: Mon Mar 01, 2021 10:17 am

Re: Use font without include or install them

Post 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 ? :)
Vadim
Posts: 362
Joined: Tue Apr 23, 2013 11:23 am

Re: Use font without include or install them

Post 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.
Morgan-
Posts: 5
Joined: Mon Mar 01, 2021 10:17 am

Re: Use font without include or install them

Post by Morgan- »

Thanks you Vadim, you answer my question.

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

Re: Use font without include or install them

Post by Lech Kulikowski »

Hello,

You are welcome.
Post Reply