Skip to content

Commit 7dbd403

Browse files
authored
fix(PDF): Add live-editing config for custom font sample (#3901)
1 parent a449a86 commit 7dbd403

File tree

4 files changed

+17
-30
lines changed

4 files changed

+17
-30
lines changed

live-editing/configs/ExportPdfConfigGenerator.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ export class ExportPdfConfigGenerator implements IConfigGenerator {
1212
appConfig: BaseAppConfig
1313
}));
1414

15+
configs.push(new Config({
16+
component: 'ExportPdfCustomFontComponent',
17+
additionalFiles: ['/src/app/services/export-pdf-custom-font/fonts/noto-sans.json', '/src/app/services/export-pdf-custom-font/fonts/OFL.txt'],
18+
appConfig: BaseAppConfig
19+
}));
20+
1521
return configs;
1622
}
1723
}

src/app/services/export-pdf-custom-font/export-pdf-custom-font.component.ts

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
import { ChangeDetectionStrategy, Component, signal, computed, inject, viewChild, OnInit } from '@angular/core';
1+
import { ChangeDetectionStrategy, Component, signal, computed, inject, viewChild } from '@angular/core';
22
import { IgxColumnComponent, IgxPdfExporterService, IgxPdfExporterOptions } from 'igniteui-angular/grids/core';
33
import { IgxGridComponent } from 'igniteui-angular/grids/grid';
4+
import notoSansFontData from './fonts/noto-sans.json';
45

56
/**
67
* Demonstrates PDF export with a custom Unicode font.
78
*
89
* The sample ships with Noto Sans (Latin/Cyrillic/Greek) loaded from
9-
* assets/fonts/noto-sans.json. Users can also upload their own .ttf font —
10+
* fonts/noto-sans.json. Users can also upload their own .ttf font —
1011
* for example Noto Sans CJK for Japanese/Chinese/Korean support.
1112
*
1213
* All Noto fonts are licensed under the SIL Open Font License 1.1
13-
* (see assets/fonts/OFL.txt).
14+
* (see fonts/OFL.txt).
1415
*/
1516
@Component({
1617
selector: 'app-export-pdf-custom-font',
@@ -19,7 +20,7 @@ import { IgxGridComponent } from 'igniteui-angular/grids/grid';
1920
changeDetection: ChangeDetectionStrategy.OnPush,
2021
imports: [IgxGridComponent, IgxColumnComponent]
2122
})
22-
export class ExportPdfCustomFontComponent implements OnInit {
23+
export class ExportPdfCustomFontComponent {
2324
private pdfExporter = inject(IgxPdfExporterService);
2425

2526
protected readonly grid = viewChild.required<IgxGridComponent>('grid');
@@ -48,32 +49,12 @@ export class ExportPdfCustomFontComponent implements OnInit {
4849
{ Name: 'Ирина Петрова', City: 'Санкт-Петербург', Product: '製品 F', Amount: 2890 }
4950
]);
5051

51-
public ngOnInit(): void {
52-
this.loadBuiltInFont();
53-
}
54-
55-
/** Loads the built-in Noto Sans font from application assets. */
56-
private async loadBuiltInFont(): Promise<void> {
57-
this.builtInFontLoading.set(true);
58-
this.exportStatus.set('Loading built-in Noto Sans font…');
59-
60-
try {
61-
const response = await fetch('assets/fonts/noto-sans.json');
62-
if (!response.ok) {
63-
throw new Error(`HTTP ${response.status}`);
64-
}
65-
const fontJson: { normal: string; bold: string } = await response.json();
66-
67-
this.builtInFontData = fontJson.normal;
68-
this.builtInBoldFontData = fontJson.bold;
69-
this.builtInFontLoaded.set(true);
70-
this.exportStatus.set('Noto Sans loaded — ready to export. Upload a CJK font for Japanese/Chinese/Korean support.');
71-
} catch (error) {
72-
console.error('Failed to load built-in font:', error);
73-
this.exportStatus.set('Failed to load built-in Noto Sans font.');
74-
} finally {
75-
this.builtInFontLoading.set(false);
76-
}
52+
constructor() {
53+
const fontJson = notoSansFontData as unknown as { normal: string; bold: string };
54+
this.builtInFontData = fontJson.normal;
55+
this.builtInBoldFontData = fontJson.bold;
56+
this.builtInFontLoaded.set(true);
57+
this.exportStatus.set('Noto Sans loaded — ready to export. Upload a CJK font for Japanese/Chinese/Korean support.');
7758
}
7859

7960
/** Handles the user uploading a custom .ttf font file. */

src/assets/fonts/OFL.txt renamed to src/app/services/export-pdf-custom-font/fonts/OFL.txt

File renamed without changes.

src/assets/fonts/noto-sans.json renamed to src/app/services/export-pdf-custom-font/fonts/noto-sans.json

File renamed without changes.

0 commit comments

Comments
 (0)