开发者

PDF generation with Acrobat Jascript using DomPDF/PHP

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);


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜