Use custom fonts when creating pdf using iReport - java

iReport Version : 3.7.1
I approached this problem in two ways.
My first method
I am creating a pdf page in iReport and I have one of the fields (from database) set to a font Gujarati-Salarl (A font for a regional language of India).
This font is available in the font list of iReport.
When I hit preview I get the desired output , with the field in the required font style.
Everything till here is fine.
But the pdf file generated still contains the same original font in English characters.
The result is same whether i call the report from the application or from a JAVA file.
After a bit of study I found this , a second method
JRProperties.setProperty("net.sf.jasperreports.default.pdf.font.name", "C:\\Gujrati-Saral-1.ttf");
This sets the font of the pdf to the ttf font provided but now the entire pdf comes in the Guarati-saral font which is not what I am looking for..
Is there a way to specifically apply this font only to that one particular field?
or
when going by the second method is there a way to not applying the font Guarati-saral to all other fields except the required one ?

You should use the Font Extensions mechanism.
After creating the font and exporting it as a jar file you should add generated jar file to the application classpath.
a) Creating new font in iReport (via Options -> Fonts -> "Install Font" Button)
b) Exporting the new font (or the existing one) as jar file in iReport (via Options -> Fonts -> "Export as extension" Button)
a) Creating new font in JasperReports Studio (via Window -> Preferences -> JasperStudio -> Fonts -> "Add" Button)
b) Configure your fonts
c) Create JAR with your fonts in it
You can find more information about using Font Extensions here.

if you have problems displaying UTF-8 characters in the pdf,
from version 4.8.0 of the IReport, no need to do nothing!
Just change the font of the cells in the table from sanserif to Dejavu sans.
thats it.

For those, who need Russian language in Jasper Reports (at least in opennms of old versions), following combination does the trick without using the Font Extension:
Font Name: SanSerif
PDF Font: Courier
PDF Encoding: CP1251
PDF Embedded: Yes (not sure, may be it works even without)
Alexey Bakhmutov

Select the field and go to filed properties and change the
select DejaVu Sans as Font Name
select Pdf Encoding to CP1256 (Arabic)
select pdf font name to Courier
with these changes in I got arabic data showing in PDF.

Related

Creating and mapping a CSS to a Crystal Report with the Java Plugin for Eclipse

Hi i want to use a css file to load 3rd Party fonts without installing them. But when i set the Css Name nothing happens.
I'm using "cr4e-all-in-one-win_2.0.23" with "com.businessobjects.crystalreports.crsdk.libs_12.2.224.r3370"
I followed this procedure:
To create a CSS and map classes to a Crystal Report
Locate the Crystal ViewerReport default.css file.
Copy the file to the same directory and rename it.
If necessary, use a text editor to add or modify CSS classes.
Open the .RPT file of the Crystal Report to which you want to map the CSS classes.
Add or select a text object and open the Format Editor. In the CSS Class Name field, enter the CSS Class Name, type the class to which you want to map the text object.
Save the report.
Open the Reporting Services application and publish the report.
#font-face {
font-family: firaGO;
src: url(FiraGO-Light.ttf);
}
* {
font-family: firaGO;
color: blue;
}

JavaFx font not showing on Windows/OracleJDK

I have a JavaFx application that uses Material Icons ttf font for icons. On Windows, with Oracle JDK, the font seems to be loaded correctly, as System.out.println(font); returns:
Font[name=Material Icons, family=Material Icons, style=Regular, size=10.0]
It is in the list of available fonts:
for (String fontFamily : Font.getFamilies()) {
System.out.println(fontFamily);
}
returns:
...
Material Icons
...
However, no matter whether i set the font in the code (e.g. label.setFont(font)), or I specify the family as a css property (e.g. label.setStyle("-fx-font-family: \"Material Icons\";");), the font is not shown correctly in the application.
On the other hand, everything works perfectly on OpenJDK on Arch Linux. If you have any idea on how to solve or further debug the problem, thank you very much!

Jaspersoft studio: UTF-8 encoding issue

I am using Jaspersoft Studio final version (v6.1.1). I have designed my report and it contains Turkish characters. When exporting the report from Studio as PDF Turkish characters are not shown although I've set the Studio workspace encoding to UTF-8. Also I have embed the jrxml report file in my JSF app and export the report, the result is the same.
Do I have to configure something more?
I was able to solve the problem. In the Jaspersoft Studio IDE, change encoding to UTF-8 in Window/Prefrences/General/Workspace. Afterwards click any field, parameter, or text in the IDE and from the Properties/Advanced menu select PDF/PDF Encoding. I hope it will help.
I think i have found an easier and more general solution. Instead of changing encoding of every field, you can do it using java coding from your web application`s controller. Below is my solution, i hope it helps a bit. Just put the font to your webapp folder. And change the encoding programatically. BTW greetings from turkey :)
JRDesignStyle jrDesignStyle = new JRDesignStyle();
/*Set the Encoding to UTF-8 for pdf and embed font to arial*/
jrDesignStyle.setDefault(true);
String fontPath = req.getSession().getServletContext().getRealPath("/jasper/arial.ttf");
jrDesignStyle.setPdfFontName(fontPath);
jrDesignStyle.setPdfEncoding("Identity-H");
jrDesignStyle.setPdfEmbedded(true);
jasperPrint.addStyle(jrDesignStyle);
JRPdfExporter exporter = new JRPdfExporter();

Could not load the following font

I have a problem that have been already asked, but there are some specific differences in my case.
I'm supporting a web application (EJB 2, PostgreSQL 9.2.4, running on a JBoss 4.2.3) that have an issue.
Sometimes, when we try to generate a specific report, we get this error:
javax.servlet.ServletException: net.sf.jasperreports.engine.JRRuntimeException: Could not load the following font :
pdfFontName : DejaVu Sans
pdfEncoding : Cp1252
isPdfEmbedded : false
org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:523)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
stirq.scan.util.NoCacheFilter.doFilter(NoCacheFilter.java:38)
jcifs.http.NtlmHttpFilter.doFilter(NtlmHttpFilter.java:118)
stirq.scan.util.TimeoutFilter.doFilter(TimeoutFilter.java:57)
stirq.scan.util.SecurityFilter.doFilter(SecurityFilter.java:82)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
I searched in many sites.
http://community.jaspersoft.com/questions/525505/could-not-load-following-font
Could not load the following font issue in iReport
JasperReports - font extensions does not work - can't find font while exporting to PDF
(And others)
As suggested in many answers, I am using font extension jar but still got the issue.
There are two fields of a table in the application's database that can contains html code.
I found that the bug occurs when there is a "font" tag in one of those two fields or the two.
Even if the specified font in this "font" tag is Arial the message I got is still concerning the font DejaVu Sans.
Every textfield of all my jrxml files are in font DejaVu Sans.
When I tested the preview mode of my report in IReport 4.1.1 every thing was fine.
I deleted every "font" tags of the two database fields containing HTML code for an occurrence that got the issue and it worked.
But the application is in production.
As you can see I can't delete every "font" tags in the database.
Any help would be appreciated.
Thanks.
In iReport if you set up a repository for your JasperServer you will be able to get the effective production version of a report xml into iReport. Then you can edit your file and replace by the edited version production one.
try setting up these system properties:
import net.sf.jasperreports.engine.util.JRProperties;
JRProperties.setProperty("net.sf.jasperreports.default.pdf.font.name", "Helvetica")
JRProperties.setProperty("net.sf.jasperreports.default.pdf.encoding", "UTF-8")
JRProperties.setProperty("net.sf.jasperreports.default.pdf.embedded", "false")
see here for more: http://www.77dev.com/2014/07/could-not-load-following-font-solved.html
Copy the fonts files (*.ttf) into the folder:
/path/to/app/WEB-INF/classes/
You app will get the fonts from here :)

Specifying a base or default font with PDFBox

Is there a system property or other parameter that can be passed to PDFBox when attempting to convert from a PDF document into an Image? I am utilizing the provided PDF2Image class like so:
String[] args = new String[]{"-imageType", "jpg", "myfile.pdf"};
org.apache.pdfbox.PDFToImage.main(args);
It works great on Windows and fails with this warning on Ubuntu:
[org.apache.pdfbox.util.PDFStreamEngine] java.lang.NullPointerException java.lang.NullPointerException at org.apache.pdfbox.pdmodel.font.PDType1Font.getawtFont(PDType1Font.java:261)
I assume from my research that this is a problem with a "missing" font, but I've found very little help so far using google and the projects website.
I've tried both versions 1.7.1 and 1.8.2 of PDFBox.
Similar question here: setting ttf for PDF to Image on PDFbox

Categories

Resources