使用 DomPDF/PHP 通过 Acrobat Jascript 生成 PDF

发布于 2024-10-17 09:58:13 字数 1314 浏览 6 评论 0原文

我目前正在构建一个应用程序,该应用程序使用 PHP 库 DOMPDF 从 HTML 生成 PDF。 PDF 需要能够更新其内容或下载更新版本(如果可以从站点 API 获得),并且要完成此操作,我相信我必须使用 Acrobat Javascript,但我不确定如何执行此操作。我编写了以下嵌入在 PDF 中的 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);

I'm currently building an application that generates PDF's from HTML using the PHP library DOMPDF. The PDF's require the ability to update their content or download a newer version if it's available from the sites API and to accomplish this I believe I'll have to use Acrobat Javascript but I'm not sure how to do it. I've written the following javascript that get's embedded in the PDF's although it doesn't do anything (Not even show the alert box). It's embedded using a <script type="text/javascript"> tag in the html head.

Any help on this would be greatly appreciated :)

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雨落星ぅ辰 2024-10-24 09:58:13

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

The URL must be escaped and the openDoc method should look like:

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

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

CPATH: "A device-independent path to the document to be opened. If oDoc is specified, the path can be relative to it. The target document must be accessible in the default file system."

CHTTP: "A string that specifies the source file system name. Two values are supported: (the empty string, which is the default), representing the default file system, and “CHTTP”. This parameter is relevant only if the web server supports 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文