2

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 <script type="text/javascript"> tag in the html head.

Any help on this would be greatly appreciated :)

// 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<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);
  • Try placing the JavaScript in the body of the document. I believe dompdf currently discards most header content. – BrianS Feb 15 '11 at 17:43
  • Thanks for the feedback. That doesn't seem to solve the problem unfortunately. Perhaps there is another method to accomplish what I'm trying? – Dave Blencowe Feb 15 '11 at 19:38
  • What version of dompdf are you using ? The 0.5 versions don't support embedded JS, but 0.6 does. – Fabien Ménager Feb 15 '11 at 20:37
  • Thanks, the 0.6 beta has got it showing the pop-up but the code doesn't appear to be doing what I want it to... Something about security errors? If you'd be able to point me in the write direction that'd be great :) – Dave Blencowe Feb 16 '11 at 13:54
  • I tried your code, but Adobe Acrobat tells me something is blocked for security reason. I'm not sure of what is blocked, this may be in the Adobe PDF Javascript API docs. – Fabien Ménager Feb 16 '11 at 21:33
  • do you have a client side debugger, like firebug to poss. inform the problem? – jamesTheProgrammer Apr 20 '12 at 20:20

1 Answers1

0

The URL must be escaped and the openDoc method should look like:

var myURL = encodeURI("http://www.example.com");

app.openDoc({cPath: myURL, cFS: "CHTTP" });

CPATH: "A device-independent path to the document to be opened. If oDoc is specified, the path can be relative to it. The target document must be accessible in the default file system."

CHTTP: "A string that specifies the source file system name. Two values are supported: (the empty string, which is the default), representing the default file system, and “CHTTP”. This parameter is relevant only if the web server supports WebDAV."

http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/wwhelp/wwhimpl/common/html/wwhelp.htm?context=Acrobat9_HTMLHelp&file=JS_API_AcroJS.88.131.html#1995988

Alex
  • 21
  • 1