Custom fonts are not displayed in pdfs

31 views
Skip to first unread message

Alexander Altukhov

unread,
Jun 26, 2024, 12:17:23 PM (10 days ago) Jun 26
to pdfium
Hello,

I am using pdfium in my flutter project. No third party wrappers, just a compiled binary that is used via dart:ffi.

I need to display pdf with non-embedded Arial font on android device. This font is not available on the device, and the replacement font does not display Cyrillic characters. This behaviour can be seen if you open the attached pdf via google drive on android.

Based on the documentation, I can pass the font search paths to the m_pUserFontPaths field during initialisation, but that doesn't change anything. I used application documents directory and app-specific external storage (for the sake of experiment) as my font storage folder. The files Arial.ttf and ArialMT.ttf were in them. The fonts are definitely available and valid, they can be used with FPDFText_LoadFont, the added cyrillic text is displayed correctly.

The following questions have arisen:
1. Is it accurate that pdfium can access the specified font directory? The passed list of strings looks like this
["/data/user/0/com.example.app/app_flutter", nullptr]
Maybe it is necessary to put fonts somewhere else? If something goes wrong at this stage, is error information available somewhere? (FPDF_GetLastError does not report anything)
2. I found out that pdfium for objects with missing Arial font defines the font as Chrom Sans OTF (this is what FPDFFont_GetFontName function returns). What is that? The name of a substitution font?
3. From the description, it appears that FPDFText_LoadFont loads the font into the document and it becomes embedded. However, after such loading the problematic Cyrillic is still not displayed. Only the text added afterwards will be displayed correctly. Is this expected behaviour?
4. Are there any workarounds? For example, assigning a custom font as the default font. Or search all text objects and replace the font with the result of FPDFText_LoadFont execution.

Any help would be appreciated.
example.pdf

Lei Zhang

unread,
Jul 1, 2024, 2:01:58 PM (5 days ago) Jul 1
to Alexander Altukhov, pdfium
Please file a bug report for this at https://crbug.com/pdfium/new

I think the issue is that the Linux "fxge" implementation in core/fxge/linux/fx_linux_impl.cpp takes the embedder-specified font paths into account, while the Android implementation in core/fxge/android/cfx_androidfontinfo.cpp and core/fxge/android/cfpf_skiafontmgr.cpp does not. One can see in cfpf_skiafontmgr.cpp the only path that is being scanned is /system/fonts and there is no GetUserFontPaths() call.

--
You received this message because you are subscribed to the Google Groups "pdfium" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pdfium+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pdfium/42a9c720-2d04-43ae-b3c5-80bc93bd7826n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages