如何生成在文档查看器中工作的纯文本源代码PDF示例? [英] How to generate plain-text source-code PDF examples that work in a document viewer?

查看:741
本文介绍了如何生成在文档查看器中工作的纯文本源代码PDF示例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚找到了 Adob​​e论坛:简单文字字串范例中的规格破碎,因此我有兴趣找到纯文本源代码PDF示例。

I just found the post Adobe Forums: Simple Text String Example in specification broken., so I got interested in finding plain-text source code PDF examples.

所以,通过那篇文章,我终于找到了:

So, through that post, I eventually found:


  • a href =http://www.adobe.com/devnet/pdf/pdf_reference.html =nofollow> PDF参考和Adobe扩展到PDF规范| Adobe开发人员连接;其中包含:
    • The webpage PDF Reference and Adobe Extensions to the PDF Specification | Adobe Developer Connection ; which contains:
      • The PDF Document Management – Portable Document Format – Part 1: PDF 1.7, First Edition (PDF32000_2008.pdf)

      PDF 1.7规格在第699页附录_Annex H(informative)PDF档案范例;并从那里,我想尝试H.3简单文本字符串示例(经典Hello World)。

      The PDF 1.7 spec has on page 699 appendix "_Annex H (informative) Example PDF files"; and from there, I wanted to try "H.3 Simple Text String Example" (the "classic Hello World").

      所以我试图将它保存为 hello.pdf (_except注意,当您从PDF32000_2008.pdf,您可能会得到%PDF-1。4 - 即在 1。 be removed_):

      So I tried to save this as hello.pdf (_except note when you copy from the PDF32000_2008.pdf, you may get "%PDF-1. 4" - that is, a space inserted after 1., which must be removed_) :

      %PDF-1.4
      1 0 obj
        << /Type /Catalog
            /Outlines 2 0 R
            /Pages 3 0 R
        >>
      endobj
      
      2 0 obj
        << /Type /Outlines
            /Count 0
        >>
      endobj
      
      3 0 obj
        << /Type /Pages
            /Kids [ 4 0 R ]
            /Count 1
        >>
      endobj
      
      4 0 obj
        << /Type /Page
            /Parent 3 0 R
            /MediaBox [ 0 0 612 792 ]
            /Contents 5 0 R
            /Resources << /ProcSet 6 0 R
            /Font << /F1 7 0 R >>
        >>
      >>
      endobj
      
      5 0 obj
        << /Length 73 >>
      stream
        BT
          /F1 24 Tf
          100 100 Td
          ( Hello World ) Tj
        ET
      endstream
      endobj
      

      ...我正尝试打开它:

      ... and I'm trying to open it:

      evince hello.pdf
      

      ...但是,evince无法打开它:无法打开文档/ PDF文档已损坏;还有:

      ... however, evince cannot open it: "Unable to open document / PDF document is damaged"; and also:

      Error: PDF file is damaged - attempting to reconstruct xref table...
      Error: Couldn't find trailer dictionary
      Error: Couldn't read xref table
      

      a href =http://qpdf.sourceforge.net/files/qpdf-manual.html =nofollow> qpdf

      I also check with qpdf:

      $ qpdf --check hello.pdf
      WARNING: hello.pdf: file is damaged
      WARNING: hello.pdf: can't find startxref
      WARNING: hello.pdf: Attempting to reconstruct cross-reference table
      hello.pdf: unable to find trailer dictionary while recovering damaged file
      

      我在哪里出错?

      非常感谢任何答案,

      干杯!

      Many thanks in advance for any answers,
      Cheers!

      推荐答案

      您应该在(语法正确的) xref trailer 文件。这意味着:PDF中的每个对象在外部参照表中都需要一行,即使字节偏移没有正确说明。然后Ghostscript,pdftk或qpdf可以重新建立正确的外部参照并渲染文件:

      You should append a (syntactically correct) xref and trailer section to the end of the file. That means: each object in your PDF needs one line in the xref table, even if the byte offset isn't correctly stated. Then Ghostscript, pdftk or qpdf can re-establish a correct xref and render the file:

      [...]
      endobj
      xref 
      0 8 
      0000000000 65535 f 
      0000000010 00000 n 
      0000000020 00000 n 
      0000000030 00000 n 
      0000000040 00000 n 
      0000000050 00000 n 
      0000000060 00000 n 
      0000000070 00000 n 
      trailer 
      <</Size 8/Root 1 0 R>> 
      startxref 
      555 
      %%EOF 
      

      这篇关于如何生成在文档查看器中工作的纯文本源代码PDF示例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆