Collect data on web on submit of PDF - javascript

I have a pdf on website, which i want, client download it or i will email them and they fill it, and when they click on submit button in the pdf, it send all the form field data to my webpage, so i can enter all the information on my database.
My Webpage using ASP.net as server side language
I have created a pdf by using "Nitro PDF" in nitro pdf there is a option to Submit form on click as a FDF,XFDF,html.
I have tried html but that doesn't work , so i collect all the fields information by using javascript an send information via GET method, mentioned below
// Obtain the value from the first field
var Fname = getField("firstName").value;
// Obtain the value from the second field
var Mname = getField("middleName").value;
// Obtain the value from the third field
var Lname = getField("lastName").value;
app.launchURL("http://techchef.org/test.php?Fname="+Fname+"&Lname="+Lname, true);
but the problem in the above mention method is, i have more than 48 fields & cant use GET method..
so i try to find out the POST method in javascript which can be workable in the pdf and i tried the below mention code which i found from this link Submit pdf form fields to a HTTP POST request but it doesn't work...It only send empty information
Code For POST Method
app.submitForm("http://example.com/test.php, true);
then i research about FDF, and i found FDF Kit, but when try this i found it only works if i ask user to fill the form of the pdf with out downloading..So in this way i can not able to send the pdf to the clients via email.
Please guide me how can i receive the filled data on my webpage on the click of "send" button (please advice if i can use a POST method or some thing else)

Related

Google Email: Button/Link which trigger a script for sheet

I am looking for a way to send an email with Google App Script (I know how to do that) which includes an approval button/link. When the user clicks the link/button in the email to approve the request, I want to trigger a script (this is the part I do not know if possible from email) which goes back to the Google Sheet and changes a value in a cell.
Example:
User A submits a request using google form, and a new row is appended in SheetA. With some formulas, I automatically associate an ID = X to that request/row. A script will then send an email to user B to ask to approve the request of user A. User B will click a link in the email and the script will find the record X in SheetA and update a value in that row.
You can create a simple web app, using code like
function doGet(e) {
params = e.parameter;
var range=e.parameter.range;
var value=e.parameter.value;
SpreadsheetApp.openById('SHEETID').getRange(range).setValue(value);
return HtmlService.createHtmlOutput(`<b>${range}</b> set to <b>${value}</b>`);
}
publish it with "execute as me", "everyone, even anonymous" options,
and then exec it using a link
https://script.google.com/macros/s/SCRIPTID/exec?range=B1&value=100
Example sheet:
https://docs.google.com/spreadsheets/d/1jNEzil1dOtXj-Qc5ZVcZnd1fwGQ7V18irWIsH9G8to8/edit?usp=sharing
Update link:
https://script.google.com/macros/s/AKfycby5KYzQELQNS0y0uf0CwjwzoWkabCJywqkpph7wUUXoTGjERUg/exec?range=Sheet1!B1&value=500
I don't know of a prefect way to do this, but with a small work-around, it is possible.
Instead of "clicking an Approve button," the user could click an Approve link. This link would open a Google Form that is pre-filled with the a request ID and Marked as Approved. All they would need to do is submit the pre-filled form. The email would also contain a Reject link that would also pre-fill the request_id and mark Reject. (I recommend radio buttons for this question)
Then set up a trigger onFormSumit(). for this form that makes the appropriate edits to the spreadsheet when a user submits this form.
If you wanted to make the solution even more complicated, but perhaps avoid the second click, the links could be to a WebApp and you could code the site to automatically record the data in the url to Google sheet.
PS: Both solutions also work as a way to get read receipts for emails sent from Google Scripts.

Get Pdf form data filled on browser and get field values as post data similar to html form

I have opened editable pdf on browser and I am able to add entries on pdf. Following is the html sample code which I have written to display editable pdf on browser:
<form enctype="multipart/form-data" method="post" action="test3.php" method="POST">
<iframe src="AbcPdfForm.pdf" type="application/pdf" width="100%" height="600px;"></iframe>
<input type="submit" id="submitpdf" name="submitpdf" value="Submit"/>
</form>
Submit button is outside the pdf document. On click of submit button, I am unable to get field values of pdf form.
I have tried pdftk library also "https://github.com/mikehaertl/php-pdftk". From this library, I have tried feature "Get PDF data" through php code. I am unable to get field values from this library too. I have received only field names of pdf file.
I have tried to receive field values using following procedure:
I have entered information in pdf opened through browser. Then I saved that pdf with name 'data.pdf' and write following code from pdktk.
use mikehaertl\pdftk\Pdf;
$pdf = new Pdf('data.pdf');
$data = $pdf->getData();
print_r($data); // Get metadata info about pdf file
$data1 = $pdf->getDataFields();
print_r($data); // Get field names, field type info of fields.
I am unable to get field values through this pdftk library. There are lot of libraries available for .net, java and python for converting pdf form to html form and then get post information. But didn't find anything for PHP. I tried to handle this situation in indirect way also like first fill data in pdf through browser and then save that pdf through browser and then get fields of newly saved pdf through pdftk library, but pdftk only fetching field names, not able to get field values.
There is another feature of pdftk "Fill Form". In this fetaure, pdf is filled with hard-coded values through php.
But I want to fill pdf on browser and get those filled values in php file.
I will be very thankful to anyone if anyone suggests me how to fulfill my requirements. Any of the following direct/indirect approaches will work for me:
* Either by converting pdf form to html form. User will fill html form and we can directly get submitted values.
* Get Pdf values through javascript on browser which user has filled on pdf opened on browser.
* Get values through library for php or javascript.

Laravel snappy pushing PDF download

I am using Laravel/Jquery with barryvdh/laravel-snappy to create a pdf on the fly from database data.
In the controller I have:
if ($request->ajax())
{
$document = Document::url($id)->first();
$pdf = PDF::loadView('app.documents.whitepapers.pdf', compact('document'));
return $pdf->download('filename.pdf');
// return response()->send($pdf->download('filename.pdf'), 200, $headers);
}
How can I push this PDF to the browser so that is available as a download?
When I do it without Jquery it is working perfectly. The reason that it is behind a Jquery function is that I use a Modal with a form to collect a persons data before the download can be initiated. This has ajax validation.
You will not be able to present the file as a regular download via JavaScript. In order to show a download prompt to the user, you'll need an extra step in your workflow.
I would suggest the following workflow:
User submits modal form
Form is validated via AJAX. If validation passes, respond with a URL to download the user's PDF from, instead of the PDF itself.
Your JavaScript redirects the user to this URL. Note that this is a redirect, rather than another AJAX request (see top.location.href)
When the user accesses that URL, you are able to deliver the PDF using the code snippet you provided in your original question. This snippet sets the content-disposition of the response appropriately, forcing the download prompt to appear in the user's browser.
If you need to customise the PDF generation for each user, make sure to include the user's ID (or another piece of identifying information) through to step 4.

Retrieve PDF from iframe

Is it possible to retrieve a PDF from an iframe and submit it back to the server?
My use case is to display a PDF form to the user, and let them submit the form after filling it out. I haven't found anything indicating this is possible, but I'm remaining hopeful for the moment.
You can add a submit button inside the PDF itself while generating it, and treat the data comming from your PDF form in the same way you would deal with an HTML form.
In order to achieve this, you will need to add a button annotation to your PDF form, and attach a "submit form" action to it. See Chapter 8 - Interactive Forms of the PDF Reference Document from Adobe for more details.
You can create then an asp.net page that processes the input from the PDF form. Note that the field names of a PDF form can be used in asp.net Request object to collect the data.
If you want to submit the whole file instead, you can do so by setting a flag in the "submit-form" action that you need to add to your PDF file, but I do not recommend doing this in general since it will consume more bandwidth from your server.

How to download a filled in form in PDF format using javascript or html

I have a html page with a form ,with few input fields, check box,radio buttons.
User can fill up the forms.
Is there any way , the user will be able to download the form (with the filled in data) in pdf format ?
1 more question, Any way to save the filled in form in html format or image format (of course File-> save of browser and screenshot are there) using java script code or html code , on a button click ?
I have tried http://code.google.com/p/jspdf/ , didnot able to get through it.
Thanks
[Adding a few more points]
if generating a pdf file using JS/HTML is not possible then ....
A bit more into it
Currently I am creating a server using C# application and when user requests a html page , I am sending the same to user.
that html page contains a form , which is needed to be filled
and I want the user to save the filled form in pdf format.
For now , I am able to process the static html form -> convert to pdf and provide the download to user ,
But can't get a way to enable the user to save the filled in form.
When the user presses the submit button , I can get all the filled in data using httpResponce object(GET/Post Method)!! , is there a way I can generate a pdf file using this httpResponce object parameters?
Or any way I can send the current html page content (e.g. getting all the contents in a div using jquery/javascript) and send it back, when user presses the submit button, in that way I can generate the pdf file at server side and provide a download - PDF format
Please ask , if I am not able to describe my question !!
jsPDF is an open-source library written by our lead developer, James,
for generating PDF documents using nothing but Javascript. You can use
it in a Firefox extension, in Server Side Javascript and with Data
URIs in some browsers. http://snapshotmedia.co.uk/blog/jspdf
Using only javascript to generate the PDF is not possible at this time. Using server-side scripting, it is possible to send the data to a server and let the server generate the PDF which is then sent to the user.
(Update): Using PHP, you can generate PDFs in the server-side using dompdf - HTML to pdf converter. Here is a demo: http://eclecticgeek.com/dompdf/docs_0-6-0/demo.php
In Google Chrome, there is a "Print to PDF" option. If you don't want to do any programming on the server side, you can just ask your users to access the page using Google Chrome. After filling out the form, they print the page as PDF.

Categories