【问题标题】:PDF generation with Acrobat Jascript using DomPDF/PHP使用 DomPDF/PHP 使用 Acrobat Jascript 生成 PDF
【发布时间】: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 测试版已经让它显示了弹出窗口,但代码似乎没有按照我的意愿做......关于安全错误的事情?如果你能指出我的写作方向那就太好了:)
  • 我尝试了您的代码,但 Adob​​e Acrobat 告诉我某些内容因安全原因被阻止。我不确定什么被阻止,这可能在 Adob​​e PDF Javascript API 文档中。

标签: php javascript acrobat dompdf


【解决方案1】:

URL 必须进行转义,openDoc 方法应如下所示:

var myURL = encodeURI("http://www.example.com");

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

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

CHTTP: "指定源文件系统名称的字符串。支持两个值:(空字符串,默认值),表示默认文件系统,以及“CHTTP”。此参数仅在网络服务器支持 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

【讨论】:

    猜你喜欢
    • 2017-08-14
    • 2012-06-06
    • 2022-01-03
    • 2015-10-30
    • 1970-01-01
    • 2020-07-12
    • 2016-10-17
    • 1970-01-01
    相关资源
    最近更新 更多