• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Send a document to Java Servlet using JavaScript - Security Issue

New Here ,
Jul 09, 2018 Jul 09, 2018

Copy link to clipboard

Copied

Hello,


I need create new option in Adobe Menu to "export/send" current/opened document to Java Servlet.
I using free Adobe Reader DC.

First my idea was to use http method in adobe java script api, but I still fighting with security permission.

My java script code is in User folder: 
C:\Users\insys\AppData\Roaming\Adobe\Acrobat\Privileged\DC\Javascripts\

Below there is a code for http method:

var runExtract = app.trustedFunction(function(doc) {

    app.beginPriv();

        try {

            var params =

             {

                cVerb: "POST",

                cURL: "http://10.179.13.16:8088/ppap/uploadFile",

                aHeaders: [{ name: "fileName", value: doc.documentFileName }],

                oRequest: Collab.documentToStream(doc)

            };

            var responseStream = Net.HTTP.request(params);

        }

        catch (e) {

           app.alert({ cMsg: e.message, cTitle: "Exception" });

        }

    app.endPriv();

});

Code for menu item:

app.addMenuItem({

    cName: "ExportPPAP",

    cUser: "Export to PPAP",

    cParent: "File",

    nPos: 7,

    cEnable: "event.rc = (event.target != null);",

    cExec: "runExtract(event.target)"  

});

But when I want to export this file I receiving:

NotAllowedError: Security settings prevent access to this property or method

Even when I created simply function just to save file (again as separate javascript file in User folder):
Script below:

var myTrustedSaveAs = app.trustedFunction( function ()

{

   app.beginPriv();

        var myTrustedRetn = this.saveAs("/c/MyDocs/" + this.documentFileName);

   app.endPriv();

   return myTrustedRetn;

});

I still receiving:

NotAllowedError: Security settings prevent access to this property or method


Can someone help me how to achive my goa using free version? Maybe someone has other idea, using different function?

TOPICS
Acrobat SDK and JavaScript , Windows

Views

1.4K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 11, 2018 Jul 11, 2018

Use the Doc.submitForm() method and in the parameters, set the "cSubmitAs" parameter to "PDF". That will send the entire PDF to your server.

Votes

Translate

Translate
Community Expert ,
Jul 09, 2018 Jul 09, 2018

Copy link to clipboard

Copied

HI,

In both cases you are calling what is a "Save" function, these are only available in the Reader if you have extended the document before opening in Reader.

This can be seen as a simple example in Acrobat DC, you can select from the user menu "File -> Save As Other -> Reader Extended PDF -> Enable More Tools (includes Form fill-in and Save ....)"

Although depending on your use case you may need to investigate the AEM server product for how to enable the forms.

Hope this helps

Malcolm

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 09, 2018 Jul 09, 2018

Copy link to clipboard

Copied

Hi BarlaeDC,

Thanks for you reply, but I not sure about your answer.

I would like to explain what I have to do.

I need add new function to export current pdf file to my application via new item in menu.

Scenario: :

1. user clicked button "open pdf file" in my java application

2. Document is opened in PDF Reader,

3. User is editing opened PDF File.

4. User pressed new item in Menu > Export to Java Application.

5. Updated document is sending from adobe reader to my application ( here I need to provide communication between adobe reader and my java application)

5. In java application  I  going to update document which include new changes.

And I have to provide some communication between pdf reader and my java application. (point 5)

In java application I would like to use java servlet, but from adobe reader I have to somehow send this current document.

And I would like to use http method but I see that it is not easy to use in free adobe reader, so I try to find some other solution how to do it.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 09, 2018 Jul 09, 2018

Copy link to clipboard

Copied

BarlaeDC  wrote

In both cases you are calling what is a "Save" function, these are only available in the Reader if you have extended the document before opening in Reader.

That was true in older versions of Reader. It's not the case in Reader DC.

However, the request method does require special "form rights" be applied to the file for it to work in Reader. I'm not sure if that's the kind of rights you can add with Acrobat, though, or it requires using one of the LiveCycle products. The documentation is not very clear on it.

The saveAs method should work fine in Reader, though. I would recommend not using the "this" keyword in it, but to pass a reference to the document as a parameter, instead.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 09, 2018 Jul 09, 2018

Copy link to clipboard

Copied

Hi

Good to know, I knew they had added the Save As functionality but I didn't think that had made it through to the JavaScript, nice.

Regards

Malcolm

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 11, 2018 Jul 11, 2018

Copy link to clipboard

Copied

Do someone else have idea?
Maybe I should use plug-in in c/c++ code?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 11, 2018 Jul 11, 2018

Copy link to clipboard

Copied

Hi,

Creating a plug-in for Adobe Reader is not just a case of writing the plug-in, it described here - Acrobat DC SDK Documentation.

It is a two stage process, there is the actual development of the plug-in and the contractual tasks which need to be done, before your plug-in can be used in the Adobe Reader. (and Adobe can say no )

I am not sure this is easier than using the AEM forms product to enable the functionality in your PDF, that is something that only you could really decide. here is more information about it - AEM forms * Configuring Acrobat Reader DC extensions

Regards

Malcolm

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 11, 2018 Jul 11, 2018

Copy link to clipboard

Copied

Use the Doc.submitForm() method and in the parameters, set the "cSubmitAs" parameter to "PDF". That will send the entire PDF to your server.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 11, 2018 Jul 11, 2018

Copy link to clipboard

Copied

I second Joel's answer.  The correct way to send a document or data to a server is with the "submitForm()" method.

Here's an article on the topic:

https://acrobatusers.com/tutorials/submitting-data

And for BarlaeDC

Here are some articles that explain trusted functions and saving in from JS in Reader

https://acrobatusers.com/tutorials/trust-and-privilege-in-acrobat-scripts https://acrobatusers.com/tutorials/how-save-pdf-acrobat-javascript

https://acrobatusers.com/tutorials/using_trusted_functions

https://acrobatusers.com/tutorials/how-save-pdf-acrobat-javascript

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 13, 2018 Jul 13, 2018

Copy link to clipboard

Copied

LATEST

Very very thanks!
It's working!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines