title: How to generate plain-text source-code PDF examples that work in a document viewer?
body: <p>I just found the post <a href="http://forums.adobe.com/thread/285416" rel="noreferrer">Adobe Forums: Simple Text String Example in specification broken.</a>, so I got interested in finding plain-text source code PDF examples. </p>
  
  <p>So, through that post, I eventually found: </p>
  
  <ul>
  <li>The webpage <a href="http://www.adobe.com/devnet/pdf/pdf_reference.html" rel="noreferrer">PDF Reference and Adobe Extensions to the PDF Specification | Adobe Developer Connection</a> ; which contains:
  <ul>
  <li>The PDF <a href="http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/devnet/pdf/pdfs/PDF32000_2008.pdf" rel="noreferrer">Document Management – Portable Document Format – Part 1: PDF 1.7, First Edition (PDF32000_2008.pdf)</a> </li>
  </ul></li>
  </ul>
  
  <p>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"). </p>
  
  <p>So I tried to save this as <code>hello.pdf</code> (_except note when you copy from the PDF32000_2008.pdf, you may get "<code>%PDF-1. 4</code>" - that is, a space inserted after <code>1.</code>, which must be removed_) :</p>
  
  <pre><code>%PDF-1.4
  1 0 obj
    &lt;&lt; /Type /Catalog
        /Outlines 2 0 R
        /Pages 3 0 R
    &gt;&gt;
  endobj
  
  2 0 obj
    &lt;&lt; /Type /Outlines
        /Count 0
    &gt;&gt;
  endobj
  
  3 0 obj
    &lt;&lt; /Type /Pages
        /Kids [ 4 0 R ]
        /Count 1
    &gt;&gt;
  endobj
  
  4 0 obj
    &lt;&lt; /Type /Page
        /Parent 3 0 R
        /MediaBox [ 0 0 612 792 ]
        /Contents 5 0 R
        /Resources &lt;&lt; /ProcSet 6 0 R
        /Font &lt;&lt; /F1 7 0 R &gt;&gt;
    &gt;&gt;
  &gt;&gt;
  endobj
  
  5 0 obj
    &lt;&lt; /Length 73 &gt;&gt;
  stream
    BT
      /F1 24 Tf
      100 100 Td
      ( Hello World ) Tj
    ET
  endstream
  endobj
  </code></pre>
  
  <p>... and I'm trying to open it: </p>
  
  <pre><code>evince hello.pdf
  </code></pre>
  
  <p>... however, evince cannot open it: "Unable to open document / PDF document is damaged"; and also: </p>
  
  <pre><code>Error: PDF file is damaged - attempting to reconstruct xref table...
  Error: Couldn't find trailer dictionary
  Error: Couldn't read xref table
  </code></pre>
  
  <p>I also check with <a href="http://qpdf.sourceforge.net/files/qpdf-manual.html" rel="noreferrer"><code>qpdf</code></a>: </p>
  
  <pre><code>$ 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
  </code></pre>
  
  <p>Where am I going wrong with this? </p>
  
  <p>Many thanks in advance for any answers,<br>
  Cheers!</p>