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

Can XMLHttpRequest object be created with JavaScript in PDF document

Community Beginner ,
Oct 15, 2021 Oct 15, 2021

I m planning to add five smilies from sad to happy to the bottom of our invoices to measure user satisfaction. User can choose to submit the chosen one with a button. I want to send this data -which is a number from 1 to 5- to a web server to process.

 

var xhttp = new XMLHttpRequest();
	xhttp.open("POST", "https://mywebservice.asp", true);
	xhttp.setRequestHeader("Content-type", "application/json");
xhttp.send(newdata);

 

Newdata is the number from 1 to 5 mentioned above.

Right now I m opening .pdf files in Firefox browser and getting below error.

 

ReferenceError: XMLHttpRequest is not defined
send@resource://pdf.js/build/pdf.scripting.js line 70 > eval:4:13
@Resource://pdf.js/build/pdf.scripting.js line 70 > eval:9:1
globalEval@resource://pdf.js/build/pdf.scripting.js:70:41
_runActions@resource://pdf.js/build/pdf.scripting.js:3100:14
_dispatchDocEvent@resource://pdf.js/build/pdf.scripting.js:3067:16
dispatch@resource://pdf.js/build/pdf.scripting.js:2613:28
_dispatchEvent@resource://pdf.js/build/pdf.scripting.js:2025:27
__webpack_modules__</initSandbox/<@resource://pdf.js/build/pdf.scripting.js:254:22

TOPICS
How to , JavaScript
2.6K
Translate
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
1 ACCEPTED SOLUTION
Community Expert ,
Oct 19, 2021 Oct 19, 2021

- Firefox is not a PDF reader, it's a browser which, like the others, does not respect all the specifications of the PDF format.

 

- Answer is yes and yes.

See these tutos:

https://acrobatusers.com/tutorials/form-submit-e-mail-demystified/

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

https://khkonsulting.com/2017/08/connect-database-pdf-form-time-without-soap/


Acrobate du PDF, InDesigner et Photoshoptographe

View solution in original post

Translate
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 Beginner ,
Oct 19, 2021 Oct 19, 2021

@JR BoulayCan you please take a look to above question if you have some time?
For now, I just d like to know if you can use forms in a PDF document that can submit data to webservice or create HTTP object with JS that submitts data. In the above code newdata contains e.g.: {"score":3}

The feedback form would look like this:

 

emoji.jpgexpand image

 

 

Highlighting the emojis onhover and set newdata value onclick is a next to do..

Translate
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 ,
Oct 19, 2021 Oct 19, 2021

The browser doesn't use Adobe Acrobat.

What happens when you open the file in Adobe Acrobat?

Translate
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 Beginner ,
Oct 19, 2021 Oct 19, 2021

I tried in Adobe Acrobat but nothing happened.

Firefox is my default app for opening files with .pdf extension and if it s just a simple .pdf file it opens it without any issues.

Translate
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
LEGEND ,
Oct 19, 2021 Oct 19, 2021

Sure, but it (Firefox) does not use any Adobe tech. If you have problem with PDF in Firefox, you need to ask Firefox. Firefox are one of many RIVALS to Adobe in PDF. 

 

We can help you look at problem with Acrobat Pro and JavaScript. What do you see in the JavaScript debugger after "nothing happened"?

Translate
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 Beginner ,
Oct 19, 2021 Oct 19, 2021

Sure, sorry for posting FF debug.

Adobe Pro JS debug:

 

Console:

Exception in line 5 of function send, script Document-Level:send
Exception in line 10 of function top_level, script Document-Level:send

ReferenceError: XMLHttpRequest is not defined
5:Document-Level:send

 

Script:


function send()

 

Is Acrobat JS able to define XMLHttpRequest object in a PDF document?
{
var newdata = {};
var xhttp = new XMLHttpRequest();
xhttp.open("POST", "https://mywebservice.asp", true);
xhttp.setRequestHeader("Content-type", "application/json");
xhttp.send(newdata);
}
send();

Translate
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 Beginner ,
Oct 19, 2021 Oct 19, 2021

function send()

{
var newdata = {};
var xhttp = new XMLHttpRequest();
xhttp.open("POST", "https://mywebservice.asp", true);
xhttp.setRequestHeader("Content-type", "application/json");
xhttp.send(newdata);
}
send();

Translate
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 ,
Oct 19, 2021 Oct 19, 2021

- Firefox is not a PDF reader, it's a browser which, like the others, does not respect all the specifications of the PDF format.

 

- Answer is yes and yes.

See these tutos:

https://acrobatusers.com/tutorials/form-submit-e-mail-demystified/

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

https://khkonsulting.com/2017/08/connect-database-pdf-form-time-without-soap/


Acrobate du PDF, InDesigner et Photoshoptographe
Translate
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 Beginner ,
Oct 19, 2021 Oct 19, 2021
LATEST

This is what I was looking for:

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

Thank you.

I ve a lot to read yet..

Translate
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