2011-02-15 73 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