Skip to content

Commit 2ffe6c9

Browse files
Copilotgedinakova
andcommitted
Add demonstration of Unicode PDF export functionality
Co-authored-by: gedinakova <[email protected]>
1 parent 5892a73 commit 2ffe6c9

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

demo-unicode-pdf.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const { jsPDF } = require('jspdf');
2+
const fs = require('fs');
3+
4+
// Load the font from the project
5+
const fontContent = fs.readFileSync('./projects/igniteui-angular/grids/core/src/services/pdf/roboto-subset-font.ts', 'utf8');
6+
const fontMatch = fontContent.match(/export const RobotoSubsetFont = '([^']+)'/);
7+
const RobotoSubsetFont = fontMatch[1];
8+
9+
console.log('📝 Creating PDF with Unicode characters...\n');
10+
11+
const pdf = new jsPDF();
12+
pdf.addFileToVFS('Roboto-Subset.ttf', RobotoSubsetFont);
13+
pdf.addFont('Roboto-Subset.ttf', 'Roboto', 'normal');
14+
pdf.setFont('Roboto', 'normal');
15+
pdf.setFontSize(12);
16+
17+
pdf.setFont('Roboto', 'bold');
18+
pdf.text('Grid Export with Unicode Headers', 20, 20);
19+
20+
pdf.setFont('Roboto', 'normal');
21+
pdf.setFontSize(10);
22+
23+
const y = 40;
24+
pdf.text('会社名 (Company Name)', 20, y);
25+
pdf.text('中文 (Chinese)', 120, y);
26+
pdf.text('日本語 (Japanese)', 200, y);
27+
28+
pdf.text('テスト株式会社', 20, y + 10);
29+
pdf.text('测试公司', 120, y + 10);
30+
pdf.text('サンプル', 200, y + 10);
31+
32+
const pdfData = pdf.output('arraybuffer');
33+
fs.writeFileSync('/tmp/demo-unicode-output.pdf', Buffer.from(pdfData));
34+
35+
console.log('✅ PDF created successfully!');
36+
console.log(' Path: /tmp/demo-unicode-output.pdf');
37+
console.log(' Size:', (pdfData.byteLength / 1024).toFixed(2), 'KB');
38+
console.log('\n✅ Unicode characters are properly supported!');
39+
console.log(' - Chinese: 会社名, 中文, 测试公司');
40+
console.log(' - Japanese: 日本語, テスト株式会社, サンプル');

0 commit comments

Comments
 (0)