title: Embed javascript in pdf with pdfkit
body: <p>Is that possible to embed some javascript code into the pdf file that I'm creating using NodeJS PDFKit (<a href="http://pdfkit.org/" rel="nofollow">http://pdfkit.org/</a>)?</p>
  
  <p>I know how to embed javascript with C# using PDFSharp, and when i look into the two files created by PDFSharp, one with embedded javascript, and one without they have the following differences:</p>
  
  <p><strong>The one with javascript containts to additional objects that are inserted as the last to objects:</strong></p>
  
  <pre><code>30 0 obj
  &lt;&lt;
  /S/JavaScript
  /JS(this.print\(true\); )
  &gt;&gt;
  endobj
  31 0 obj
  &lt;&lt;
  /Names[(EmbeddedJS)30 0 R]
  &gt;&gt;
  endobj
  </code></pre>
  
  <p>In this case the js i'm embedding is <code>this.print\(true\);</code>. Also after that the object reference offsets are different accordingly.</p>
  
  <p>And there is also this:</p>
  
  <pre><code>/Names
  &lt;&lt;
  /JavaScript 31 0 R
  &gt;&gt;
  </code></pre>
  
  <p>reference in the second object of the pdf. This whole object looks like this:</p>
  
  <pre><code>2 0 obj
  &lt;&lt;
  /Type/Catalog
  /Pages 3 0 R
  /Names
  &lt;&lt;
  /JavaScript 31 0 R
  &gt;&gt;
  &gt;&gt;
  endobj
  </code></pre>
  
  <p>And when I try to insert this code into a pdf generated by pdfkit i get a corrupted file. Is there something I'm missing? Is there possibly a better way to embed javascript into pdf with pdfkit?</p>
  
  <p>PS. Of course I calculate the proper object numbers, adjust the offsets etc.</p>