Skip to content

Commit 9d978d7

Browse files
committed
feat(PDF): Adding support for custom fonts.
1 parent c6082c6 commit 9d978d7

File tree

14 files changed

+290
-12
lines changed

14 files changed

+290
-12
lines changed

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,24 @@
22

33
All notable changes for each version of this project will be documented in this file.
44

5+
# 21.1.0
6+
7+
## New Features
8+
9+
### PDF Exporter
10+
- **Custom Font Support for CJK and Arabic Scripts**: Added pre-configured font constants for easy PDF export with non-Latin character support:
11+
- `NOTO_SANS_FONT` - Supports Latin, Cyrillic, and Greek characters
12+
- `NOTO_SANS_CJK_FONT` - Supports Chinese, Japanese, and Korean characters (CJK)
13+
- `NOTO_SANS_ARABIC_FONT` - Supports Arabic script and related languages
14+
15+
These fonts can be imported from `igniteui-angular/grids/core` and used with `IgxPdfExporterOptions.customFont`:
16+
17+
```typescript
18+
import { NOTO_SANS_CJK_FONT } from 'igniteui-angular/grids/core';
19+
20+
const options = new IgxPdfExporterOptions('Export');
21+
options.customFont = NOTO_SANS_CJK_FONT;
22+
523
## 21.0.0
624

725
### New Features

projects/igniteui-angular/grids/core/src/public_api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ export * from './services/excel/excel-exporter';
125125
export * from './services/excel/excel-exporter-options';
126126
export * from './services/pdf/pdf-exporter';
127127
export * from './services/pdf/pdf-exporter-options';
128+
export * from './services/pdf/fonts/noto-fonts';
128129

129130
/*
130131
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { NOTO_SANS_BASE64, NOTO_SANS_BOLD_BASE64 } from './noto-sans';
2+
import { NOTO_SANS_ARABIC_BASE64, NOTO_SANS_ARABIC_BOLD_BASE64 } from './noto-sans-arabic';
3+
import { NOTO_SANS_CJK_BASE64, NOTO_SANS_CJK_BOLD_BASE64 } from './noto-sans-cjk';
4+
5+
/**
6+
* Pre-configured Noto Sans font for PDF exports
7+
* Supports Latin, Cyrillic, Greek, and extended Latin characters
8+
*
9+
* @example
10+
* ```typescript
11+
* import { NOTO_SANS_FONT } from 'igniteui-angular/pdf-fonts';
12+
*
13+
* const options = new IgxPdfExporterOptions('Export');
14+
* options.customFont = NOTO_SANS_FONT;
15+
* ```
16+
*
17+
* @publicApi
18+
*/
19+
export const NOTO_SANS_FONT = {
20+
data: NOTO_SANS_BASE64,
21+
name: 'NotoSans',
22+
bold: {
23+
data: NOTO_SANS_BOLD_BASE64,
24+
name: 'NotoSans-Bold'
25+
}
26+
};
27+
28+
/**
29+
* Pre-configured Noto Sans CJK font for PDF exports
30+
*
31+
* @publicApi
32+
*/
33+
export const NOTO_SANS_CJK_FONT = {
34+
data: NOTO_SANS_CJK_BASE64,
35+
name: 'NotoSansCJK',
36+
bold: {
37+
data: NOTO_SANS_CJK_BOLD_BASE64,
38+
name: 'NotoSansCJK-Bold'
39+
}
40+
};
41+
42+
/**
43+
* Pre-configured Noto Sans Arabic font for PDF exports
44+
*
45+
* @publicApi
46+
*/
47+
export const NOTO_SANS_ARABIC_FONT = {
48+
data: NOTO_SANS_ARABIC_BASE64,
49+
name: 'NotoSansArabic',
50+
bold: {
51+
data: NOTO_SANS_ARABIC_BOLD_BASE64,
52+
name: 'NotoSansCJK-Bold'
53+
}
54+
};

projects/igniteui-angular/grids/core/src/services/pdf/fonts/noto-sans-arabic.json

Lines changed: 5 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import fontData from './noto-sans-arabic.json'
2+
/**
3+
* Base64-encoded Noto Sans Arabic font data (Regular weight).
4+
*
5+
* This font provides comprehensive support for Arabic script and related languages,
6+
* including Arabic, Persian/Farsi, Urdu, Pashto, and Kurdish (Sorani).
7+
*
8+
* @remarks
9+
* This constant is used with `IgxPdfExporterOptions.customFont` to enable
10+
* Arabic and related right-to-left (RTL) scripts in exported PDF documents.
11+
*
12+
* The font uses the SIL Open Font License 1.1.
13+
* Source: https://fonts.google.com/noto/specimen/Noto+Sans+Arabic
14+
*
15+
* @example
16+
* ```typescript
17+
* const options = new IgxPdfExporterOptions('MyExport');
18+
* options.customFont = {
19+
* name: 'Noto Sans Arabic',
20+
* data: NOTO_SANS_ARABIC_BASE64,
21+
* bold: { data: NOTO_SANS_ARABIC_BOLD_BASE64 }
22+
* };
23+
* ```
24+
*/
25+
export const NOTO_SANS_ARABIC_BASE64 = fontData.normal;
26+
27+
/**
28+
* Base64-encoded Noto Sans Arabic Bold font data.
29+
*
30+
* This is the bold variant of the Noto Sans Arabic font, used for headers and emphasized text
31+
* in PDF exports with Arabic script support.
32+
*
33+
* @remarks
34+
* Pair this with `NOTO_SANS_ARABIC_BASE64` in the `IgxPdfExporterOptions.customFont.bold` property
35+
* to ensure consistent rendering of both regular and bold Arabic text.
36+
*
37+
* @see NOTO_SANS_ARABIC_BASE64
38+
*/
39+
export const NOTO_SANS_ARABIC_BOLD_BASE64 = fontData.bold;

projects/igniteui-angular/grids/core/src/services/pdf/fonts/noto-sans-cjk.json

Lines changed: 5 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import fontData from './noto-sans-cjk.json';
2+
3+
/**
4+
* Base64-encoded Noto Sans CJK font data (Regular weight).
5+
*
6+
* This font provides comprehensive support for CJK (Chinese, Japanese, Korean) characters,
7+
* including Hiragana, Katakana, Kanji, Hangul, and CJK Unified Ideographs, as well as
8+
* Latin, Cyrillic, and Greek scripts.
9+
*
10+
* @remarks
11+
* This is a large font file (~15-25MB when Base64-encoded). Consider loading it
12+
* asynchronously or on-demand to avoid impacting initial application load time.
13+
*
14+
* The font uses the SIL Open Font License 1.1.
15+
* Source: https://fonts.google.com/noto/specimen/Noto+Sans+JP
16+
*
17+
* This constant is used with `IgxPdfExporterOptions.customFont` to enable
18+
* CJK characters in exported PDF documents.
19+
*
20+
* @example
21+
* ```typescript
22+
* const options = new IgxPdfExporterOptions('MyExport');
23+
* options.customFont = {
24+
* name: 'Noto Sans CJK',
25+
* data: NOTO_SANS_CJK_BASE64,
26+
* bold: { data: NOTO_SANS_CJK_BOLD_BASE64 }
27+
* };
28+
* ```
29+
*/
30+
export const NOTO_SANS_CJK_BASE64 = (fontData as any).normal;
31+
32+
/**
33+
* Base64-encoded Noto Sans CJK Bold font data.
34+
*
35+
* This is the bold variant of the Noto Sans CJK font, used for headers and emphasized text
36+
* in PDF exports with CJK character support.
37+
*
38+
* @remarks
39+
* Pair this with `NOTO_SANS_CJK_BASE64` in the `IgxPdfExporterOptions.customFont.bold` property
40+
* to ensure consistent rendering of both regular and bold CJK text.
41+
*
42+
* Like the regular weight, this is a large font file that may impact bundle size.
43+
*
44+
* @see NOTO_SANS_CJK_BASE64
45+
*/
46+
export const NOTO_SANS_CJK_BOLD_BASE64 = (fontData as any).bold;

projects/igniteui-angular/grids/core/src/services/pdf/fonts/noto-sans.json

Lines changed: 5 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import fontData from './noto-sans.json';
2+
3+
/**
4+
* Base64-encoded Noto Sans font data (Regular weight).
5+
*
6+
* This font provides extended Latin, Cyrillic, and Greek character support.
7+
* For CJK (Chinese, Japanese, Korean) character support, use a CJK-specific font
8+
* such as Noto Sans CJK or Arial Unicode MS.
9+
*
10+
* @remarks
11+
* This constant is used with `IgxPdfExporterOptions.customFont` to enable
12+
* non-Latin characters in exported PDF documents.
13+
*
14+
* @example
15+
* ```typescript
16+
* const options = new IgxPdfExporterOptions('MyExport');
17+
* options.customFont = {
18+
* name: 'Noto Sans',
19+
* data: NOTO_SANS_BASE64,
20+
* bold: { data: NOTO_SANS_BOLD_BASE64 }
21+
* };
22+
* ```
23+
*/
24+
export const NOTO_SANS_BASE64 = fontData.normal;
25+
26+
/**
27+
* Base64-encoded Noto Sans Bold font data.
28+
*
29+
* This is the bold variant of the Noto Sans font, used for headers and emphasized text
30+
* in PDF exports.
31+
*
32+
* @remarks
33+
* Pair this with `NOTO_SANS_BASE64` in the `IgxPdfExporterOptions.customFont.bold` property
34+
* to ensure consistent rendering of both regular and bold text.
35+
*
36+
* @see NOTO_SANS_BASE64
37+
*/
38+
export const NOTO_SANS_BOLD_BASE64 = fontData.bold;

projects/igniteui-angular/grids/core/src/services/pdf/pdf-exporter-options.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,41 @@ export class IgxPdfExporterOptions extends IgxExporterOptionsBase {
4848
*/
4949
public fontSize = 10;
5050

51+
/**
52+
* Custom font data for Unicode support (optional).
53+
* If not provided, uses Helvetica (Latin characters only).
54+
*
55+
* @example
56+
* ```typescript
57+
* import { NOTO_SANS_FONT } from './fonts';
58+
*
59+
* const options = new IgxPdfExporterOptions('Export');
60+
* options.customFont = {
61+
* data: NOTO_SANS_FONT,
62+
* name: 'NotoSans'
63+
* };
64+
* ```
65+
*/
66+
public customFont?: PdfUnicodeFont;
67+
5168
constructor(fileName: string) {
5269
super(fileName, '.pdf');
5370
}
5471
}
72+
73+
/**
74+
* Font configuration for PDF export
75+
*/
76+
export interface PdfUnicodeFont {
77+
/** Base64-encoded font data */
78+
data: string;
79+
/** Font family name */
80+
name: string;
81+
/** Bold variant of the font (optional) */
82+
bold?: {
83+
/** Base64-encoded bold font data */
84+
data: string;
85+
/** Font family name (usually same as normal) */
86+
name: string;
87+
};
88+
}

0 commit comments

Comments
 (0)