PDFVIEW.CREATEWEBPRINTJOB:导出的PDF未显示正确的字体样式(Android 12)

发布于 2025-02-06 07:48:30 字数 1307 浏览 2 评论 0原文

我正在使用pdfview.createwebprintjob将WebView转换为PDF。到目前为止,我可以成功转换,除了字体样式在查看PDF时未正确加载。我正在使用Google字体Noto-serif,它看起来只有在字体重量大胆或600以上时起作用。

这是我的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>

在WebView中,加载自定义字体没有问题:

中,该字体在大多数PDF查看器中都无法正确显示正常字体样式的字体。但是,当字体样式大胆或重量时,它显示正确显示

。 https://i.sstatic.net/1s5si.png“ alt =“ firefox”>

在Android 10中测试,没有问题。到目前为止,它只发生在Android 12中。

这可能是什么问题?任何帮助将不胜感激。

谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不离久伴 2025-02-13 07:48:31

当我尝试调用activity.getSystemService(android.content.context.print_service)时,我也有类似的字体问题。's createPrintDocumentAdapter(),所以我认为问题不是在pdfview中,而是在Android系统本身中。

就我而言,如果在CSS中,我尝试说font-family:times new roman(通常将其映射到notoserif,但您不能按名称要求notoserif,您必须要求一些东西像《时代的新罗马》一样),它在屏幕上和pdf上都可以在模拟的像素2上运行Android 10或Android 12,并且在真正的三星Galaxy S9上运行Android 10,但是当我移至三星Galaxy S21时运行Android 12,它在屏幕上工作,但不使用pdf ,而在pdf中替换的字体则缺失了诸如ǎ(在我的情况下,这很重要,因为我试图尝试为中文写拼音发音辅助工具,我最终得到了丢失的字母)。

这两种设备都具有相同版本的Android System WebView应用程序(102.0.5005.78),因此我想在三星在Android 12的打印服务中必须有所不同,而WebView尚未更新以匹配的WebView。

至少如果我设置字体家庭:sans-serif而不是在pdf中缺少字母(如果我只是将其放入@media(print) CSS的一节),因此,如果我检测到API级别31或更高(或者,如果没有人能确认Android 11没有这个问题,我可能会在CSS上添加丢失的字母。 。不幸的是,我不确定如何正确地与相关开发人员一起提出错误。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文