Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] PdfView.createWebPrintJob: exported PDF is not displaying correct font style (Android 12)

Posted on November 11, 2022 By

Solution 1 :

I have a similar problem with fonts when I try to call activity.getSystemService(android.content.Context.PRINT_SERVICE)).print() with an object returned from an android.webkit.WebView‘s createPrintDocumentAdapter(), so I think the problem is not in PdfView but in the Android system itself.

In my case, if in the CSS I try to say font-family: Times New Roman (which normally maps to NotoSerif, but you can’t ask for NotoSerif by name, you have to ask for something like Times New Roman), it works both on-screen and in-PDF on a simulated Pixel 2 running either Android 10 or Android 12, and on a real Samsung Galaxy S9 running Android 10, but when I move over to a Samsung Galaxy S21 running Android 12, it works on-screen but not in-PDF and the font that gets substituted in the PDF is missing characters like ǎ (which is a big deal in my case as I’m trying to write Pinyin pronunciation aids for Chinese and I end up with missing letters).

Both devices have the same version of the Android System Webview app (102.0.5005.78), so I guess something must be different in the print service of Android 12 on Samsung which Webview has not yet been updated to match.

At least I don’t get letters missing in PDF if I set font-family: sans-serif instead (also works if I just put it into an @media(print) section of the CSS), so I will probably be working around my missing letters by adding that to the CSS if I detect API level 31 or above (or perhaps level 30 if nobody can confirm that Android 11 doesn’t have this problem). Unfortunately I’m not sure how to raise a bug with the relevant developers properly.

READ  [FIXED] android - Change a font family name in pubspec.yaml
Powered by Inline Related Posts

Problem :

I’m using PdfView.createWebPrintJob to convert Webview into PDF. So far I can successfully convert except that font style is not loading properly when viewing the PDF. I’m using google font Noto-Serif, and it looks like it works only when font-weight is bold or above 600.

Here is my html:

<html>
    <head>
        <style type="text/css">
@font-face {
  font-family: 'Noto';
  font-style: normal;
  src: url('NotoSerif-Regular.ttf');
}
p.normal {
font-family: 'Noto';
font-size:14px;
}
p.bold {
font-family: 'Noto';
font-size:18px;
font-weight: bold;
}
p.large{
font-family: 'Noto';
font-weight: 600;
font-size:18px;
}
</style>
    </head>
    <body>
        <p class="normal">Normal - not working</p>
        <p class="bold">Bold - working</p>
        <p class="large">W600 - working</p>
    </body>
</html>

In the webview, there’s no issue loading the custom font:
No issue in the webview

Now when viewing the PDF, the font is not displaying correctly for the normal font style in most PDF viewers. But it displays properly when font style is bold or weight>=600.

Firefox

Tested in Android 10 and there’s no issue. So far, it only happens in Android 12.

What could be the issue? Any help will be appreciated.

Thanks!

Android Tags:android, android-webview, google-fonts, pdf, webview

Post navigation

Previous Post: [FIXED] android developer api – there is a ‘Late Initialization Error’ during flutter development
Next Post: [FIXED] android – How to set SSL pinning using retrofit for Firebase Realtime Database Url?

Related Posts

[FIXED] java – Trying to create a custom layout that extends constraintlayout Android
[FIXED] android – Attempt to invoke virtual method ‘int java.lang.String.length()’ on a null object reference, iven that object is not null and initialize Android
[FIXED] android – Link bintray repo to jcenter Android
[FIXED] android-add moving header above RecyclerView Android
[FIXED] How to get pop up message texts while automating Mobile App using Appium selenium C#? Android
[FIXED] android – Can not dissmiss progress default progress dialog andorid Android

Archives

  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • What are the main features of Islamic education?
  • Is the Jeep 4xe worth it?
  • How does the ringer work on cast iron?
  • What is the biggest size interior door?
  • Is blue raspberry an original Jolly Rancher flavor?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme