Download PDF For Smartform on a click

  • 23 May 2017
  • 1 reply
  • 13 views

Badge +2

Hello All,

 

There is always a requirement when the client wants to download a PDF for the smartform on a single click and have it autodownloaded.

 

To achieve the same the below steps can be followed.

 

1)on click of a button save the PDF to K2 using save as PDF OOB control.

2)obtain the base 64 string for the PDF

3)set a datafield with an expression on runtime

  The expression holds the script for the PDF download

 

<script type="text/javascript">$(document).ready(function () { var base64PDF =' Data Label Raw Data '; var objbuilder = ''; objbuilder += ('<object width="100%" height="100%" data="data&colon;application/pdf;base64,'); objbuilder += (base64PDF); objbuilder += ('" type="application/pdf" class="internal">'); objbuilder += ('<embed src="data&colon;application/pdf;base64,'); objbuilder += (base64PDF); objbuilder += ('" type="application/pdf" />'); objbuilder += ('</object>'); var win = window.open("", "_blank", "titlebar=yes"); win.document.title = "Print"; win.document.write('<html><body>'); win.document.write(objbuilder); win.document.write('</body></html>'); layer = jQuery(win.document); });</script>

 

The script work well for all browsers, except IE.

 

In case of IE, the user would be displayed with a custom message and a file attachment download link for the PDF.

 

Regards

Lubna

 


1 reply

Badge +3

Hello Lubna,

 

I just tried the steps written above but no luck .

 

Could you please let me know at steps how can we achive .

 

Regards,

Ruchi

Reply