forked from Yara724/api
PDF generation
This commit is contained in:
27
src/helpers/persian-pdf-text.ts
Normal file
27
src/helpers/persian-pdf-text.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
/** Strip invisible bidi / ZWNJ chars that render as tofu in embedded Arabic fonts. */
|
||||
export function normalizePersianPdfText(text: string): string {
|
||||
return text
|
||||
.replace(/\u200c/g, " ")
|
||||
.replace(/[\u200e\u200f\u202a-\u202e\u2066-\u2069\ufeff]/g, "")
|
||||
.replace(/\u2014/g, "-")
|
||||
.replace(/\s+/g, " ")
|
||||
.trim();
|
||||
}
|
||||
|
||||
export function pdfKitRtlKeyValue(
|
||||
label: string,
|
||||
value: string,
|
||||
): { label: string; value: string } {
|
||||
return {
|
||||
label: normalizePersianPdfText(label),
|
||||
value: normalizePersianPdfText(value),
|
||||
};
|
||||
}
|
||||
|
||||
export function pdfKitRtlParagraph(text: string): string {
|
||||
return normalizePersianPdfText(text);
|
||||
}
|
||||
|
||||
export function isMostlyAscii(text: string): boolean {
|
||||
return text.length > 0 && !/[\u0600-\u06FF]/.test(text);
|
||||
}
|
||||
Reference in New Issue
Block a user