title: PDF generation with Acrobat Jascript using DomPDF/PHP
body: <p>I'm currently building an application that generates PDF's from HTML using the PHP library DOMPDF. The PDF's require the ability to update their content or download a newer version if it's available from the sites API and to accomplish this I believe I'll have to use Acrobat Javascript but I'm not sure how to do it. I've written the following javascript that get's embedded in the PDF's although it doesn't do anything (Not even show the alert box). It's embedded using a <code>&lt;script type="text/javascript"&gt;</code> tag in the html head.</p>
  
  <p>Any help on this would be greatly appreciated :)</p>
  
  <pre><code>// The JS that needs to be inserted in to a PDF file to self update
  
  app.alert('checking for updates');
  
  var version = "1";
  var book_id = "1234";
  var update_url = "http://localhost/koolbookz/"+book_id+"/"+version;
  
  
  // Open the source documents:
  var source1 = app.openDoc(update_url);
  
  // Obtain the OCG order array for each source document:
  var mergedOCGArray = new Array();
  var source1OCGArray = source1.getOCGOrder();
  
  // Merge the OCG order arrays into the target array:
  for (var i=0; i&lt;source1OCGArray.length; i++) mergedOCGArray[i] = source1OCGArray[i];
  var offset = source1OCGArray.length;
  
  // Create the target document:
  var target = app.newDoc(book_id+".pdf");
  
  // Insert source1.pdf:
  target.insertPages({
      nPage : -1,
      cPath : update_url,
  });
  
  // Set the OCG order array in the target document
  target.setOCGOrder(mergedOCGArray);
  
  // Save the target document:
  target.saveAs(book_id+".pdf");
  
  // Close the target document without notifying the user:
  //target.closeDoc(true);
  </code></pre>