我正在尝试使用 PDF 代码在 pdf 中创建一个表格。我已经成功地创建了一个表并且它在 Linux(Ubuntu) 中工作正常但是当我试图在 Windows 中打开它时它向我显示一条错误消息“文件已损坏”。这是我编辑的代码,
%PDF-1.5
%âãÏÓ
1 0 obj
<<
/PageLayout /OneColumn
/MarkInfo
<<
/Marked true
>>
/Outlines 2 0 R
/Lang <feff0045004e002d00550053>
/Pages 3 0 R
/StructTreeRoot 4 0 R
/Type /Catalog
>>
endobj
2 0 obj
<<
/First 5 0 R
/Type /Outlines
/Count 1
/Last 5 0 R
>>
endobj
3 0 obj
<<
/Kids [6 0 R]
/Type /Pages
/Count 1
>>
endobj
4 0 obj
<<
/ParentTree 7 0 R
/RoleMap 8 0 R
/ParentTreeNextKey 1
/K 9 0 R
/Type /StructTreeRoot
>>
endobj
5 0 obj
<<
/Title (Example table)
/Parent 2 0 R
/A 10 0 R
>>
endobj
6 0 obj
<<
/CropBox [0.0 0.0 612.0 792.0]
/Rotate 0
/StructParents 0
/Parent 3 0 R
/Resources
<<
/ColorSpace
<<
/CS1 11 0 R
/CS0 12 0 R
>>
/Font
<<
/TT2 13 0 R
/TT1 14 0 R
/TT0 15 0 R
>>
>>
/MediaBox [0.0 0.0 612.0 792.0]
/Type /Page
/Contents [16 0 R 17 0 R]
>>
endobj
9 0 obj
<<
/P 4 0 R
/K [18 0 R 19 0 R 20 0 R 21 0 R]
/S /Sect
>>
endobj
7 0 obj
<<
/Nums [0 22 0 R]
>>
endobj
8 0 obj
<<
/Subscript /Span
/Diagram /Figure
/Strikeout /Span
/Outline /Span
/DropCap /Figure
/InlineShape /Figure
/Footnote /Note
/Annotation /Span
/Underline /Span
/Superscript /Span
/Chart /Figure
/Endnote /Note
/TextBox /Art
>>
endobj
10 0 obj
<<
/D [6 0 R /XYZ 72 720 0.0]
/S /GoTo
>>
endobj
16 0 obj
<<
/Length 1991
>>
stream
BT
/H1 <</MCID 0 >>BDC
/CS0 cs 0.212 0.373 0.569 scn
/TT0 1 Tf
0.002 Tw 14.04 0 0 14.04 72 682.8 Tm
[(E)-3(x)4(a)-3(m)1(p)-1(le)10( t)6(a)-3(b)1(le)]TJ
0 Tw 6.496 0 Td
( )Tj
EMC
/P <</MCID 1 >>BDC
/CS1 cs 0 scn
/TT1 1 Tf
0.001 Tc -0.001 Tw 15.96 0 0 15.96 72 664.44 Tm
[(T)-1(hi)-3(s)1( )1(i)-3(s)1( )1(a)-1(n e)3(x)-2(a)-1(m)3(pl)-3(e)3( )-7(o)2(f)-2( )1(a)-1( da)-1(t)-2(a)-1( t)-2(a)-1(bl)-3(e)3(.)]TJ
0 Tc 0 Tw 13.789 0 Td
( )Tj
EMC
ET
/TH <</MCID 3 >>BDC
/CS0 cs 0.553 0.702 0.886 scn
84.84 632.64 76.68 14.88 re
f*
84.84 591.36 5.16 41.28 re
f*
156.36 591.36 5.16 41.28 re
f*
84.84 576.48 76.68 14.88 re
f*
EMC
/P <</MCID 4 >>BDC
90 618 66.36 14.64 re
f*
BT
/CS1 cs 0 scn
/TT2 1 Tf
0.004 Tc -0.004 Tw 12 0 0 12 90 621.24 Tm
[(D)4(is)3(a)8(b)1(il)10(it)1(y)8( )]TJ
ET
/CS0 cs 0.553 0.702 0.886 scn
90 591.36 66.36 26.64 re
f*
BT
/CS1 cs 0 scn
/TT2 1 Tf
-0.004 Tc 0.004 Tw 12 0 0 12 90 606.6 Tm
[(C)-5(at)-7(e)-1(go)-6(r)-9(y)]TJ
0 Tc 0 Tw ( )Tj
ET
EMC
/TH <</MCID 7 >>BDC
/CS0 cs 0.553 0.702 0.886 scn
162 625.32 71.76 22.2 re
f*
162 598.68 5.16 26.64 re
f*
228.6 598.68 5.16 26.64 re
f*
162 576.48 71.76 22.2 re
f*
EMC
/P <</MCID 8 >>BDC
167.16 598.68 61.44 26.64 re
f*
BT
/CS1 cs 0 scn
/TT2 1 Tf
0.003 Tc -0.003 Tw 12 0 0 12 167.16 613.92 Tm
[(P)5(a)7(r)-2(ti)-1(c)1(i)9(pa)7(nts)]TJ
0 Tc 0 Tw 4.95 0 Td
( )Tj
ET
EMC
/TH <</MCID 11 >>BDC
/CS0 cs 0.553 0.702 0.886 scn
234.24 632.64 71.52 14.88 re
f*
234.24 591.36 5.16 41.28 re
f*
300.6 591.36 5.16 41.28 re
f*
234.24 576.48 71.52 14.88 re
f*
EMC
/P <</MCID 12 >>BDC
239.4 618 61.2 14.64 re
f*
BT
/CS1 cs 0 scn
/TT2 1 Tf
0.004 Tc -0.004 Tw 12 0 0 12 239.4 621.24 Tm
[(B)5(a)8(llo)2(t)1(s)13( )]TJ
ET
/CS0 cs 0.553 0.702 0.886 scn
239.4 591.36 61.2 26.64 re
f*
BT
/CS1 cs 0 scn
/TT2 1 Tf
-0.003 Tc 0.003 Tw 12 0 0 12 239.4 606.6 Tm
[(C)-4(o)-5(mp)-6(l)-7(et)-6(ed)]TJ
0 Tc 0 Tw 4.55 0 Td
( )Tj
ET
EMC
endstream
endobj
17 0 obj
<<
/Length 707
>>
stream
/P <</MCID 42 >>BDC
q
84.84 550.56 76.68 25.44 re
W n
BT
/TT1 1 Tf
-0.001 Tc 0.001 Tw 11.04 0 0 11.04 90 565.56 Tm
[(Blin)2(d)]TJ
ET
Q
q
84.84 550.56 76.68 25.44 re
W n
BT
/TT1 1 Tf
11.04 0 0 11.04 112.56 565.56 Tm
( )Tj
ET
EMC
/P <</MCID 46 >>BDC
Q
q
162 550.56 71.76 25.44 re
W n
BT
/TT1 1 Tf
11.04 0 0 11.04 195.12 565.56 Tm
(5)Tj
ET
Q
q
162 550.56 71.76 25.44 re
W n
BT
/TT1 1 Tf
11.04 0 0 11.04 200.64 565.56 Tm
( )Tj
ET
EMC
/P <</MCID 50 >>BDC
Q
q
234.24 550.56 71.519 25.44 re
W n
BT
/TT1 1 Tf
11.04 0 0 11.04 267.24 565.56 Tm
(1)Tj
ET
Q
q
234.24 550.56 71.519 25.44 re
W n
BT
/TT1 1 Tf
11.04 0 0 11.04 272.76 565.56 Tm
( )Tj
ET
EMC
endstream
endobj
12 0 obj /DeviceRGB
endobj
11 0 obj /DeviceRGB
endobj
15 0 obj
<<
/BaseFont /Times-Roman
/Subtype /Type1
/Type /Font
/Encoding /WinAnsiEncoding
>>
endobj
14 0 obj
<<
/BaseFont /Helvetica
/Subtype /Type1
/Type /Font
/Encoding /WinAnsiEncoding
>>
endobj
13 0 obj
<<
/BaseFont /Courier
/Subtype /Type1
/Type /Font
/Encoding /WinAnsiEncoding
>>
endobj
18 0 obj
<<
/Pg 6 0 R
/P 9 0 R
/K 0
/S /H1
>>
endobj
19 0 obj
<<
/Pg 6 0 R
/P 9 0 R
/K 1
/S /P
>>
endobj
20 0 obj
<<
/P 9 0 R
/A 23 0 R
/K [24 0 R 25 0 R]
/S /Table
>>
endobj
21 0 obj
<<
/Pg 6 0 R
/P 9 0 R
/K 144
/S /P
>>
endobj
22 0 obj [18 0 R 19 0 R null 26 0 R 27 0 R null null 28 0 R 29 0 R null null 30 0 R 31 0 R null null null null null null null null null 24 0 R null null null null null null null null null null null null null null null null null null null 32 0 R null null null 33 0 R null null null 34 0 R null null null null null null null null null null null null null 25 0 R null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null 35 0 R null null null 36 0 R null null null 37 0 R null null null null null null null null null null null null null 38 0 R null null null null null null null null null null null null null null null null null null null null null null null null null 21 0 R]
endobj
23 0 obj
<<
/O /Layout
/Placement /Block
/BBox [84.11 446.51 545.89 648.25]
>>
endobj
24 0 obj
<<
/Pg 6 0 R
/P 20 0 R
/K [26 0 R 28 0 R 30 0 R]
/S /TR
>>
endobj
25 0 obj
<<
/Pg 6 0 R
/P 20 0 R
/K [39 0 R 40 0 R 41 0 R]
/S /TR
>>
endobj
38 0 obj
<<
/Pg 6 0 R
/P 20 0 R
/K [42 0 R 43 0 R 44 0 R]
/S /TR
>>
endobj
26 0 obj
<<
/Pg 6 0 R
/P 24 0 R
/K [27 0 R]
/S /TH
>>
endobj
27 0 obj
<<
/Pg 6 0 R
/P 26 0 R
/K 4
/S /P
>>
endobj
28 0 obj
<<
/Pg 6 0 R
/P 24 0 R
/K [29 0 R]
/S /TH
>>
endobj
29 0 obj
<<
/Pg 6 0 R
/P 28 0 R
/K 8
/S /P
>>
endobj
30 0 obj
<<
/Pg 6 0 R
/P 24 0 R
/K [11 31 0 R]
/S /TH
>>
endobj
31 0 obj
<<
/Pg 6 0 R
/P 30 0 R
/K 12
/S /P
>>
endobj
32 0 obj
<<
/Pg 6 0 R
/P 39 0 R
/K 42
/S /P
>>
endobj
33 0 obj
<<
/Pg 6 0 R
/P 40 0 R
/K 46
/S /P
>>
endobj
34 0 obj
<<
/Pg 6 0 R
/P 41 0 R
/K 50
/S /P
>>
endobj
35 0 obj
<<
/Pg 6 0 R
/P 42 0 R
/K 96
/S /P
>>
endobj
36 0 obj
<<
/Pg 6 0 R
/P 43 0 R
/K 100
/S /P
>>
endobj
37 0 obj
<<
/Pg 6 0 R
/P 44 0 R
/K 104
/S /P
>>
endobj
39 0 obj
<<
/P 25 0 R
/K 32 0 R
/S /TD
>>
endobj
40 0 obj
<<
/P 25 0 R
/K 33 0 R
/S /TD
>>
endobj
41 0 obj
<<
/P 25 0 R
/K 34 0 R
/S /TD
>>
endobj
42 0 obj
<<
/P 38 0 R
/K 35 0 R
/S /TD
>>
endobj
43 0 obj
<<
/P 38 0 R
/K 36 0 R
/S /TD
>>
endobj
44 0 obj
<<
/P 38 0 R
/K 37 0 R
/S /TD
>>
endobj xref
0 45
0000000000 65535 f
0000000015 00000 n
0000000190 00000 n
0000000263 00000 n
0000000322 00000 n
0000000430 00000 n
0000000500 00000 n
0000000849 00000 n
0000000889 00000 n
0000000775 00000 n
0000001130 00000 n
0000004027 00000 n
0000003999 00000 n
0000004203 00000 n
0000004130 00000 n
0000004055 00000 n
0000001190 00000 n
0000003237 00000 n
0000004274 00000 n
0000004329 00000 n
0000004383 00000 n
0000004460 00000 n
0000004516 00000 n
0000005296 00000 n
0000005384 00000 n
0000005461 00000 n
0000005615 00000 n
0000005678 00000 n
0000005733 00000 n
0000005796 00000 n
0000005851 00000 n
0000005917 00000 n
0000005973 00000 n
0000006029 00000 n
0000006085 00000 n
0000006141 00000 n
0000006197 00000 n
0000006254 00000 n
0000005538 00000 n
0000006311 00000 n
0000006362 00000 n
0000006413 00000 n
0000006464 00000 n
0000006515 00000 n
0000006566 00000 n
trailer
<<
/Root 1 0 R
/Size 45
>>
startxref
6616
%%EOF
最佳答案
注意:“在 Windows 中打开”是一个非陈述。您不能在 Windows 中“打开”PDF,您需要使用某些软件才能做到这一点。据推测,您尝试使用 Acrobat Reader 或类似的东西(您引用的错误消息来自 Acrobat Reader)。
它可以在 Mac OS X Preview 中使用,但话又说回来,这并不能真正告诉我们太多。 Preview 是由 Apple 编写的,它并不是一个真正符合标准的 PDF 阅读器(让任何使用透明度或色彩空间的人感到沮丧)。您没有提供您的文档应该是什么样子的图像;是这样的吗?
但它不能在 Acrobat X 中打开。(a) 检查 PDF 偏移——最有可能出错的地方——我发现 xref
11 0 obj
的偏移量错误向前。这会导致所有下一个对象的偏移量错误为 +89 字节,直到并包括结尾 startxref 6616
, IMO 应该是 6527
.
我通过比较每个 X 0 obj
的位置手动修复了 34 个错误的偏移量。使用十六进制编辑器,并使用 cr
保存行尾。我自己的检查工具出现错误:
The keyword stream that follows the stream dictionary should be followed by either a carriage return and a line feed or by just a line feed, and not by a carriage return alone. (PDF Reference 1.7, §3.2.7)
所以我用
lf
重新保存行尾。没有错误,它在 Preview 中正确显示,但在 Acrobat X 中仍然没有。我注意到
/Length
对象 16 和 17(页面内容对象)的键也关闭了。将它们更正为 1887
后和 648
,它仍然显示在预览中,但仍然不显示在 Acrobat X 中。问题似乎在于这些内容。请求 list 显示错误消息:“解析内容流时发生错误。无法分析 PDF 文件。”,并浏览内部 PDF 结构,我看到了来自
16 0 obj
的第一批文本格式化命令但他们在第 15 个命令处停止:/CS1 cs 0 scn
和下一个命令,
/TT1 1 Tf
,永远不会被看到。哦,好吧。检查
scn
的参数,我看到它们的数量取决于使用 cs
设置的色彩空间;还有你的问题。两个
11 0 obj
和 12 0 obj
设置颜色空间,他们都将其设置为 /DeviceRGB
.所以 /CS1
的参数数量(在 11 0 obj
中定义)是错误的——你只提供一个。可以肯定地假设您的意思是 /DeviceGray
,你瞧,在最后的改变之后,我在 Acrobat X 中看到了这个:以及适当的库存和完全可浏览的 PDF 结构。
这个文件有很多小问题,但 PDF 格式本身就很有弹性。错误的偏移量,可能还有长度,可能已经被默默地纠正了(PDF规范允许这样做),但是颜色空间的错误参数正在扼杀它。
(a) 重读后的澄清:它在 Acrobat 中打开,但只显示空白页;没有任何类型的错误消息。
添加
这让我想到:是
/DeviceRGB
在 Acrobat X 中失败的唯一原因是什么?否:在重新加载原始 PDF 并仅更改那一行后,Acrobat 说文件已损坏,无法修复。因此,幸运的是,我所做的所有额外检查都不是白费的。
关于pdf - (手动创建)PDF 在 Ubuntu 上运行良好,但在 Windows 中无法运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20745056/