This is an archived forum post. The information may be outdated. Contact us if you have any questions.

Form Input Fields Not Being Saved to PDF

insurancemavs wrote on 2011-07-07:
I've tried several things, but it never saves the data I put into the input fields into the final PDF. Does it support that?
support wrote on 2011-07-07:
Do you mean data specified using the value attribute, e.g:
<input type=text value="sample text" />

or data entered by a user on a web page?
insurancemavs wrote on 2011-07-08:
Data entered by users on the site.
kizmar wrote on 2011-07-09:
I ended up having to use jQuery to get this data to show on the PDF. I replace the value of the containing element with the $.val() of the text box. This way it didn't render the text box border either.

If you'd like a working example let me know.

Edit: You can do the same thing with plain JavaScript, it's just easier with jQuery. :)
insurancemavs wrote on 2011-07-11:
Yes working example would be great, thank you.
kizmar wrote on 2011-07-11:
What I'm doing is something like this:

Instead of sending directly to a link with an anchor tag, call a JavaScript function:
  <a href="javascript:DoPDFCrowdThing()">Save as PDF</a>

Then in your JavaScript function, do something like this:
function DoPDFCrowdThing() {
  // using jQuery
  $("input", "form").each(function() {
    // replace the html with the input value
    $(this).html($(this).val());
  });

  // send to pdfcrowd to prompt for file save
  window.location = "http://pdfcrowd.com/url_to_pdf/?width=8.5in&amp;height=11in";
}

This method will ensure that any user interaction that's happened in the form after page load will show when the PDF is created.

Doing this will remove the text fields from the page. If you want the page to remain untouched this method won't work.
insurancemavs wrote on 2011-07-11:
This is what I have but no data entered in the input fields are showing on the PDF. Thank you for your help btw.

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" src="pdf-it.js"></script>


What version of jquery are you using? It does create the PDF just fine, but no data from the input fields show up.
The pdf-it.js file is this:

function DoPDFCrowdThing() {
  // using jQuery
  $("input", "form").each(function() {
    // replace the html with the input value
    $(this).html($(this).val());
  });

  // send to pdfcrowd to prompt for file save
  window.location = "http://pdfcrowd.com/url_to_pdf/?width=8.5in&amp;height=11in";
}


Here is an example of one of the input fields. In total there are 11 input fields.

<input type="text"   name="input3" value="" style="height:25px; width:340px; border:0px; border-bottom:solid 1px #001a2d;; font-size:15px; color: #666; font-family:Arial; background:#fff;" />
support wrote on 2011-07-11:
Generally, the API can't directly access form data entered by users in the browser. Depending on your use case there may be a workaround.

Please, describe your use case and also how you use the API and we will look into it.
insurancemavs wrote on 2011-07-11:
I'm trying another method. But this isn't working either. They fill out the form and press submit. Next page will just echo it out as normal text.

For example:

<?php echo $input1; ?>


It displays the text inputted on the previous page. But when I create a PDF from this page it doesn't show up in the PDF...

What I'm trying to do is create a PDF with this page from the input entered by the user.

http://safemoneymillionaire.com/blueprint-online/

This page may change since I'm still trying to get this to work..
support wrote on 2011-07-11:
The simplest solution seems to be to POST entered data to your server, generate HTML that contains the entered values, and then send it to the API. Actually, it seems you actually have the first two steps in place.

The remaining step is to use the convertHtml() method:
$pdf = $client->convertHtml(<html code generated by print-version.php>);


Note, that you can't do this:
$pdf = $client->convertURI("http://safemoneymillionaire.com/blueprint-online/print-version.php");

since the API will download the page using the GET method.
insurancemavs wrote on 2011-07-11:
Ok, just wanted to report back that I got this working. Here is how I did it. It's pretty simple.

First page is a regular form. This is the part of the form code from the first page:

<form method="post" action="print-version.php" name="blue">

<input type="text"   name="input1" value="" style="height:25px; width:440px; border:0px; border-bottom:solid 1px #001a2d;; font-size:15px; color: #666; font-family:Arial; background:#fff;" />


2nd page I have this:

$input1 = $_POST['input1'];
$input2 = $_POST['input2'];
$input3 = $_POST['input3'];
$input4 = $_POST['input4'];
$input5 = $_POST['input5'];
$input6 = $_POST['input6'];
$input7 = $_POST['input7'];
$input8 = $_POST['input8'];
$input9 = $_POST['input9'];
$input10 = $_POST['input10'];
$input11 = $_POST['input11'];


Then I have the:

$pdf = $client->convertHtml('amazing <em>HTML</em> here');


Then all the HTML of that page. When I need to echo out the input fields of the previous form I do something like this:

$pdf = $client->convertHtml('Input field 1 text is the following:  <b>'.$input1.'</b>');


Anyway I got it to work the way I needed. Hopefully this helps others.
support wrote on 2011-07-11:
Great! Thanks for reporting back.