A .NET MAUI Blazor Hybrid app that creates an Arabic, right-to-left PDF with the JavaScript package
@syncfusion/ej2-pdf running inside the Blazor WebView.
js/pdf-generator.jsimportsPdfDocument,PdfPageSettings,PdfMargins,PdfBrush,PdfStringFormat,PdfTextDirection,PdfTextAlignmentandPdfTrueTypeFontfrom@syncfusion/ej2-pdf.- The Noto Naskh Arabic TTF is downloaded with
fetchfromhttps://cdn.syncfusion.com/content/pdf-resources/noto-naskh-arabic-regular.ttf(cached after first load) and turned into aUint8Array. - A
PdfTrueTypeFontis created from those bytes and the text is drawn with aPdfStringFormatusingPdfTextDirection.rightToLeftandPdfTextAlignment.right. - The PDF bytes are returned to Blazor as a base64 string through JS interop (
generateArabicPdf). Services/PdfService.csdecodes them, savesArabicSample.pdfinFileSystem.Current.AppDataDirectory, and opens it with anACTION_VIEWintent through aFileProvider(falls back to the share sheet if no viewer is installed).Components/Pages/PdfGenerator.razorprovides the UI: editable Arabic text and a Generate PDF button (saves the PDF and opens it in the Android viewer) and an Extract Text button.- Extract Text calls
extractTextFromPdf(), which downloads (once, then caches)ArabicText.pdf, extracts the text lines of page 0 withPdfDataExtractorfrom@syncfusion/ej2-pdf-data-extract, and shows them in an RTL, scrollable output block. Failures are logged to the console and shown in the output block.
| Path | Purpose |
|---|---|
js/pdf-generator.js |
Source module using EJ2 PDF |
wwwroot/js/pdf-generator.js |
esbuild bundle (generated, git-ignored) |
Services/PdfService.cs |
JS interop, save, open, share |
Components/Pages/PdfGenerator.razor |
Blazor UI |
Platforms/Android/ |
Manifest (INTERNET permission, FileProvider, PDF queries) and file_paths.xml |
- .NET 9 SDK with the MAUI workload:
dotnet workload install maui-android - Android SDK + an emulator (API 21+)
- Node.js 18+ (to bundle the JS)
- Internet access on the emulator/device (to download the font)
npm install
npm run build:js # bundles @syncfusion/ej2-pdf into wwwroot/js/pdf-generator.js
dotnet build -t:Run -f net9.0-androidThe csproj also runs the npm steps automatically if the bundle is missing. Re-run npm run build:js after editing
js/pdf-generator.js.
@syncfusion/ej2-pdfis a Syncfusion commercial package; a license may be required for production use.- The font is fetched at runtime; for offline use, add the TTF to
wwwroot/and changearabicFontUrlto a relative path.