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

OnLoad To call PDF convert (not worknig)

basemMO wrote on 2011-10-04:
<a id="callPDF" href="http://pdfcrowd.com/url_to_pdf/?width=210mm&height=297mm&pdf_name=dashboard.pdf">&nbsp;</a>


<script type="text/javascript">
DisplayHTML();
window.onload = function () { triggerPDF(); }

function triggerPDF() {

$('#callPDF').click();
}
</script>
basemMO wrote on 2011-10-04:
Hi,

I think I was able to trigger an <a> tag, however, what the HTML I want to to convert into PDF is in below tag, and I'm usining innerHTML to pouplate the text, However the PDF is not showing the dynamically rendered HTML code, Kindly advise, what other code should I use


<td id="projectsDisplayList" height="163" align="left" valign="top" bgcolor="#FFFFFF">
<p>&nbsp;</p></td>
</tr>
basemMO wrote on 2011-10-04:
<form method='post' target='_blank' action='http://pdfcrowd.com/api/pdf/convert/html/' id='createPdfForm'>

<input type='hidden' name='username' value='basemMO' />
<input type='hidden' name='key' value='basemMO' />

<input type='hidden' name='src' id='pdfsrc' />

<input type='hidden' name='width' value='210mm' />
<input type='hidden' name='height' value='297mm' />
<input type='hidden' name='pdf_name' value='dashboard.pdf' />

</form>


<script type="text/javascript">

whichToList();


window.onload = function () { triggerForm(); }

function triggerForm() {

alert ('before setting');
// set the inner html page to the pdf converter tool
document.getElementById("pdfsrc").value = projectDisplay;
alert ('after setting');

alert ('submitting the form');
alert (document.getElementById("pdfsrc").value);


document.getElementById("createPdfForm").submit();

}
</script>


NOT WORKING............................. PLEASE WANT HELP HERE
support wrote on 2011-10-04:
Submitting the form automatically (i.e. without user intervention) in onload seems not to work reliably in all browsers. For example Google Chrome displays "This site is attempting to download multiple files" on the second reload.

An option is to submit the form manually. You can set the value of the src field dynamically like this
<html>
  <head>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
    <script>
      $(function() {
        $("#createPdf").click(function() {
          $("#pdfsrc").val("<b>your html code</b>")
          $("#createPdfForm").submit();
        });
      });
    </script>
  </head>

  <body>
    <form method="post" action="http://pdfcrowd.com/api/pdf/convert/html/" id="createPdfForm" > 
      <input type="hidden" name="username" value="***" /> 
      <input type="hidden" name="key" value="***" /> 
      <input type="hidden" name="src" id="pdfsrc" value="test"/> 
      <input type="hidden" name="width" value="210mm" /> 
      <input type="hidden" name="height" value="297mm" /> 
      <input type="hidden" name="pdf_name" value="dashboard.pdf" /> 
      <input type="button" id="createPdf" value="create PDF" /> 
    </form>   
    
  </body>
</html>

basemMO wrote on 2011-10-05:
Perfectoo... working fine now :) much apprecaited, I'm pretty sure that after showing it to management, we will buy it