Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Thu Dec 01, 2022 4:09 pm

Hi

I'm trying to create a PDF on Android using Spire.PDF for Android via Java 4.1.0.
The problem I'm having is:

If I use
Code: Select all
private static final PdfFontBase font = new PdfFont(PdfFontFamily.Helvetica, 10);
then UTF-8 characters are not correctly displayed in the resulting PDF. (For example the German word "Änderung")

If I use
Code: Select all
private static final PdfFontBase font = new PdfTrueTypeFont("Arial", 10);
(like for .Net), it obviously doesn't work because Android doesn't have an Arial Font.

Based on this SO-question/answer https://stackoverflow.com/questions/39535475/what-is-the-default-font-family-in-android I also tried
Code: Select all
 private static final PdfFontBase font = new PdfTrueTypeFont("sans-serif", 10);
and
Code: Select all
private static final PdfFontBase font = new PdfTrueTypeFont("Roboto", 10);
which doesn't work.

PdfCjkStandardFonts work, but they don't look good for normal text.

So how can I display UTF-8 characters correctly?
And yes, I probably could bundle some font file with my app and embed this. But delivering fonts with your app is legally very complicated so I'd like to not do that.

RicoScheller
 
Posts: 35
Joined: Tue Jul 02, 2019 10:34 am

Fri Dec 02, 2022 10:05 am

Hello,

Thanks for your inquiry.
For your issue, please make sure that these fonts(Helvetica、Arial、sans-serif、Roboto) has been installed in your computer. Due to if your computer doesn’t install these fonts, there may be appearing disorder in result PDF file. If these fonts are installed in your computer, but the issue still exists, please offer the following message to help us reproduce your issue and work out a solution for you.
1) The simple test project that can reproduce your issue. You could upload your large file via Dropbox or OneDrive server, then share us with the download link.
2) Your input file(if any).
3) Your OS information (E.g. Win7, 64 bit) and region setting (E.g. China, Chinese)
4) Your gradle version (E.g. gradle-5.1)

Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 1010
Joined: Tue Mar 08, 2022 2:02 am

Mon Dec 05, 2022 12:19 pm

Ok, while creating a sample project, I realized that using "PdfFontFamily.Helvetica" in Spire.PDF for Android 4.1.0 leads to wrongly displayed UTF-8 characters, but the same works in version 8.8.1.

So, even though the release notes https://www.e-iceblue.com/news/spire-pdf-java/Spire.PDF-for-Android-via-Java-8.8.1-enhances-the-conversion-from-PDF-to-DOCX.html say nothing about this, upgrading to version 8.8.1 fixed the issue.

RicoScheller
 
Posts: 35
Joined: Tue Jul 02, 2019 10:34 am

Tue Dec 06, 2022 2:39 am

Hello,

Thanks for your feedback.
I'm glad to hear that your issue has been solved in the latest version. If you have any issue, just feel free to contact us.

Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 1010
Joined: Tue Mar 08, 2022 2:02 am

Return to Spire.PDF