【问题标题】:PDF Error reading a content streamPDF 读取内容流时出错
【发布时间】:2018-02-12 03:50:43
【问题描述】:

我正在捕获对show 的postscript 调用,并将当前字体和字体大小存储到pdf 文本对象中输出。

PDF file
Input Postscript Program

但是identify 给了我一个错误:

$ identify pd0.pdf
   **** Error reading a content stream. The page may be incomplete.
   **** File did not complete the page properly and may be damaged.
   **** Error reading a content stream. The page may be incomplete.
   **** File did not complete the page properly and may be damaged.
   **** Error reading a content stream. The page may be incomplete.
   **** File did not complete the page properly and may be damaged.

   **** This file had errors that were repaired or ignored.
   **** Please notify the author of the software that produced this
   **** file that it does not conform to Adobe's published PDF
   **** specification.

pd0.pdf[0] PBM 612x792 612x792+0+0 16-bit Bilevel Gray 61KB 0.000u 0:00.000
pd0.pdf[1] PBM 612x792 612x792+0+0 16-bit Bilevel Gray 61KB 0.000u 0:00.000
pd0.pdf[2] PBM 612x792 612x792+0+0 16-bit Bilevel Gray 61KB 0.000u 0:00.000

ghostscript 的输出并没有给我理解问题所需的详细信息:

$ gsnd -dPDFDEBUG pd0.pdf
GPL Ghostscript 9.18 (2015-10-05)
Copyright (C) 2015 Artifex Software, Inc.  All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
<<
/Root 1 0 R
/Size 12 >>
%Resolving: [1 0]
<<
/Type /Catalog /Pages 2 0 R
>>
endobj
%Resolving: [2 0]
<<
/Kids [
3 0 R
6 0 R
9 0 R
]
/Type /Pages /Count 3 >>
endobj
%Resolving: [3 0]
<<
/Parent 2 0 R
/Contents [
5 0 R
]
/MediaBox [
0.0 0.0 612.0 792.0 ]
/Resources <<
/Font <<
/F1 4 0 R
>>
/ProcSet [
/PDF /Text ]
>>
/Type /Page >>
endobj
%Resolving: [6 0]
<<
/Parent 2 0 R
/Contents [
8 0 R
]
/MediaBox [
0.0 0.0 612.0 792.0 ]
/Resources <<
/Font <<
/F2 7 0 R
>>
/ProcSet [
/PDF /Text ]
>>
/Type /Page >>
endobj
%Resolving: [9 0]
<<
/Parent 2 0 R
/Contents [
11 0 R
]
/MediaBox [
0.0 0.0 612.0 792.0 ]
/Resources <<
/Font <<
/F3 10 0 R
>>
/ProcSet [
/PDF /Text ]
>>
/Type /Page >>
endobj
%Resolving: [1 0]
%Resolving: [2 0]
%Resolving: [1 0]
%Resolving: [1 0]
%Resolving: [1 0]
%Resolving: [1 0]
%Resolving: [1 0]
%Resolving: [2 0]
Processing pages 1 through 3.
Page 1
%Resolving: [1 0]
%Resolving: [2 0]
%Resolving: [3 0]
%Resolving: [3 0]
%Resolving: [3 0]
%Resolving: [3 0]
%Resolving: [3 0]
%Resolving: [2 0]
%Resolving: [1 0]
%Resolving: [2 0]
%Resolving: [2 0]
%Resolving: [1 0]
%Resolving: [2 0]
%Resolving: [1 0]
%Resolving: [2 0]
%Resolving: [5 0]
<<
/Length 15660 >>
stream
%FilePosition: 471
endobj
BT
F1
10.0 Tf
%Resolving: [4 0]
<<
/Type /Font /SubType /Type1 /BaseFont /Palatino-Roman >>
endobj
   **** Error reading a content stream. The page may be incomplete.
   **** File did not complete the page properly and may be damaged.
Page 2
%Resolving: [1 0]
%Resolving: [2 0]
%Resolving: [3 0]
%Resolving: [6 0]
%Resolving: [6 0]
%Resolving: [6 0]
%Resolving: [6 0]
%Resolving: [6 0]
%Resolving: [2 0]
%Resolving: [1 0]
%Resolving: [2 0]
%Resolving: [2 0]
%Resolving: [1 0]
%Resolving: [2 0]
%Resolving: [1 0]
%Resolving: [2 0]
%Resolving: [8 0]
<<
/Length 31667 >>
stream
%FilePosition: 16474
endobj
BT
F2
10.0 Tf
%Resolving: [7 0]
<<
/Type /Font /SubType /Type1 /BaseFont /Palatino-Roman >>
endobj
   **** Error reading a content stream. The page may be incomplete.
   **** File did not complete the page properly and may be damaged.
Page 3
%Resolving: [1 0]
%Resolving: [2 0]
%Resolving: [3 0]
%Resolving: [6 0]
%Resolving: [9 0]
%Resolving: [9 0]
%Resolving: [9 0]
%Resolving: [9 0]
%Resolving: [9 0]
%Resolving: [2 0]
%Resolving: [1 0]
%Resolving: [2 0]
%Resolving: [2 0]
%Resolving: [1 0]
%Resolving: [2 0]
%Resolving: [1 0]
%Resolving: [2 0]
%Resolving: [11 0]
<<
/Length 8335 >>
stream
%FilePosition: 48487
endobj
BT
F3
10.0 Tf
%Resolving: [10 0]
<<
/Type /Font /SubType /Type1 /BaseFont /Palatino-Roman >>
endobj
   **** Error reading a content stream. The page may be incomplete.
   **** File did not complete the page properly and may be damaged.

   **** This file had errors that were repaired or ignored.
   **** Please notify the author of the software that produced this
   **** file that it does not conform to Adobe's published PDF
   **** specification.

GS>

谁能帮我理解我输出的 pdf 文件有什么问题?

【问题讨论】:

  • 第一次检查:第一个流15660 的长度似乎不正确,应该是15661。之后,下一个对象的xref 偏移量由1 偏移。但是,由于修复这些数字并不能使其在 Acrobat 中可读,因此肯定还有更多。您创建这些项目的源代码是什么?
  • Ghostscript 似乎在抱怨对象 4 0,一种 1 型字体和对象 7 0,也是一种 1 型字体。在这种情况下,您应该设置 PDFSTOPONERROR 和 PDFDEBUG,它可能会给您一个 PostScript 错误,这可能对您更有用。事实上,它在运行时给出了“未定义”,这表明其中使用了未定义的过程。 1 型字体似乎不太可能。请注意,正如 usr2564301 所述,当前代码(您应该真正更新,9.18 已经 2 岁)确实抱怨对象 5(第一个流)的长度不正确。让我看看PDF。
  • 好吧,它是一个常见的,你把 /Subtype 拼错为 /SubType。如果我更正那个(3 次出现),它就可以了。
  • @usr2564301 代码与code in this question 类似,但在获得报酬之前,我不会尝试在线分享最新版本。 :)
  • 而且您不使用名称对象来引用字体。使用名称对象并修复“子类型”问题足以让 Adob​​e Reader 在您的 PDF 中显示文本。 PDF 不是真的有效,但至少 Adob​​e Reader 可以使用它。

标签: pdf pdf-generation postscript


【解决方案1】:

PDF 中有许多错误。根据所讨论的 PDF 查看器,需要修复它们中更小或更大的子集,以允许按预期显示 PDF。

页面内容流

页面内容流的内容如下所示:

BT F1 10.0 Tf 30.0 750.0 Td (<< ) Tj ET BT F1 10.0 Tf 50.0 738.0 Td (/) Tj ET [...]

这里的错误在字体选择说明中:

F1 10.0 Tf

字体名称操作数 F1 不是作为 PDF 名称对象(可通过前导斜杠识别)给出的,而是作为通常为指令运算符保留的一些通用文字。

(顺便说一句,这些内容流结构不必要地臃肿,大多数单独的文本对象仅绘制一到三个字形,并且具有(总是相同的)它们自己的文本字体选择指令。本身不是错误,但完全没有必要)

此外,正如 @usr2564301 已经指出的那样,流长度似乎减少了 1。

字体资源

每个字体资源如下所示:

<<
  /Type /Font 
  /SubType /Type1 
  /BaseFont /Palatino-Roman 
>>

首先存在一个问题:正如@KenS 已经指出的那样,正确的拼写是Subtype,而不是SubType

还有另一个问题:因此,直到 PDF 1.7 的短字体资源字典仅允许用于标准 14 种字体,而对于 PDF 2.0,则根本不再允许使用。由于 Palatino-Roman 显然不是标准的 14 字体,因此资源是不完整的。

根据表 109 — ISO 32000-2 中 Type 1 字体字典中的条目,

  • TypeSubtypeBaseFont 普遍必需
  • FirstCharLastCharWidthsFontDescriptor 是必需的,但在 PDF 1.0-1.7 中是可选的标准 14 种字体,
  • 名称 在 PDF 1.0 中是必需的,在 PDF 1.1 到 1.7 中是可选的,在 PDF 2.0 中已弃用,并且
  • EncodingToUnicode 普遍可选

根据您尝试使用的 PDF 查看器,要求可能看起来更宽松,但如果您不符合规范要求,任何 PDF 处理器都可能会合理地拒绝您的 PDF。

交叉引用

@usr2564301 还提到许多交叉引用表条目(以及对交叉引用表本身开头的引用)都偏离了 1。

它们确实不指向对象编号/ xref 文字,而是指向之前的空白。由于在数字/文字之前只需要忽略空格,因此许多 PDF 处理器不会注意到。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-05
    • 2011-04-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多