Acrobat Javascript 保存并保存退出按钮

发布于 2024-08-20 19:49:53 字数 339 浏览 2 评论 0原文

我有一个在 acrobat pro 中创建的可写 pdf 表单。现在,我添加了一个按钮,该按钮必须更改字段值、保存 pdf 并关闭它。

我决定按如下方式执行此操作:

var fieldX = this.getField("xxxxField");
fieldX.value = 1;
app.execMenuItem("Save");
this.closeDoc(true);

但这不会保存 pdf。

我不想有确认对话框。我在 API 中看到了 saveAs 函数,但是如何获取实际路径(包括)。当前编辑文档的文件名?或者您还有其他方法吗?

谢谢。

I have a writeable pdf form created in acrobat pro. Now, i added a button which has to change a fields value, save the pdf and close it.

I decided to do this as following:

var fieldX = this.getField("xxxxField");
fieldX.value = 1;
app.execMenuItem("Save");
this.closeDoc(true);

But this doesn't save the pdf.

I don't want to have a confirmation dialog. I saw the saveAs function in the API but how to get the real-path incl. filename of the current editing document? Or do you have any other approaches?

thank you.

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

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

发布评论

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

评论(2

舟遥客 2024-08-27 19:49:53

但这不会保存 pdf。

这是因为存在安全限制,导致 app.execMenuItem("Save"); 无法正常工作。不可以通过JS调用Save。

API 中的函数,但如何获取实际路径,包括。当前编辑文档的文件名?或者您还有其他方法吗?

您可以使用 Doc.path 获取当前文档的路径,包括其文件名(而 Doc.documentFilename 仅提供文件名)。

但是,saveAs 也受到安全限制,并且只能在“特权”上下文(批处理或控制台)中调用。所以这也行不通。

简而言之,安全限制将阻止您在未询问用户的情况下保存文档。如果你仔细想想,这也是合乎逻辑的。

请参阅:Acrobat JS API 参考

But this doesn't save the pdf.

That's because there are security restrictions that prevent app.execMenuItem("Save"); from working. You're not allowed to call Save via JS.

function in the API but how to get the real-path incl. filename of the current editing document? Or do you have any other approaches?

You can use Doc.path to get the path of the current document including its filename (and Doc.documentFilename gives you the filename only).

However, saveAs is also subject to security restrictions, and it can only be called in a "privileged" context (batch or console). So this won't work either.

In short, security restrictions will prevent you from saving documents without asking the user. If you think about it, it's only logical.

See: Acrobat JS API Reference

滴情不沾 2024-08-27 19:49:53

使用下面的链接或代码保存 PDF 数据的客户端代码。这是客户端可信函数,您需要将其放入 C:\Program Files\Adobe\...\JavaScript\Config.js。

如何使用 Acrobat JavaScript 保存 PDF

1) 在文件夹级别保存数据的代码。

var mySaveAs = app.trustedFunction ( function(oDoc,cPath,cFlName)
{

app.beginPriv();
    var flag=false; 

    cPath = cPath.replace(/([^\/])$/, "$1/");

    if(cPath.indexOf("http://") !== -1 || cPath.indexOf("https://") !== -1)
    {
        cPath = cPath.replace('http://', "\\\\");
        cPath = cPath.replace('https://', "\\\\");

        while(cPath.indexOf("/") !== -1)
        {
            cPath = cPath.replace('/', "\\\\");          
        }
    }

    if(cPath.indexOf(":") !== -1)
    {       
        cPath = cPath.replace(":","@"); 
    }


    try{

        oDoc.saveAs(cPath + cFlName);        

        flag = true;

    }catch(e){
        app.alert("Error During Save");
    }
    app.endPriv();

    return flag;
});

2) 在SharePoint保存数据的代码。

var mySaveAs = app.trustedFunction ( function(oDoc,cPath,cFlName)
{

    app.beginPriv();
    var flag=false;
    try{                         
        app.execMenuItem("Save");        
        flag = true;         
    }catch(e){
        app.alert("Error During Save");
    }
    app.endPriv();  
    return flag;
});

Client side code to save PDF Data used below link or code. It's Client side trusted function which you need to put in C:\Program Files\Adobe\...\JavaScript\Config.js.

How to Save a PDF with Acrobat JavaScript

1) Code to save data at folder level.

var mySaveAs = app.trustedFunction ( function(oDoc,cPath,cFlName)
{

app.beginPriv();
    var flag=false; 

    cPath = cPath.replace(/([^\/])$/, "$1/");

    if(cPath.indexOf("http://") !== -1 || cPath.indexOf("https://") !== -1)
    {
        cPath = cPath.replace('http://', "\\\\");
        cPath = cPath.replace('https://', "\\\\");

        while(cPath.indexOf("/") !== -1)
        {
            cPath = cPath.replace('/', "\\\\");          
        }
    }

    if(cPath.indexOf(":") !== -1)
    {       
        cPath = cPath.replace(":","@"); 
    }


    try{

        oDoc.saveAs(cPath + cFlName);        

        flag = true;

    }catch(e){
        app.alert("Error During Save");
    }
    app.endPriv();

    return flag;
});

2) Code to save data at SharePoint.

var mySaveAs = app.trustedFunction ( function(oDoc,cPath,cFlName)
{

    app.beginPriv();
    var flag=false;
    try{                         
        app.execMenuItem("Save");        
        flag = true;         
    }catch(e){
        app.alert("Error During Save");
    }
    app.endPriv();  
    return flag;
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文