2011-02-15 71 views
2

我目前正在构建一个应用程序,使用PHP库DOMPDF从HTML生成PDF。 PDF需要能够更新其内容或下载更新的版本(如果可以从网站API获得),并且要实现这一点,我相信我必须使用Acrobat Javascript,但我不知道该怎么做。我已经编写了以下嵌入在PDF中的JavaScript,尽管它不会执行任何操作(甚至不显示警告框)。它使用HTML头中的<script type="text/javascript">标签嵌入。在这个使用DomPDF/PHP使用Acrobat Jascript生成PDF

任何帮助,将不胜感激:)

// 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); 
+0

尝试将JavaScript放置在文档的正文中。我相信dompdf目前丢弃了大多数标题内容。 – BrianS 2011-02-15 17:43:29

回答

0

URL必须进行转义和OpenDoc的方法应该是这样的:

VAR myURL =是encodeURI(“HTTP:// WWW。 example.com“);

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

CPATH:“与设备无关的打开文档的路径,如果指定了oDoc,路径可以相对于它,目标文档必须在默认文件系统中可访问。 “

CHTTP:”一个指定源文件系统名称的字符串,支持两种值:(表示默认文件系统的空字符串)和“CHTTP”。该Web服务器支持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