-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Example of custom font usage and documentation update.
- Loading branch information
Showing
12 changed files
with
126 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Adding font | ||
|
||
To use a font, simply install it on the operating system and use it in your report. If that doesn't work, you have the option to add a .jar file with the fonts you want to use along with the library. I've shown below how to do it. | ||
|
||
|
||
## Step 1 - Understanding the structure | ||
|
||
In the project repository, there's a folder with the base structure to perform the procedure. After cloning the repository, inside the folder where you cloned it, navigate to the **example_custom_font** directory | ||
|
||
``` | ||
.. | ||
+-- example_custom_font | ||
| +-- src | ||
| +-- fonts | ||
| +-- myfontcustom | ||
| +-- CaskaydiaCoveNerdFont-Bold.ttf | ||
| +-- CaskaydiaCoveNerdFont-BoldItalic.ttf | ||
| +-- CaskaydiaCoveNerdFont-Italic.ttf | ||
| +-- CaskaydiaCoveNerdFont-Regular.ttf | ||
| +-- fontsfamily1703017000639.xml | ||
| +-- jasperreports_extension.properties | ||
``` | ||
|
||
## Step 2 - Changes | ||
1) Within the **fonts** folder, change the name of the folder `myfontcustom` to the name you want to use for the font in the report. | ||
|
||
2) Copy the `.ttf` font files to the folder from the previous step. Specifically, the font files for `Regular`, `Bold`, `BoldItalic`, and `Italic`. Modify the corresponding file names within the `fontsfamily1703017000639.xml` file in their respective tags. | ||
|
||
3) Using your preferred editor, open the file `fontsfamily1703017000639.xml`. Replace wherever you find the name `myfontcustom` with the same name you gave in step 1 of this section. | ||
|
||
|
||
## Step 3 - Generating `.jar` file. | ||
|
||
Compress the `fonts` folder along with the file `jasperreports_extension.properties`. Then, change the extension from `.zip` to `.jar` and name the `.jar` file with the same name as in `step 1` of the previous section, `Step 2 - Changes`. | ||
|
||
## Step 4 - Using the generated `.jar` with the library. | ||
|
||
Save the generated `.jar` in a folder of your choice, and in the `resource` parameter of the library, specify the folder where the `.jar` is located. Assign the font name in the report (`.jrxml`) and make good use of it. | ||
|
||
## Reference | ||
|
||
For further details, visit: [https://jasperreports.sourceforge.net/sample.reference/fonts/#fonts](https://jasperreports.sourceforge.net/sample.reference/fonts/#fonts) |
11 changes: 11 additions & 0 deletions
11
example_custom_font/src/fonts/fontsfamily1703017000639.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<fontFamilies> | ||
<fontFamily name="myfontcustom"> | ||
<normal><![CDATA[fonts/myfontcustom/CaskaydiaCoveNerdFont-Regular.ttf]]></normal> | ||
<bold><![CDATA[fonts/myfontcustom/CaskaydiaCoveNerdFont-Bold.ttf]]></bold> | ||
<italic><![CDATA[fonts/myfontcustom/CaskaydiaCoveNerdFont-Italic.ttf]]></italic> | ||
<boldItalic><![CDATA[fonts/myfontcustom/CaskaydiaCoveNerdFont-BoldItalic.ttf]]></boldItalic> | ||
<pdfEmbedded><![CDATA[true]]></pdfEmbedded> | ||
<exportFonts/> | ||
</fontFamily> | ||
</fontFamilies> |
Binary file added
BIN
+2.24 MB
example_custom_font/src/fonts/myfontcustom/CaskaydiaCoveNerdFont-Bold.ttf
Binary file not shown.
Binary file added
BIN
+2.1 MB
example_custom_font/src/fonts/myfontcustom/CaskaydiaCoveNerdFont-BoldItalic.ttf
Binary file not shown.
Binary file added
BIN
+2.1 MB
example_custom_font/src/fonts/myfontcustom/CaskaydiaCoveNerdFont-Italic.ttf
Binary file not shown.
Binary file added
BIN
+2.24 MB
example_custom_font/src/fonts/myfontcustom/CaskaydiaCoveNerdFont-Regular.ttf
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
net.sf.jasperreports.extension.registry.factory.fonts=net.sf.jasperreports.engine.fonts.SimpleFontExtensionsRegistryFactory | ||
net.sf.jasperreports.extension.simple.font.families.ireportfamily1703017000639=fonts/fontsfamily1703017000639.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" | ||
name="CustomFont" pageWidth="595" pageHeight="200" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" | ||
uuid="0eb3df49-8342-4b94-9567-9afe83ee4297"> | ||
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/> | ||
<queryString> | ||
<![CDATA[]]> | ||
</queryString> | ||
<background> | ||
<band splitType="Stretch"/> | ||
</background> | ||
<detail> | ||
<band height="125" splitType="Stretch"> | ||
<staticText> | ||
<reportElement x="127" y="30" width="100" height="30" uuid="a4cf64e9-d6c3-4ce9-9039-79800533550a"/> | ||
<textElement textAlignment="Left" verticalAlignment="Middle" markup="html"> | ||
<font fontName="myfont" size="11.5"/> | ||
</textElement> | ||
<text><![CDATA[caskaydia - Regular]]></text> | ||
</staticText> | ||
<staticText> | ||
<reportElement x="337" y="30" width="100" height="30" uuid="ea00d75c-4bc9-44cd-9385-45f9f5dacaf0"/> | ||
<textElement textAlignment="Left" verticalAlignment="Middle" markup="html"> | ||
<font fontName="myfont" size="11.5" isBold="true"/> | ||
</textElement> | ||
<text><![CDATA[caskaydia - Bold]]></text> | ||
</staticText> | ||
<staticText> | ||
<reportElement x="127" y="70" width="100" height="30" uuid="52ca47a2-6c40-4163-a3b2-26098001a2d4"/> | ||
<textElement textAlignment="Left" verticalAlignment="Middle" markup="html"> | ||
<font fontName="myfont" size="11.5" isItalic="true"/> | ||
</textElement> | ||
<text><![CDATA[caskaydia - Italic]]></text> | ||
</staticText> | ||
<staticText> | ||
<reportElement x="337" y="70" width="100" height="30" uuid="fb69e717-6483-4039-a012-4e3d6cd1404c"/> | ||
<textElement textAlignment="Left" verticalAlignment="Middle" markup="html"> | ||
<font fontName="myfont" size="11.5" isBold="true" isItalic="true"/> | ||
</textElement> | ||
<text><![CDATA[caskaydia - Bold Italic]]></text> | ||
</staticText> | ||
</band> | ||
</detail> | ||
</jasperReport> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# -*- coding: utf-8 -*- | ||
import os | ||
from pyreportjasper import PyReportJasper | ||
|
||
def processing(): | ||
REPORTS_DIR = os.path.join(os.path.abspath(os.path.dirname(__file__))) | ||
input_file = os.path.join(REPORTS_DIR, 'custom_font.jrxml') | ||
output_file = os.path.join(REPORTS_DIR, 'output', 'custom_font') | ||
pyreportjasper = PyReportJasper() | ||
pyreportjasper.config( | ||
input_file, | ||
output_file, | ||
output_formats=["pdf"] | ||
) | ||
pyreportjasper.process_report() | ||
|
||
processing() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters