How to compare two PDF documents
It&#x27;s been a while, but if I remember right PDF is nothing more than PostScript with extensions by Adobe and a PDF pre-amble. Essentially, it is structured text based on PostScript with the possibility of added embedded binary streams for things such as forms. Given this, implementing a good compare tool should not be too difficult.<p>The hardest parts would probably be scoping to figure out what Adobe extensions to support, and acquiring or reverse engineering the Adobe extension formats.<p>Simple PDF example:<p><pre><code>  %PDF-1.3
  %‚„œ”

  1 0 obj
  &lt;&lt;
  &#x2F;Type &#x2F;Catalog
  &#x2F;Outlines 2 0 R
  &#x2F;Pages 3 0 R
  &gt;&gt;
  endobj

  2 0 obj
  &lt;&lt;
  &#x2F;Type &#x2F;Outlines
  &#x2F;Count 0
  &gt;&gt;
  endobj

  3 0 obj
  &lt;&lt;
  &#x2F;Type &#x2F;Pages
  &#x2F;Count 2
  &#x2F;Kids [ 4 0 R 6 0 R ] 
  &gt;&gt;
  endobj

  4 0 obj
  &lt;&lt;
  &#x2F;Type &#x2F;Page
  &#x2F;Parent 3 0 R
  &#x2F;Resources &lt;&lt;
  &#x2F;Font &lt;&lt;
  &#x2F;F1 9 0 R 
  &gt;&gt;
  &#x2F;ProcSet 8 0 R
  &gt;&gt;
  &#x2F;MediaBox [0 0 612.0000 792.0000]
  &#x2F;Contents 5 0 R
  &gt;&gt;
  endobj

  5 0 obj
  &lt;&lt; &#x2F;Length 1074 &gt;&gt;
  stream
  2 J
  BT
  0 0 0 rg
  &#x2F;F1 0027 Tf
  57.3750 722.2800 Td
  ( A Simple PDF File ) Tj
  ET
  BT
  &#x2F;F1 0010 Tf
  69.2500 688.6080 Td
  ( This is a small demonstration .pdf file - ) Tj
  ET
  BT
  &#x2F;F1 0010 Tf
  69.2500 664.7040 Td
  ( just for use in the Virtual Mechanics tutorials. More 
  text. And more ) Tj
  ET
  BT
  &#x2F;F1 0010 Tf
  69.2500 652.7520 Td
  ( text. And more text. And more text. And more text. ) Tj
  ET
  BT
  &#x2F;F1 0010 Tf 
  69.2500 628.8480 Td
  ( And more text. And more text. And more text. And more 
  text. And more ) Tj
  ET
  BT
  &#x2F;F1 0010 Tf
  69.2500 616.8960 Td
  ( text. And more text. Boring, zzzzz. And more text. And 
  more text. And ) Tj
  ET
  BT
  &#x2F;F1 0010 Tf
  69.2500 604.9440 Td
  ( more text. And more text. And more text. And more text. 
  And more text. ) Tj
  ET
  BT
  &#x2F;F1 0010 Tf
  69.2500 592.9920 Td 
  ( And more text. And more text. ) Tj
  ET
  BT
  &#x2F;F1 0010 Tf
  69.2500 569.0880 Td
  ( And more text. And more text. And more text. And more 
  text. And more ) Tj
  ET
  BT
  &#x2F;F1 0010 Tf
  69.2500 557.1360 Td
  ( text. And more text. And more text. Even more. Continued 
  on page 2 ...) Tj
  ET
  endstream
  endobj

  6 0 obj
  &lt;&lt;
  &#x2F;Type &#x2F;Page
  &#x2F;Parent 3 0 R
  &#x2F;Resources &lt;&lt;
  &#x2F;Font &lt;&lt;
  &#x2F;F1 9 0 R 
  &gt;&gt;
  &#x2F;ProcSet 8 0 R
  &gt;&gt;
  &#x2F;MediaBox [0 0 612.0000 792.0000]
  &#x2F;Contents 7 0 R
  &gt;&gt;
  endobj

  7 0 obj
  &lt;&lt; &#x2F;Length 676 &gt;&gt;
  stream
  2 J
  BT
  0 0 0 rg
  &#x2F;F1 0027 Tf
  57.3750 722.2800 Td
  ( Simple PDF File 2 ) Tj
  ET
  BT
  &#x2F;F1 0010 Tf
  69.2500 688.6080 Td
  ( ...continued from page 1. Yet more text. And more text. 
  And more text. ) Tj
  ET
  BT
  &#x2F;F1 0010 Tf
  69.2500 676.6560 Td
  ( And more text. And more text. And more text. And more 
  text. And more ) Tj
  ET
  BT
  &#x2F;F1 0010 Tf
  69.2500 664.7040 Td
  ( text. Oh, how boring typing this stuff. But not as boring as watching ) Tj
  ET
  BT
  &#x2F;F1 0010 Tf
  69.2500 652.7520 Td
  ( paint dry. And more text. And more text. And more text. 
  And more text. ) Tj
  ET
  BT
  &#x2F;F1 0010 Tf
  69.2500 640.8000 Td
  ( Boring.  More, a little more text. The end, and just as 
  well. ) Tj
  ET
  endstream
  endobj

  8 0 obj
  [&#x2F;PDF &#x2F;Text]
  endobj

  9 0 obj
  &lt;&lt;
  &#x2F;Type &#x2F;Font
  &#x2F;Subtype &#x2F;Type1
  &#x2F;Name &#x2F;F1
  &#x2F;BaseFont &#x2F;Helvetica
  &#x2F;Encoding &#x2F;WinAnsiEncoding
  &gt;&gt;
  endobj
 
  10 0 obj
  &lt;&lt;
  &#x2F;Creator (Rave \(http:&#x2F;&#x2F;www.nevrona.com&#x2F;rave\))
  &#x2F;Producer (Nevrona Designs)
  &#x2F;CreationDate (D:20060301072826)
  &gt;&gt; 
  endobj

  xref
  0 11
  0000000000 65535 f
  0000000019 00000 n
  0000000093 00000 n
  0000000147 00000 n
  0000000222 00000 n
  0000000390 00000 n
  0000001522 00000 n
  0000001690 00000 n
  0000002423 00000 n
  0000002456 00000 n
  0000002574 00000 n

  trailer
  &lt;&lt;
  &#x2F;Size 11
  &#x2F;Root 1 0 R
  &#x2F;Info 10 0 R
  &gt;&gt;

  startxref
  2714
  %%EOF</code></pre>