在单个Android设备上使用PdfDocument获得奇怪的结果

时间:2022-09-11 04:05:39

In an android app I'm using PdfDocument to save a report to a pdf file. On a customer's device I'm getting a strange result with the text of the report.

在Android应用程序中,我正在使用PdfDocument将报告保存到pdf文件。在客户的设备上,我收到了报告文本的奇怪结果。

The following is image of header with the following text rendered in DroidSansMono:

以下是在DroidSansMono中呈现以下文本的标题图像:


Baus Demo Company
4727 4TH AVE SW STE 202
Seatle, WA 9816
Tel: 206-932-986
Fax: 206-932-986

Baus演示公司4727 4TH AVE SW STE 202 Seatle,WA 9816电话:206-932-986传真:206-932-986

在单个Android设备上使用PdfDocument获得奇怪的结果

I this same process renders well on most devices. I checked the pdf file and it has the correct font.

我在大多数设备上使用相同的过程。我检查了pdf文件,它有正确的字体。

here is the full PDF file: PDF File

这是完整的PDF文件:PDF文件

Can anyone help me figure out why the text is rendered so?

任何人都可以帮我弄清楚文本为何如此呈现?

1 个解决方案

#1


0  

The reason for this weird look is that this is exactly the formatting the PDF describes.

这种奇怪外观的原因是这正​​是PDF描述的格式。

Horizontal scaling

The content stream of the page consists of three sections:

页面的内容流由三部分组成:

The top section, all text above the image of a signature, contains at the beginning the instruction

顶部,即签名图像上方的所有文本,在开头包含指令

2000 Tz

Inside the section after some text a 1000 Tz follows, then again a 2000 Tz and yet again a 1000 Tz.

在一些文本之后的部分内部跟随1000Tz,然后再是2000Tz并且再次是1000Tz。

The Tz operator sets the horizontal scaling to the preceding number as a percentage value. Thus, these instruction cause all following text (until the end of the section where the graphics state is reset) to be horizontally stretched by a factor of either 10 or 20!

Tz运算符将水平缩放设置为前一个数字作为百分比值。因此,这些指令会导致所有后续文本(直到图形状态重置的部分结束)被水平拉伸10或20倍!

This explains why the glyphs are so wide but not why they overlap so much.

这解释了为什么字形如此宽,但不是为什么它们重叠如此之多。

Glyph widths and positioning

The reason why they overlap so much is that each glyph is individually positioned at a distance appropriate for a layout without horizontal scaling.

它们重叠的原因是每个字形分别位于适合布局的距离而没有水平缩放。

First of all, the DroidSansMono font information in the PDF declare that virtually all glyphs in the font have a width of 0. Thus, whenever a glyph is drawn, the text insertion point does not wander along to the glyph's end but remains at its start.

首先,PDF中的DroidSansMono字体信息声明几乎所有字体中的字形都具有宽度0.因此,无论何时绘制字形,文本插入点都不会漫游到字形的末尾,而是保持在其开头。

Furthermore, each glyph is drawn using an individual operation and between two such single glyph drawing operations the text insertion point is advanced by a separate instruction. But the distance parameter of this instruction is appropriate for the glyphs without horizontal scaling!

此外,每个字形使用单独的操作绘制,并且在两个这样的单个字形绘制操作之间,文本插入点由单独的指令前进。但是这条指令的距离参数适用于没有水平缩放的字形!

This causes all the overlaps.

这会导致所有重叠。


If this very PDF is rendered "well" (i.e. incorrectly ignoring the Tz operations) on most devices, the PDF renderer used on those devices clearly does a lousy job of PDF rendering.

如果在大多数设备上将这个非常好的PDF渲染(即错误地忽略了Tz操作),那么在这些设备上使用的PDF渲染器显然会造成糟糕的PDF渲染工作。

#1


0  

The reason for this weird look is that this is exactly the formatting the PDF describes.

这种奇怪外观的原因是这正​​是PDF描述的格式。

Horizontal scaling

The content stream of the page consists of three sections:

页面的内容流由三部分组成:

The top section, all text above the image of a signature, contains at the beginning the instruction

顶部,即签名图像上方的所有文本,在开头包含指令

2000 Tz

Inside the section after some text a 1000 Tz follows, then again a 2000 Tz and yet again a 1000 Tz.

在一些文本之后的部分内部跟随1000Tz,然后再是2000Tz并且再次是1000Tz。

The Tz operator sets the horizontal scaling to the preceding number as a percentage value. Thus, these instruction cause all following text (until the end of the section where the graphics state is reset) to be horizontally stretched by a factor of either 10 or 20!

Tz运算符将水平缩放设置为前一个数字作为百分比值。因此,这些指令会导致所有后续文本(直到图形状态重置的部分结束)被水平拉伸10或20倍!

This explains why the glyphs are so wide but not why they overlap so much.

这解释了为什么字形如此宽,但不是为什么它们重叠如此之多。

Glyph widths and positioning

The reason why they overlap so much is that each glyph is individually positioned at a distance appropriate for a layout without horizontal scaling.

它们重叠的原因是每个字形分别位于适合布局的距离而没有水平缩放。

First of all, the DroidSansMono font information in the PDF declare that virtually all glyphs in the font have a width of 0. Thus, whenever a glyph is drawn, the text insertion point does not wander along to the glyph's end but remains at its start.

首先,PDF中的DroidSansMono字体信息声明几乎所有字体中的字形都具有宽度0.因此,无论何时绘制字形,文本插入点都不会漫游到字形的末尾,而是保持在其开头。

Furthermore, each glyph is drawn using an individual operation and between two such single glyph drawing operations the text insertion point is advanced by a separate instruction. But the distance parameter of this instruction is appropriate for the glyphs without horizontal scaling!

此外,每个字形使用单独的操作绘制,并且在两个这样的单个字形绘制操作之间,文本插入点由单独的指令前进。但是这条指令的距离参数适用于没有水平缩放的字形!

This causes all the overlaps.

这会导致所有重叠。


If this very PDF is rendered "well" (i.e. incorrectly ignoring the Tz operations) on most devices, the PDF renderer used on those devices clearly does a lousy job of PDF rendering.

如果在大多数设备上将这个非常好的PDF渲染(即错误地忽略了Tz操作),那么在这些设备上使用的PDF渲染器显然会造成糟糕的PDF渲染工作。