我目前正在構建一個應用程序,使用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);
嘗試將JavaScript放置在文檔的正文中。我相信dompdf目前丟棄了大多數標題內容。 – BrianS 2011-02-15 17:43:29