【发布时间】:2011-06-27 18:11:12
【问题描述】:
我目前正在构建一个使用 PHP 库 DOMPDF 从 HTML 生成 PDF 的应用程序。 PDF 需要能够更新其内容或下载更新的版本(如果它可从站点 API 获得)并完成此操作我相信我将不得不使用 Acrobat Javascript,但我不知道该怎么做。我编写了以下嵌入在 PDF 中的 javascript,尽管它没有做任何事情(甚至不显示警告框)。它使用 html 头部中的 <script type="text/javascript"> 标记嵌入。
对此的任何帮助将不胜感激:)
// 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 目前会丢弃大多数标题内容。
-
感谢您的反馈。不幸的是,这似乎并不能解决问题。也许还有另一种方法可以完成我正在尝试的事情?
-
您使用的是什么版本的 dompdf? 0.5 版本不支持嵌入式 JS,但 0.6 支持。
-
谢谢,0.6 测试版已经让它显示了弹出窗口,但代码似乎没有按照我的意愿做......关于安全错误的事情?如果你能指出我的写作方向那就太好了:)
-
我尝试了您的代码,但 Adobe Acrobat 告诉我某些内容因安全原因被阻止。我不确定什么被阻止,这可能在 Adobe PDF Javascript API 文档中。
标签: php javascript acrobat dompdf