Create pdf by using javascript


Create pdf by using javascript

icon for PDF files (Photo credit: Wikipedia)

By using jspdf library which generates PDF files using java script.You can download library from http://jspdf.com/

after downloading  the library create a html or php file in example folder and paste below code.It already as many examples. but sharing this code ,because we can,t add edit or alter code.but we can add function to work according to our condition.because we can replace or change other option in saveondisk button.one more think we can add php variable in it to create pdf file with php content.

<!doctype>
<html>
<head>
    <title>jsPDF</title>
    <link rel=”stylesheet” type=”text/css” href=”css/main.css”>
     <script src=”http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js”></script&gt;
     <script type=”text/javascript” src=”../libs/downloadify/js/swfobject.js”></script>
    <script type=”text/javascript” src=”../libs/base64.js”></script>
    <script type=”text/javascript” src=”../jspdf.js”></script>
     <script type=”text/javascript” src=”../libs/downloadify/js/downloadify.min.js”></script>    
        
</head>

<body>
    <input id=”notify_checkbox” type=”checkbox” value=”y”  name=”notify”>
<h1>jsPDF Downloadify Example</h1>

<p>This is an example of jsPDF using <a href=”http://www.downloadify.info/”>Downloadify</a&gt;. This works in all major browsers.</p>

<p id=”downloadify”>
    You must have Flash 10 installed to download this file.
</p>
<?php
$varible=”http://ephptutorial.wordpress.com/&#8221;;
?>

<script type=”text/javascript”>
 
    $(‘#notify_checkbox’).change(function()
    {
     if($(‘#notify_checkbox’).is(‘:checked’))
    {
    Downloadify.create(‘downloadify’,{
            filename: ‘Example.pdf’,
            data: function(){
                var doc = new jsPDF();
                doc.text(20, 20, <?php echo $varible;?>’);
                doc.addPage();
                doc.text(20, 20, ‘Do you like that?’);
                return doc.output();
            },
             onComplete: function(){ alert(‘Your File Has Been Saved!’); },
            onCancel: function(){ alert(‘You have cancelled the saving of this file.’); },
            onError: function(){ alert(‘You must put something in the File Contents or there will be nothing to save!’); },
            swf: ‘../libs/downloadify/media/downloadify.swf’,
            downloadImage: ‘../libs/downloadify/images/download.png’,
            width: 100,
            height: 30,
            transparent: true,
            append: false
            
        });
 
   }
    else
    {
    
        $( “#downloadify” ).html( “<p>Okay, we email you.</p>” );
    }
});
</script>    
</body>
</html>

About these ads

Tagged: , , , , , , , , , , , , , , ,

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: